Skip to content

Commit

Permalink
chore: try serialize esbuild
Browse files Browse the repository at this point in the history
  • Loading branch information
patak-dev committed Jul 2, 2022
1 parent 6eb114d commit 387b18e
Showing 1 changed file with 36 additions and 1 deletion.
37 changes: 36 additions & 1 deletion packages/vite/src/node/optimizer/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -429,11 +429,46 @@ export function depsLogString(qualifiedIds: string[]): string {
}
}

const esbuildQueue: (() => Promise<any>)[] = []
let esbuildProcessing = false
export function enqueueEsbuildTask(task: () => Promise<any>): void {
esbuildQueue.push(task)
if (!esbuildProcessing) {
processNext()
}
}
async function processNext() {
const task = esbuildQueue.shift()
if (task) {
esbuildProcessing = true
await task()
if (esbuildQueue.length > 0) {
processNext()
} else {
esbuildProcessing = false
}
}
}

export function runOptimizeDeps(
resolvedConfig: ResolvedConfig,
depsInfo: Record<string, OptimizedDepInfo>,
ssr: boolean = !!resolvedConfig.build.ssr
): Promise<DepOptimizationResult> {
return new Promise((resolve) => {
enqueueEsbuildTask(() => {
const result = _runOptimizeDeps(resolvedConfig, depsInfo, ssr)
resolve(result)
return result
})
})
}

/**
* Internally, Vite uses this function to prepare a optimizeDeps run. When Vite starts, we can get
* the metadata and start the server without waiting for the optimizeDeps processing to be completed
*/
export async function runOptimizeDeps(
async function _runOptimizeDeps(
resolvedConfig: ResolvedConfig,
depsInfo: Record<string, OptimizedDepInfo>,
ssr: boolean = !!resolvedConfig.build.ssr
Expand Down

0 comments on commit 387b18e

Please sign in to comment.