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: serialize bundleWorkerEntry #11218

Merged
merged 3 commits into from Dec 6, 2022
Merged
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
23 changes: 23 additions & 0 deletions packages/vite/src/node/plugins/worker.ts
Expand Up @@ -49,10 +49,33 @@ function saveEmitWorkerAsset(
workerMap.assets.set(fileName, asset)
}

// Ensure that only one rollup build is called at the same time to avoid
// leaking state in plugins between worker builds.
patak-dev marked this conversation as resolved.
Show resolved Hide resolved
// TODO: Review if we can parallelize the bundling of workers.
const workerConfigSemaphore = new WeakMap<
patak-dev marked this conversation as resolved.
Show resolved Hide resolved
ResolvedConfig,
Promise<OutputChunk>
>()
export async function bundleWorkerEntry(
config: ResolvedConfig,
id: string,
query: Record<string, string> | null,
): Promise<OutputChunk> {
const processing = workerConfigSemaphore.get(config)
if (processing) {
await processing
return bundleWorkerEntry(config, id, query)
}
const promise = serialBundleWorkerEntry(config, id, query)
workerConfigSemaphore.set(config, promise)
promise.then(() => workerConfigSemaphore.delete(config))
return promise
}

async function serialBundleWorkerEntry(
config: ResolvedConfig,
id: string,
query: Record<string, string> | null,
): Promise<OutputChunk> {
// bundle the file as entry to support imports
const { rollup } = await import('rollup')
Expand Down