From 4c45e98005018e53333b659b00c11c8935c3c210 Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Tue, 4 Jun 2024 15:37:20 -0400 Subject: [PATCH 1/9] add new eslint rules --- eslint.config.js | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/eslint.config.js b/eslint.config.js index 0607fe2ebca0..f44b6e2eb49e 100644 --- a/eslint.config.js +++ b/eslint.config.js @@ -4,8 +4,15 @@ import svelte_config from '@sveltejs/eslint-config'; export default [ ...svelte_config, { + languageOptions: { + parserOptions: { + project: true + } + }, rules: { + '@typescript-eslint/await-thenable': 'error', '@typescript-eslint/no-unused-expressions': 'off', + '@typescript-eslint/require-await': 'error', 'no-undef': 'off' } }, @@ -15,7 +22,18 @@ export default [ 'packages/adapter-static/test/apps/*/build', 'packages/adapter-cloudflare/files', 'packages/adapter-netlify/files', - 'packages/adapter-node/files' + 'packages/adapter-node/files', + 'packages/adapter-node/rollup.config.js', + 'packages/adapter-node/tests/smoke.spec.js', + 'packages/adapter-static/test/apps', + 'packages/create-svelte/shared', + 'packages/create-svelte/templates', + 'packages/kit/src/core/sync/create_manifest_data/test/samples', + 'packages/kit/test/apps', + 'packages/kit/test/build-errors', + 'packages/kit/test/prerendering', + 'packages/package/test/errors', + 'packages/package/test/fixtures' ] } ]; From 664daf0f22805674d5764b7515d0b93cc4d2e486 Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Tue, 4 Jun 2024 15:57:16 -0400 Subject: [PATCH 2/9] chore: cleanup promise handling --- packages/adapter-auto/index.js | 4 ++-- packages/adapter-netlify/index.js | 4 ++-- packages/create-svelte/index.js | 1 + packages/enhanced-img/src/index.js | 6 ++++-- .../kit/src/core/sync/write_types/index.js | 4 ++-- .../kit/src/exports/hooks/sequence.spec.js | 4 ++-- packages/kit/src/exports/node/index.js | 4 ++++ .../vite/build/build_service_worker.js | 4 ++-- packages/kit/src/exports/vite/dev/index.js | 2 +- packages/kit/src/exports/vite/index.js | 10 +++++----- packages/kit/src/runtime/client/client.js | 20 ++++++------------- packages/kit/src/runtime/client/fetcher.js | 1 + packages/kit/src/runtime/client/utils.js | 1 + packages/kit/src/runtime/server/page/index.js | 2 +- .../src/runtime/server/page/load_data.spec.js | 4 +++- .../runtime/server/page/respond_with_error.js | 2 ++ packages/kit/src/utils/fork.js | 2 +- packages/kit/test/utils.js | 8 ++++---- .../migrations/self-closing-tags/index.js | 4 ++-- packages/package/src/index.js | 2 +- 20 files changed, 47 insertions(+), 42 deletions(-) diff --git a/packages/adapter-auto/index.js b/packages/adapter-auto/index.js index 983f6a1fa66c..fe720092bc79 100644 --- a/packages/adapter-auto/index.js +++ b/packages/adapter-auto/index.js @@ -36,9 +36,9 @@ function detect_package_manager() { } /** @param {string} name */ -async function import_from_cwd(name) { +function import_from_cwd(name) { const cwd = pathToFileURL(process.cwd()).href; - const url = await resolve(name, cwd + '/x.js'); + const url = resolve(name, cwd + '/x.js'); return import(url); } diff --git a/packages/adapter-netlify/index.js b/packages/adapter-netlify/index.js index 7bfec980ef9a..8f8a1c5eecd4 100644 --- a/packages/adapter-netlify/index.js +++ b/packages/adapter-netlify/index.js @@ -92,7 +92,7 @@ export default function ({ split = false, edge = edge_set_in_env_var } = {}) { await generate_edge_functions({ builder }); } else { - await generate_lambda_functions({ builder, split, publish }); + generate_lambda_functions({ builder, split, publish }); } }, @@ -182,7 +182,7 @@ async function generate_edge_functions({ builder }) { * @param { string } params.publish * @param { boolean } params.split */ -async function generate_lambda_functions({ builder, publish, split }) { +function generate_lambda_functions({ builder, publish, split }) { builder.mkdirp('.netlify/functions-internal/.svelte-kit'); /** @type {string[]} */ diff --git a/packages/create-svelte/index.js b/packages/create-svelte/index.js index b247b73a1fbb..be274e274337 100755 --- a/packages/create-svelte/index.js +++ b/packages/create-svelte/index.js @@ -3,6 +3,7 @@ import path from 'node:path'; import { mkdirp, copy, dist } from './utils.js'; /** @type {import('./types/index.js').create} */ +// eslint-disable-next-line @typescript-eslint/require-await export async function create(cwd, options) { mkdirp(cwd); diff --git a/packages/enhanced-img/src/index.js b/packages/enhanced-img/src/index.js index bbdac4d9b5d7..e59b1bfe3a84 100644 --- a/packages/enhanced-img/src/index.js +++ b/packages/enhanced-img/src/index.js @@ -5,8 +5,10 @@ import { image } from './preprocessor.js'; /** * @returns {Promise} */ +// TODO make the signature synchronous in the next major? +// eslint-disable-next-line @typescript-eslint/require-await export async function enhancedImages() { - const imagetools_instance = await imagetools_plugin(); + const imagetools_instance = imagetools_plugin(); return !process.versions.webcontainer ? [image_plugin(imagetools_instance), imagetools_instance] : []; @@ -60,7 +62,7 @@ const fallback = { '.webp': 'png' }; -async function imagetools_plugin() { +function imagetools_plugin() { /** @type {Partial} */ const imagetools_opts = { defaultDirectives: async ({ pathname, searchParams: qs }, metadata) => { diff --git a/packages/kit/src/core/sync/write_types/index.js b/packages/kit/src/core/sync/write_types/index.js index 2c2f0fa0b5b3..778f338260c3 100644 --- a/packages/kit/src/core/sync/write_types/index.js +++ b/packages/kit/src/core/sync/write_types/index.js @@ -28,7 +28,7 @@ const cwd = process.cwd(); * @param {import('types').ValidatedConfig} config * @param {import('types').ManifestData} manifest_data */ -export async function write_all_types(config, manifest_data) { +export function write_all_types(config, manifest_data) { if (!ts) return; const types_dir = `${config.kit.outDir}/types`; @@ -133,7 +133,7 @@ export async function write_all_types(config, manifest_data) { * @param {import('types').ManifestData} manifest_data * @param {string} file */ -export async function write_types(config, manifest_data, file) { +export function write_types(config, manifest_data, file) { if (!ts) return; if (!path.basename(file).startsWith('+')) { diff --git a/packages/kit/src/exports/hooks/sequence.spec.js b/packages/kit/src/exports/hooks/sequence.spec.js index a4912bdd5790..0829e90a92e6 100644 --- a/packages/kit/src/exports/hooks/sequence.spec.js +++ b/packages/kit/src/exports/hooks/sequence.spec.js @@ -120,7 +120,7 @@ test('uses first defined preload option', async () => { const event = /** @type {import('@sveltejs/kit').RequestEvent} */ ({}); const response = await handler({ event, - resolve: async (_event, opts = {}) => { + resolve: (_event, opts = {}) => { let html = ''; const { preload = () => false } = opts; @@ -153,7 +153,7 @@ test('uses first defined filterSerializedResponseHeaders option', async () => { const event = /** @type {import('@sveltejs/kit').RequestEvent} */ ({}); const response = await handler({ event, - resolve: async (_event, opts = {}) => { + resolve: (_event, opts = {}) => { let html = ''; const { filterSerializedResponseHeaders = () => false } = opts; diff --git a/packages/kit/src/exports/node/index.js b/packages/kit/src/exports/node/index.js index 77f2a0354ad6..b3fe17c5a4f7 100644 --- a/packages/kit/src/exports/node/index.js +++ b/packages/kit/src/exports/node/index.js @@ -103,6 +103,8 @@ function get_raw_body(req, body_size_limit) { * }} options * @returns {Promise} */ +// TODO 3.0 make the signature synchronous? +// eslint-disable-next-line @typescript-eslint/require-await export async function getRequest({ request, base, bodySizeLimit }) { return new Request(base + request.url, { // @ts-expect-error @@ -121,6 +123,8 @@ export async function getRequest({ request, base, bodySizeLimit }) { * @param {Response} response * @returns {Promise} */ +// TODO 3.0 make the signature synchronous? +// eslint-disable-next-line @typescript-eslint/require-await export async function setResponse(res, response) { for (const [key, value] of response.headers) { try { diff --git a/packages/kit/src/exports/vite/build/build_service_worker.js b/packages/kit/src/exports/vite/build/build_service_worker.js index cd594cdad096..a7c11188d02a 100644 --- a/packages/kit/src/exports/vite/build/build_service_worker.js +++ b/packages/kit/src/exports/vite/build/build_service_worker.js @@ -66,13 +66,13 @@ export async function build_service_worker( */ const sw_virtual_modules = { name: 'service-worker-build-virtual-modules', - async resolveId(id) { + resolveId(id) { if (id.startsWith('$env/') || id.startsWith('$app/') || id === '$service-worker') { return `\0virtual:${id}`; } }, - async load(id) { + load(id) { if (!id.startsWith('\0virtual:')) return; if (id === service_worker) { diff --git a/packages/kit/src/exports/vite/dev/index.js b/packages/kit/src/exports/vite/dev/index.js index 503cb51feb45..a31aee1997e0 100644 --- a/packages/kit/src/exports/vite/dev/index.js +++ b/packages/kit/src/exports/vite/dev/index.js @@ -389,7 +389,7 @@ export async function dev(vite, vite_config, svelte_config) { return ws_send.apply(vite.ws, args); }; - vite.middlewares.use(async (req, res, next) => { + vite.middlewares.use((req, res, next) => { try { const base = `${vite.config.server.https ? 'https' : 'http'}://${ req.headers[':authority'] || req.headers.host diff --git a/packages/kit/src/exports/vite/index.js b/packages/kit/src/exports/vite/index.js index 81689ddb91da..e79a62db8223 100644 --- a/packages/kit/src/exports/vite/index.js +++ b/packages/kit/src/exports/vite/index.js @@ -131,7 +131,7 @@ const warning_preprocessor = { async function resolve_peer_dependency(dependency) { try { // @ts-expect-error the types are wrong - const resolved = await imr.resolve(dependency, pathToFileURL(process.cwd() + '/dummy.js')); + const resolved = imr.resolve(dependency, pathToFileURL(process.cwd() + '/dummy.js')); return import(resolved); } catch { throw new Error( @@ -373,7 +373,7 @@ async function kit({ svelte_config }) { const plugin_virtual_modules = { name: 'vite-plugin-sveltekit-virtual-modules', - async resolveId(id, importer) { + resolveId(id, importer) { // If importing from a service-worker, only allow $service-worker & $env/static/public, but none of the other virtual modules. // This check won't catch transitive imports, but it will warn when the import comes from a service-worker directly. // Transitive imports will be caught during the build. @@ -397,7 +397,7 @@ async function kit({ svelte_config }) { } }, - async load(id, options) { + load(id, options) { const browser = !options?.ssr; const global = is_build @@ -533,7 +533,7 @@ async function kit({ svelte_config }) { writeBundle: { sequential: true, - async handler(_options) { + handler(_options) { if (vite_config.build.ssr) return; const guard = module_guard(this, { @@ -560,7 +560,7 @@ async function kit({ svelte_config }) { * Build the SvelteKit-provided Vite config to be merged with the user's vite.config.js file. * @see https://vitejs.dev/guide/api-plugin.html#config */ - async config(config) { + config(config) { /** @type {import('vite').UserConfig} */ let new_config; diff --git a/packages/kit/src/runtime/client/client.js b/packages/kit/src/runtime/client/client.js index df0148d4e75c..f91728bccc2c 100644 --- a/packages/kit/src/runtime/client/client.js +++ b/packages/kit/src/runtime/client/client.js @@ -469,15 +469,7 @@ function initialize(result, target, hydrate) { * form?: Record | null; * }} opts */ -async function get_navigation_result_from_branch({ - url, - params, - branch, - status, - error, - route, - form -}) { +function get_navigation_result_from_branch({ url, params, branch, status, error, route, form }) { /** @type {import('types').TrailingSlash} */ let slash = 'never'; @@ -1017,7 +1009,7 @@ async function load_route({ id, invalidating, url, params, route, preload }) { const error_load = await load_nearest_error_page(i, branch, errors); if (error_load) { - return await get_navigation_result_from_branch({ + return get_navigation_result_from_branch({ url, params, branch: branch.slice(0, error_load.idx).concat(error_load.node), @@ -1036,7 +1028,7 @@ async function load_route({ id, invalidating, url, params, route, preload }) { } } - return await get_navigation_result_from_branch({ + return get_navigation_result_from_branch({ url, params, branch, @@ -1136,7 +1128,7 @@ async function load_root_error_page({ status, error, url, route }) { data: null }; - return await get_navigation_result_from_branch({ + return get_navigation_result_from_branch({ url, params, branch: [root_layout, root_error], @@ -1942,7 +1934,7 @@ export async function applyAction(result) { const error_load = await load_nearest_error_page(current.branch.length, branch, route.errors); if (error_load) { - const navigation_result = await get_navigation_result_from_branch({ + const navigation_result = get_navigation_result_from_branch({ url, params: current.params, branch: branch.slice(0, error_load.idx).concat(error_load.node), @@ -2364,7 +2356,7 @@ async function _hydrate( } } - result = await get_navigation_result_from_branch({ + result = get_navigation_result_from_branch({ url, params, branch, diff --git a/packages/kit/src/runtime/client/fetcher.js b/packages/kit/src/runtime/client/fetcher.js index 46d7a0b569a3..1d43a5bc905a 100644 --- a/packages/kit/src/runtime/client/fetcher.js +++ b/packages/kit/src/runtime/client/fetcher.js @@ -19,6 +19,7 @@ if (DEV && BROWSER) { let can_inspect_stack_trace = false; // detect whether async stack traces work + // eslint-disable-next-line @typescript-eslint/require-await const check_stack_trace = async () => { const stack = /** @type {string} */ (new Error().stack); can_inspect_stack_trace = stack.includes('check_stack_trace'); diff --git a/packages/kit/src/runtime/client/utils.js b/packages/kit/src/runtime/client/utils.js index d205f48cdc42..16a1b3426a9e 100644 --- a/packages/kit/src/runtime/client/utils.js +++ b/packages/kit/src/runtime/client/utils.js @@ -240,6 +240,7 @@ export function create_updated_store() { if (DEV || !BROWSER) { return { subscribe, + // eslint-disable-next-line @typescript-eslint/require-await check: async () => false }; } diff --git a/packages/kit/src/runtime/server/page/index.js b/packages/kit/src/runtime/server/page/index.js index b90bf67eef58..3424c5fcdce5 100644 --- a/packages/kit/src/runtime/server/page/index.js +++ b/packages/kit/src/runtime/server/page/index.js @@ -146,7 +146,7 @@ export async function render_page(event, page, options, manifest, state, resolve const data = {}; for (let j = 0; j < i; j += 1) { const parent = await server_promises[j]; - if (parent) Object.assign(data, await parent.data); + if (parent) Object.assign(data, parent.data); } return data; } diff --git a/packages/kit/src/runtime/server/page/load_data.spec.js b/packages/kit/src/runtime/server/page/load_data.spec.js index ec3167c08822..bed961fbb872 100644 --- a/packages/kit/src/runtime/server/page/load_data.spec.js +++ b/packages/kit/src/runtime/server/page/load_data.spec.js @@ -5,6 +5,7 @@ import { create_universal_fetch } from './load_data.js'; * @param {Partial>} event */ function create_fetch(event) { + // eslint-disable-next-line @typescript-eslint/require-await event.fetch = event.fetch || (async () => new Response('foo')); event.request = event.request || new Request('doesnt:matter'); event.route = event.route || { id: 'foo' }; @@ -38,6 +39,7 @@ test('keeps body when mode isnt no-cors on same domain', async () => { test('succeeds when acao header present on cors', async () => { const fetch = create_fetch({ + // eslint-disable-next-line @typescript-eslint/require-await fetch: async () => new Response('foo', { headers: { 'access-control-allow-origin': '*' } }) }); const response = await fetch('https://domain-a.com'); @@ -45,7 +47,7 @@ test('succeeds when acao header present on cors', async () => { assert.equal(text, 'foo'); }); -test('errors when no acao header present on cors', async () => { +test('errors when no acao header present on cors', () => { const fetch = create_fetch({}); expect(async () => { diff --git a/packages/kit/src/runtime/server/page/respond_with_error.js b/packages/kit/src/runtime/server/page/respond_with_error.js index 121ebc5406f2..10bf3fe0d324 100644 --- a/packages/kit/src/runtime/server/page/respond_with_error.js +++ b/packages/kit/src/runtime/server/page/respond_with_error.js @@ -50,6 +50,7 @@ export async function respond_with_error({ event, state, node: default_layout, + // eslint-disable-next-line @typescript-eslint/require-await parent: async () => ({}) }); @@ -59,6 +60,7 @@ export async function respond_with_error({ event, fetched, node: default_layout, + // eslint-disable-next-line @typescript-eslint/require-await parent: async () => ({}), resolve_opts, server_data_promise, diff --git a/packages/kit/src/utils/fork.js b/packages/kit/src/utils/fork.js index 96d513a21e6f..28dc8a798853 100644 --- a/packages/kit/src/utils/fork.js +++ b/packages/kit/src/utils/fork.js @@ -7,7 +7,7 @@ import { Worker, parentPort } from 'node:worker_threads'; * @template T * @template U * @param {string} module `import.meta.url` of the file - * @param {(opts: T) => U} callback The function that is invoked in the subprocess + * @param {(opts: T) => Promise} callback The function that is invoked in the subprocess * @returns {(opts: T) => Promise} A function that when called starts the subprocess */ export function forked(module, callback) { diff --git a/packages/kit/test/utils.js b/packages/kit/test/utils.js index 38e4faaedd6c..630ed1c061a8 100644 --- a/packages/kit/test/utils.js +++ b/packages/kit/test/utils.js @@ -5,7 +5,7 @@ import { fileURLToPath } from 'node:url'; import { test as base, devices } from '@playwright/test'; export const test = base.extend({ - app: async ({ page }, use) => { + app: ({ page }, use) => { // these are assumed to have been put in the global scope by the layout use({ /** @@ -52,7 +52,7 @@ export const test = base.extend({ }); }, - clicknav: async ({ page, javaScriptEnabled }, use) => { + clicknav: ({ page, javaScriptEnabled }, use) => { /** * @param {string} selector * @param {{ timeout: number }} options @@ -69,7 +69,7 @@ export const test = base.extend({ use(clicknav); }, - in_view: async ({ page }, use) => { + in_view: ({ page }, use) => { /** @param {string} selector */ async function in_view(selector) { const box = await page.locator(selector).boundingBox(); @@ -85,7 +85,7 @@ export const test = base.extend({ * @param {string} selector * @param {string} prop */ - async function get_computed_style(selector, prop) { + function get_computed_style(selector, prop) { return page.$eval( selector, (node, prop) => window.getComputedStyle(node).getPropertyValue(prop), diff --git a/packages/migrate/migrations/self-closing-tags/index.js b/packages/migrate/migrations/self-closing-tags/index.js index 1c11ea56c448..40bcabfa65bc 100644 --- a/packages/migrate/migrations/self-closing-tags/index.js +++ b/packages/migrate/migrations/self-closing-tags/index.js @@ -48,9 +48,9 @@ export async function migrate() { } /** @param {string} name */ -async function import_from_cwd(name) { +function import_from_cwd(name) { const cwd = pathToFileURL(process.cwd()).href; - const url = await resolve(name, cwd + '/x.js'); + const url = resolve(name, cwd + '/x.js'); return import(url); } diff --git a/packages/package/src/index.js b/packages/package/src/index.js index 6d7450182643..a6cbda297cbb 100644 --- a/packages/package/src/index.js +++ b/packages/package/src/index.js @@ -80,7 +80,7 @@ export async function watch(options) { const watcher = chokidar.watch(input, { ignoreInitial: true }); const ready = new Promise((resolve) => watcher.on('ready', resolve)); - watcher.on('all', async (type, filepath) => { + watcher.on('all', (type, filepath) => { const file = analyze(path.relative(input, filepath), extensions); pending.push({ file, type }); From e7410071bb522189ba8ac3eb7d6b4d97b24dfbbe Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Tue, 4 Jun 2024 16:23:41 -0400 Subject: [PATCH 3/9] more --- packages/kit/postinstall.js | 2 +- packages/kit/src/cli.js | 2 +- packages/kit/src/core/sync/sync.js | 18 ++++++++---------- packages/kit/src/exports/vite/dev/index.js | 6 +++--- packages/kit/src/exports/vite/index.js | 4 ++-- 5 files changed, 15 insertions(+), 17 deletions(-) diff --git a/packages/kit/postinstall.js b/packages/kit/postinstall.js index da908bbf8537..8d6d9ed37b8e 100644 --- a/packages/kit/postinstall.js +++ b/packages/kit/postinstall.js @@ -40,7 +40,7 @@ try { try { const config = await load_config(); - await sync.all(config, 'development'); + sync.all(config, 'development'); } catch (error) { console.error('Error while trying to sync SvelteKit config'); console.error(error); diff --git a/packages/kit/src/cli.js b/packages/kit/src/cli.js index 9cf2cfaf1afe..99c339844230 100755 --- a/packages/kit/src/cli.js +++ b/packages/kit/src/cli.js @@ -35,7 +35,7 @@ prog try { const config = await load_config(); const sync = await import('./core/sync/sync.js'); - await sync.all_types(config, mode); + sync.all_types(config, mode); } catch (error) { handle_error(error); } diff --git a/packages/kit/src/core/sync/sync.js b/packages/kit/src/core/sync/sync.js index d16466818f40..a96e40bc0928 100644 --- a/packages/kit/src/core/sync/sync.js +++ b/packages/kit/src/core/sync/sync.js @@ -23,7 +23,7 @@ export function init(config, mode) { * Update SvelteKit's generated files * @param {import('types').ValidatedConfig} config */ -export async function create(config) { +export function create(config) { const manifest_data = create_manifest_data({ config }); const output = path.join(config.kit.outDir, 'generated'); @@ -31,7 +31,7 @@ export async function create(config) { write_client_manifest(config.kit, manifest_data, `${output}/client`); write_server(config, output); write_root(manifest_data, output); - await write_all_types(config, manifest_data); + write_all_types(config, manifest_data); return { manifest_data }; } @@ -44,10 +44,8 @@ export async function create(config) { * @param {import('types').ManifestData} manifest_data * @param {string} file */ -export async function update(config, manifest_data, file) { - await write_types(config, manifest_data, file); - - return { manifest_data }; +export function update(config, manifest_data, file) { + write_types(config, manifest_data, file); } /** @@ -55,9 +53,9 @@ export async function update(config, manifest_data, file) { * @param {import('types').ValidatedConfig} config * @param {string} mode The Vite mode */ -export async function all(config, mode) { +export function all(config, mode) { init(config, mode); - return await create(config); + return create(config); } /** @@ -65,10 +63,10 @@ export async function all(config, mode) { * @param {import('types').ValidatedConfig} config * @param {string} mode The Vite mode */ -export async function all_types(config, mode) { +export function all_types(config, mode) { init(config, mode); const manifest_data = create_manifest_data({ config }); - await write_all_types(config, manifest_data); + write_all_types(config, manifest_data); } /** diff --git a/packages/kit/src/exports/vite/dev/index.js b/packages/kit/src/exports/vite/dev/index.js index a31aee1997e0..e3e69432aa81 100644 --- a/packages/kit/src/exports/vite/dev/index.js +++ b/packages/kit/src/exports/vite/dev/index.js @@ -97,9 +97,9 @@ export async function dev(vite, vite_config, svelte_config) { return { module, module_node, url }; } - async function update_manifest() { + function update_manifest() { try { - ({ manifest_data } = await sync.create(svelte_config)); + ({ manifest_data } = sync.create(svelte_config)); if (manifest_error) { manifest_error = null; @@ -273,7 +273,7 @@ export async function dev(vite, vite_config, svelte_config) { return error.stack; } - await update_manifest(); + update_manifest(); /** * @param {string} event diff --git a/packages/kit/src/exports/vite/index.js b/packages/kit/src/exports/vite/index.js index e79a62db8223..402fa009bf64 100644 --- a/packages/kit/src/exports/vite/index.js +++ b/packages/kit/src/exports/vite/index.js @@ -242,7 +242,7 @@ async function kit({ svelte_config }) { * Build the SvelteKit-provided Vite config to be merged with the user's vite.config.js file. * @see https://vitejs.dev/guide/api-plugin.html#config */ - async config(config, config_env) { + config(config, config_env) { initial_config = config; vite_config_env = config_env; is_build = config_env.command === 'build'; @@ -339,7 +339,7 @@ async function kit({ svelte_config }) { }; if (!secondary_build_started) { - manifest_data = (await sync.all(svelte_config, config_env.mode)).manifest_data; + manifest_data = sync.all(svelte_config, config_env.mode).manifest_data; } } else { new_config.define = { From c5280d5c6b75370fc917adb22fd8e37e0ccf01e0 Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Tue, 4 Jun 2024 16:29:38 -0400 Subject: [PATCH 4/9] another --- packages/kit/src/core/sync/write_types/index.spec.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/kit/src/core/sync/write_types/index.spec.js b/packages/kit/src/core/sync/write_types/index.spec.js index d50a4d12fa82..5fd7a9571703 100644 --- a/packages/kit/src/core/sync/write_types/index.spec.js +++ b/packages/kit/src/core/sync/write_types/index.spec.js @@ -25,7 +25,8 @@ async function run_test(dir) { const manifest = create_manifest_data({ config: /** @type {import('types').ValidatedConfig} */ (initial) }); - await write_all_types(initial, manifest); + + write_all_types(initial, manifest); } test('Creates correct $types', async () => { From 0b26f26b3978dc64ba00b6f60f2ea0617f23186b Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Wed, 5 Jun 2024 15:43:57 -0400 Subject: [PATCH 5/9] make enhancedImages synchronous --- .changeset/modern-deers-grab.md | 5 +++++ packages/enhanced-img/src/index.js | 6 ++---- 2 files changed, 7 insertions(+), 4 deletions(-) create mode 100644 .changeset/modern-deers-grab.md diff --git a/.changeset/modern-deers-grab.md b/.changeset/modern-deers-grab.md new file mode 100644 index 000000000000..a1ccab60c340 --- /dev/null +++ b/.changeset/modern-deers-grab.md @@ -0,0 +1,5 @@ +--- +'@sveltejs/enhanced-img': minor +--- + +breaking: return plugin synchronously from `enhancedImages()` diff --git a/packages/enhanced-img/src/index.js b/packages/enhanced-img/src/index.js index e59b1bfe3a84..7e46b9570127 100644 --- a/packages/enhanced-img/src/index.js +++ b/packages/enhanced-img/src/index.js @@ -3,11 +3,9 @@ import { imagetools } from 'vite-imagetools'; import { image } from './preprocessor.js'; /** - * @returns {Promise} + * @returns {import('vite').Plugin[]} */ -// TODO make the signature synchronous in the next major? -// eslint-disable-next-line @typescript-eslint/require-await -export async function enhancedImages() { +export function enhancedImages() { const imagetools_instance = imagetools_plugin(); return !process.versions.webcontainer ? [image_plugin(imagetools_instance), imagetools_instance] From 6d388127fd81f6f98fecc0492073b8926148b5fa Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Wed, 5 Jun 2024 15:59:12 -0400 Subject: [PATCH 6/9] more --- .../src/core/sync/write_types/index.spec.js | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/packages/kit/src/core/sync/write_types/index.spec.js b/packages/kit/src/core/sync/write_types/index.spec.js index 5fd7a9571703..6aa4de64ea7d 100644 --- a/packages/kit/src/core/sync/write_types/index.spec.js +++ b/packages/kit/src/core/sync/write_types/index.spec.js @@ -12,7 +12,7 @@ const cwd = fileURLToPath(new URL('./test', import.meta.url)); /** * @param {string} dir */ -async function run_test(dir) { +function run_test(dir) { rimraf(path.join(cwd, dir, '.svelte-kit')); const initial = options({}, 'config'); @@ -29,19 +29,19 @@ async function run_test(dir) { write_all_types(initial, manifest); } -test('Creates correct $types', async () => { +test('Creates correct $types', () => { // To save us from creating a real SvelteKit project for each of the tests, // we first run the type generation directly for each test case, and then // call `tsc` to check that the generated types are valid. - await run_test('actions'); - await run_test('simple-page-shared-only'); - await run_test('simple-page-server-only'); - await run_test('simple-page-server-and-shared'); - await run_test('layout'); - await run_test('layout-advanced'); - await run_test('slugs'); - await run_test('slugs-layout-not-all-pages-have-load'); - await run_test('param-type-inference'); + run_test('actions'); + run_test('simple-page-shared-only'); + run_test('simple-page-server-only'); + run_test('simple-page-server-and-shared'); + run_test('layout'); + run_test('layout-advanced'); + run_test('slugs'); + run_test('slugs-layout-not-all-pages-have-load'); + run_test('param-type-inference'); try { execSync('pnpm testtypes', { cwd }); } catch (e) { From 596592d37d12ba251a5992c431a457bc976bcc0b Mon Sep 17 00:00:00 2001 From: Ben McCann <322311+benmccann@users.noreply.github.com> Date: Wed, 5 Jun 2024 13:37:02 -0700 Subject: [PATCH 7/9] reduce global ignores --- eslint.config.js | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/eslint.config.js b/eslint.config.js index f44b6e2eb49e..33fb2ba4bd1d 100644 --- a/eslint.config.js +++ b/eslint.config.js @@ -4,25 +4,32 @@ import svelte_config from '@sveltejs/eslint-config'; export default [ ...svelte_config, { - languageOptions: { - parserOptions: { - project: true - } - }, rules: { - '@typescript-eslint/await-thenable': 'error', - '@typescript-eslint/no-unused-expressions': 'off', - '@typescript-eslint/require-await': 'error', 'no-undef': 'off' } }, { + // global ignores. must be specified alone ignores: [ '**/.svelte-kit', 'packages/adapter-static/test/apps/*/build', 'packages/adapter-cloudflare/files', 'packages/adapter-netlify/files', - 'packages/adapter-node/files', + 'packages/adapter-node/files' + ] + }, + { + languageOptions: { + parserOptions: { + project: true + } + }, + rules: { + '@typescript-eslint/await-thenable': 'error', + '@typescript-eslint/no-unused-expressions': 'off', + '@typescript-eslint/require-await': 'error', + }, + ignores: [ 'packages/adapter-node/rollup.config.js', 'packages/adapter-node/tests/smoke.spec.js', 'packages/adapter-static/test/apps', From e3e45c0d7256ebc08c67c80816f0dc29e329d71d Mon Sep 17 00:00:00 2001 From: Ben McCann <322311+benmccann@users.noreply.github.com> Date: Wed, 5 Jun 2024 13:48:22 -0700 Subject: [PATCH 8/9] Revert "reduce global ignores" This reverts commit 596592d37d12ba251a5992c431a457bc976bcc0b. --- eslint.config.js | 25 +++++++++---------------- 1 file changed, 9 insertions(+), 16 deletions(-) diff --git a/eslint.config.js b/eslint.config.js index 33fb2ba4bd1d..f44b6e2eb49e 100644 --- a/eslint.config.js +++ b/eslint.config.js @@ -3,21 +3,6 @@ import svelte_config from '@sveltejs/eslint-config'; /** @type {import('eslint').Linter.FlatConfig[]} */ export default [ ...svelte_config, - { - rules: { - 'no-undef': 'off' - } - }, - { - // global ignores. must be specified alone - ignores: [ - '**/.svelte-kit', - 'packages/adapter-static/test/apps/*/build', - 'packages/adapter-cloudflare/files', - 'packages/adapter-netlify/files', - 'packages/adapter-node/files' - ] - }, { languageOptions: { parserOptions: { @@ -28,8 +13,16 @@ export default [ '@typescript-eslint/await-thenable': 'error', '@typescript-eslint/no-unused-expressions': 'off', '@typescript-eslint/require-await': 'error', - }, + 'no-undef': 'off' + } + }, + { ignores: [ + '**/.svelte-kit', + 'packages/adapter-static/test/apps/*/build', + 'packages/adapter-cloudflare/files', + 'packages/adapter-netlify/files', + 'packages/adapter-node/files', 'packages/adapter-node/rollup.config.js', 'packages/adapter-node/tests/smoke.spec.js', 'packages/adapter-static/test/apps', From 136e7d457b41b05a3c3141ab49021e853a9b3bb8 Mon Sep 17 00:00:00 2001 From: Ben McCann <322311+benmccann@users.noreply.github.com> Date: Wed, 5 Jun 2024 14:05:44 -0700 Subject: [PATCH 9/9] add TODO --- eslint.config.js | 1 + 1 file changed, 1 insertion(+) diff --git a/eslint.config.js b/eslint.config.js index f44b6e2eb49e..769f3f260f3e 100644 --- a/eslint.config.js +++ b/eslint.config.js @@ -23,6 +23,7 @@ export default [ 'packages/adapter-cloudflare/files', 'packages/adapter-netlify/files', 'packages/adapter-node/files', + // TODO: figure out if we can ignore these only for @typescript-eslint 'packages/adapter-node/rollup.config.js', 'packages/adapter-node/tests/smoke.spec.js', 'packages/adapter-static/test/apps',