Skip to content

Commit 8967235

Browse files
chore: cleanup promise handling (#12297)
Co-authored-by: Ben McCann <[email protected]>
1 parent 7133648 commit 8967235

File tree

26 files changed

+100
-74
lines changed

26 files changed

+100
-74
lines changed

.changeset/modern-deers-grab.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@sveltejs/enhanced-img': minor
3+
---
4+
5+
breaking: return plugin synchronously from `enhancedImages()`

eslint.config.js

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,15 @@ import svelte_config from '@sveltejs/eslint-config';
44
export default [
55
...svelte_config,
66
{
7+
languageOptions: {
8+
parserOptions: {
9+
project: true
10+
}
11+
},
712
rules: {
13+
'@typescript-eslint/await-thenable': 'error',
814
'@typescript-eslint/no-unused-expressions': 'off',
15+
'@typescript-eslint/require-await': 'error',
916
'no-undef': 'off'
1017
}
1118
},
@@ -15,7 +22,19 @@ export default [
1522
'packages/adapter-static/test/apps/*/build',
1623
'packages/adapter-cloudflare/files',
1724
'packages/adapter-netlify/files',
18-
'packages/adapter-node/files'
25+
'packages/adapter-node/files',
26+
// TODO: figure out if we can ignore these only for @typescript-eslint
27+
'packages/adapter-node/rollup.config.js',
28+
'packages/adapter-node/tests/smoke.spec.js',
29+
'packages/adapter-static/test/apps',
30+
'packages/create-svelte/shared',
31+
'packages/create-svelte/templates',
32+
'packages/kit/src/core/sync/create_manifest_data/test/samples',
33+
'packages/kit/test/apps',
34+
'packages/kit/test/build-errors',
35+
'packages/kit/test/prerendering',
36+
'packages/package/test/errors',
37+
'packages/package/test/fixtures'
1938
]
2039
}
2140
];

packages/adapter-auto/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ function detect_package_manager() {
3636
}
3737

3838
/** @param {string} name */
39-
async function import_from_cwd(name) {
39+
function import_from_cwd(name) {
4040
const cwd = pathToFileURL(process.cwd()).href;
41-
const url = await resolve(name, cwd + '/x.js');
41+
const url = resolve(name, cwd + '/x.js');
4242

4343
return import(url);
4444
}

packages/adapter-netlify/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ export default function ({ split = false, edge = edge_set_in_env_var } = {}) {
9292

9393
await generate_edge_functions({ builder });
9494
} else {
95-
await generate_lambda_functions({ builder, split, publish });
95+
generate_lambda_functions({ builder, split, publish });
9696
}
9797
},
9898

@@ -182,7 +182,7 @@ async function generate_edge_functions({ builder }) {
182182
* @param { string } params.publish
183183
* @param { boolean } params.split
184184
*/
185-
async function generate_lambda_functions({ builder, publish, split }) {
185+
function generate_lambda_functions({ builder, publish, split }) {
186186
builder.mkdirp('.netlify/functions-internal/.svelte-kit');
187187

188188
/** @type {string[]} */

packages/create-svelte/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import path from 'node:path';
33
import { mkdirp, copy, dist } from './utils.js';
44

55
/** @type {import('./types/index.js').create} */
6+
// eslint-disable-next-line @typescript-eslint/require-await
67
export async function create(cwd, options) {
78
mkdirp(cwd);
89

packages/enhanced-img/src/index.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ import { imagetools } from 'vite-imagetools';
33
import { image } from './preprocessor.js';
44

55
/**
6-
* @returns {Promise<import('vite').Plugin[]>}
6+
* @returns {import('vite').Plugin[]}
77
*/
8-
export async function enhancedImages() {
9-
const imagetools_instance = await imagetools_plugin();
8+
export function enhancedImages() {
9+
const imagetools_instance = imagetools_plugin();
1010
return !process.versions.webcontainer
1111
? [image_plugin(imagetools_instance), imagetools_instance]
1212
: [];
@@ -60,7 +60,7 @@ const fallback = {
6060
'.webp': 'png'
6161
};
6262

63-
async function imagetools_plugin() {
63+
function imagetools_plugin() {
6464
/** @type {Partial<import('vite-imagetools').VitePluginOptions>} */
6565
const imagetools_opts = {
6666
defaultDirectives: async ({ pathname, searchParams: qs }, metadata) => {

packages/kit/postinstall.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ try {
4040

4141
try {
4242
const config = await load_config();
43-
await sync.all(config, 'development');
43+
sync.all(config, 'development');
4444
} catch (error) {
4545
console.error('Error while trying to sync SvelteKit config');
4646
console.error(error);

packages/kit/src/cli.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ prog
3535
try {
3636
const config = await load_config();
3737
const sync = await import('./core/sync/sync.js');
38-
await sync.all_types(config, mode);
38+
sync.all_types(config, mode);
3939
} catch (error) {
4040
handle_error(error);
4141
}

packages/kit/src/core/sync/sync.js

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,15 @@ export function init(config, mode) {
2323
* Update SvelteKit's generated files
2424
* @param {import('types').ValidatedConfig} config
2525
*/
26-
export async function create(config) {
26+
export function create(config) {
2727
const manifest_data = create_manifest_data({ config });
2828

2929
const output = path.join(config.kit.outDir, 'generated');
3030

3131
write_client_manifest(config.kit, manifest_data, `${output}/client`);
3232
write_server(config, output);
3333
write_root(manifest_data, output);
34-
await write_all_types(config, manifest_data);
34+
write_all_types(config, manifest_data);
3535

3636
return { manifest_data };
3737
}
@@ -44,31 +44,29 @@ export async function create(config) {
4444
* @param {import('types').ManifestData} manifest_data
4545
* @param {string} file
4646
*/
47-
export async function update(config, manifest_data, file) {
48-
await write_types(config, manifest_data, file);
49-
50-
return { manifest_data };
47+
export function update(config, manifest_data, file) {
48+
write_types(config, manifest_data, file);
5149
}
5250

5351
/**
5452
* Run sync.init and sync.create in series, returning the result from sync.create.
5553
* @param {import('types').ValidatedConfig} config
5654
* @param {string} mode The Vite mode
5755
*/
58-
export async function all(config, mode) {
56+
export function all(config, mode) {
5957
init(config, mode);
60-
return await create(config);
58+
return create(config);
6159
}
6260

6361
/**
6462
* Run sync.init and then generate all type files.
6563
* @param {import('types').ValidatedConfig} config
6664
* @param {string} mode The Vite mode
6765
*/
68-
export async function all_types(config, mode) {
66+
export function all_types(config, mode) {
6967
init(config, mode);
7068
const manifest_data = create_manifest_data({ config });
71-
await write_all_types(config, manifest_data);
69+
write_all_types(config, manifest_data);
7270
}
7371

7472
/**

packages/kit/src/core/sync/write_types/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ const cwd = process.cwd();
2828
* @param {import('types').ValidatedConfig} config
2929
* @param {import('types').ManifestData} manifest_data
3030
*/
31-
export async function write_all_types(config, manifest_data) {
31+
export function write_all_types(config, manifest_data) {
3232
if (!ts) return;
3333

3434
const types_dir = `${config.kit.outDir}/types`;
@@ -133,7 +133,7 @@ export async function write_all_types(config, manifest_data) {
133133
* @param {import('types').ManifestData} manifest_data
134134
* @param {string} file
135135
*/
136-
export async function write_types(config, manifest_data, file) {
136+
export function write_types(config, manifest_data, file) {
137137
if (!ts) return;
138138

139139
if (!path.basename(file).startsWith('+')) {

0 commit comments

Comments
 (0)