Skip to content

Commit

Permalink
fix: less promises for scanning and await with allSettled (#11245)
Browse files Browse the repository at this point in the history
  • Loading branch information
dominikg committed Dec 7, 2022
1 parent bb235b2 commit 45b170e
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 20 deletions.
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 @@ -419,7 +419,7 @@ export async function createServer(
process.stdin.off('end', exitProcess)
}
}
await Promise.all([
await Promise.allSettled([
watcher.close(),
ws.close(),
container.close(),
Expand Down

0 comments on commit 45b170e

Please sign in to comment.