File tree 1 file changed +23
-0
lines changed
packages/vite/src/node/plugins
1 file changed +23
-0
lines changed Original file line number Diff line number Diff line change @@ -49,10 +49,33 @@ function saveEmitWorkerAsset(
49
49
workerMap . assets . set ( fileName , asset )
50
50
}
51
51
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
+ > ( )
52
59
export async function bundleWorkerEntry (
53
60
config : ResolvedConfig ,
54
61
id : string ,
55
62
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 ,
56
79
) : Promise < OutputChunk > {
57
80
// bundle the file as entry to support imports
58
81
const { rollup } = await import ( 'rollup' )
You can’t perform that action at this time.
0 commit comments