File tree Expand file tree Collapse file tree 1 file changed +23
-0
lines changed
packages/vite/src/node/plugins Expand file tree Collapse file tree 1 file changed +23
-0
lines changed Original file line number Diff line number Diff line change @@ -49,10 +49,33 @@ function saveEmitWorkerAsset(
4949 workerMap . assets . set ( fileName , asset )
5050}
5151
52+ // Ensure that only one rollup build is called at the same time to avoid
53+ // leaking state in plugins between worker builds.
54+ // TODO: Review if we can parallelize the bundling of workers.
55+ const workerConfigSemaphore = new WeakMap <
56+ ResolvedConfig ,
57+ Promise < OutputChunk >
58+ > ( )
5259export async function bundleWorkerEntry (
5360 config : ResolvedConfig ,
5461 id : string ,
5562 query : Record < string , string > | null ,
63+ ) : Promise < OutputChunk > {
64+ const processing = workerConfigSemaphore . get ( config )
65+ if ( processing ) {
66+ await processing
67+ return bundleWorkerEntry ( config , id , query )
68+ }
69+ const promise = serialBundleWorkerEntry ( config , id , query )
70+ workerConfigSemaphore . set ( config , promise )
71+ promise . then ( ( ) => workerConfigSemaphore . delete ( config ) )
72+ return promise
73+ }
74+
75+ async function serialBundleWorkerEntry (
76+ config : ResolvedConfig ,
77+ id : string ,
78+ query : Record < string , string > | null ,
5679) : Promise < OutputChunk > {
5780 // bundle the file as entry to support imports
5881 const { rollup } = await import ( 'rollup' )
You can’t perform that action at this time.
0 commit comments