@@ -70,7 +70,6 @@ class CopyPlugin {
7070 }
7171
7272 static async runPattern (
73- assetMap ,
7473 compiler ,
7574 compilation ,
7675 logger ,
@@ -319,7 +318,6 @@ class CopyPlugin {
319318 sourceFilename,
320319 filename,
321320 toType,
322- priority : pattern . priority || 0 ,
323321 } ;
324322 } )
325323 ) ;
@@ -329,13 +327,7 @@ class CopyPlugin {
329327 try {
330328 assets = await Promise . all (
331329 files . map ( async ( file ) => {
332- const {
333- absoluteFilename,
334- sourceFilename,
335- filename,
336- toType,
337- priority,
338- } = file ;
330+ const { absoluteFilename, sourceFilename, filename, toType } = file ;
339331 const info =
340332 typeof pattern . info === "function"
341333 ? pattern . info ( file ) || { }
@@ -585,12 +577,6 @@ class CopyPlugin {
585577 result . filename = normalizePath ( result . filename ) ;
586578 }
587579
588- if ( ! assetMap . has ( priority ) ) {
589- assetMap . set ( priority , [ ] ) ;
590- }
591-
592- assetMap . get ( priority ) . push ( result ) ;
593-
594580 // eslint-disable-next-line consistent-return
595581 return result ;
596582 } )
@@ -627,29 +613,38 @@ class CopyPlugin {
627613
628614 const assetMap = new Map ( ) ;
629615
630- try {
631- await Promise . all (
632- this . patterns . map ( ( item , index ) =>
633- limit ( async ( ) =>
634- CopyPlugin . runPattern (
635- assetMap ,
616+ await Promise . all (
617+ this . patterns . map ( ( item , index ) =>
618+ limit ( async ( ) => {
619+ let assets ;
620+
621+ try {
622+ assets = await CopyPlugin . runPattern (
636623 compiler ,
637624 compilation ,
638625 logger ,
639626 cache ,
640627 item ,
641628 index
642- )
643- )
644- )
645- ) ;
646- } catch ( error ) {
647- compilation . errors . push ( error ) ;
629+ ) ;
630+ } catch ( error ) {
631+ compilation . errors . push ( error ) ;
648632
649- callback ( ) ;
633+ return ;
634+ }
650635
651- return ;
652- }
636+ if ( assets && assets . length > 0 ) {
637+ const priority = item . priority || 0 ;
638+
639+ if ( ! assetMap . has ( priority ) ) {
640+ assetMap . set ( priority , [ ] ) ;
641+ }
642+
643+ assetMap . get ( priority ) . push ( ...assets ) ;
644+ }
645+ } )
646+ )
647+ ) ;
653648
654649 const assets = [ ...assetMap . entries ( ) ] . sort ( ( a , b ) => a [ 0 ] - b [ 0 ] ) ;
655650
0 commit comments