Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: less promises for scanning and await with allSettled #11245

Merged
merged 2 commits into from Dec 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 7 additions & 5 deletions packages/vite/src/node/optimizer/optimizer.ts
Expand Up @@ -168,11 +168,13 @@ async function createDepsOptimizer(
let optimizingNewDeps: Promise<DepOptimizationResult> | undefined
async function close() {
closed = true
await discoverProjectDependenciesPromise?.catch(() => {
/* ignore error for scanner because it's not important */
})
await postScanOptimizationResult
await optimizingNewDeps
await Promise.allSettled([
discoverProjectDependenciesPromise?.catch(() => {
/* ignore error for scanner because it's not important */
}),
postScanOptimizationResult,
optimizingNewDeps,
])
}

if (!cachedMetadata) {
Expand Down
27 changes: 13 additions & 14 deletions packages/vite/src/node/optimizer/scan.ts
Expand Up @@ -106,20 +106,19 @@ export async function scanImports(config: ResolvedConfig): Promise<{
const { plugins = [], ...esbuildOptions } =
config.optimizeDeps?.esbuildOptions ?? {}

await Promise.all(
entries.map((entry) =>
build({
absWorkingDir: process.cwd(),
write: false,
entryPoints: [entry],
bundle: true,
format: 'esm',
logLevel: 'error',
plugins: [...plugins, plugin],
...esbuildOptions,
}),
),
)
await build({
absWorkingDir: process.cwd(),
write: false,
stdin: {
contents: entries.map((e) => `import '${e}'`).join('\n'),
loader: 'js',
},
bundle: true,
format: 'esm',
logLevel: 'error',
plugins: [...plugins, plugin],
...esbuildOptions,
})

debug(`Scan completed in ${(performance.now() - start).toFixed(2)}ms:`, deps)

Expand Down
2 changes: 1 addition & 1 deletion packages/vite/src/node/server/index.ts
Expand Up @@ -410,7 +410,7 @@ export async function createServer(
process.stdin.off('end', exitProcess)
}
}
await Promise.all([
await Promise.allSettled([
watcher.close(),
ws.close(),
container.close(),
Expand Down