@@ -178,30 +178,41 @@ export async function copyJsModule(moduleSourcePath, to) {
178178 actualSourcePath = realpathSync ( moduleSourcePath ) ;
179179 }
180180
181- cpSync ( actualSourcePath , to , {
182- recursive : true ,
183- dereference : true , // Follow symlinks and copy the actual files
184- filter : ( src , dest ) => {
185- const relativePath = src . replace ( actualSourcePath , "" ) . replace ( / ^ [ \\ / ] / , "" ) ;
186-
187- // Skip certain directories
188- if ( relativePath . match ( / [ \\ / ] ( a n d r o i d | i o s | w i n d o w s | m a c | j e s t | g i t h u b | g r a d l e | _ _ .* _ _ | d o c s | e x a m p l e .* ) [ \\ / ] / ) ) {
189- return false ;
190- }
181+ try {
182+ cpSync ( actualSourcePath , to , {
183+ recursive : true ,
184+ dereference : true , // Follow symlinks and copy the actual files
185+ filter : ( src , dest ) => {
186+ const relativePath = src . replace ( actualSourcePath , "" ) . replace ( / ^ [ \\ / ] / , "" ) ;
187+
188+ // Skip certain directories
189+ if (
190+ relativePath . match ( / [ \\ / ] ( a n d r o i d | i o s | w i n d o w s | m a c | j e s t | g i t h u b | g r a d l e | _ _ .* _ _ | d o c s | e x a m p l e .* ) [ \\ / ] / )
191+ ) {
192+ return false ;
193+ }
191194
192- // Skip certain file types
193- if ( relativePath . match ( / \. ( c o n f i g | s e t u p ) \. | \. p o d s p e c $ | \. f l o w $ / ) ) {
194- return false ;
195- }
195+ // Skip certain file types
196+ if ( relativePath . match ( / \. ( c o n f i g | s e t u p ) \. | \. p o d s p e c $ | \. f l o w $ / ) ) {
197+ return false ;
198+ }
199+
200+ // Include LICENSE files
201+ if ( relativePath . match ( / l i c e n s e / i) ) {
202+ return true ;
203+ }
196204
197- // Include LICENSE files
198- if ( relativePath . match ( / l i c e n s e / i) ) {
199205 return true ;
200206 }
201-
202- return true ;
207+ } ) ;
208+ } catch ( error ) {
209+ // Handle race condition: if another parallel build process already created this directory,
210+ // ignore EEXIST errors and verify the directory now exists
211+ if ( error . code === "EEXIST" && existsSync ( to ) ) {
212+ return ;
203213 }
204- } ) ;
214+ throw error ;
215+ }
205216}
206217
207218function getModuleName ( modulePath ) {
0 commit comments