File tree 2 files changed +39
-5
lines changed
2 files changed +39
-5
lines changed Original file line number Diff line number Diff line change @@ -59,21 +59,29 @@ export default function preProcessPattern(globalRef, pattern) {
59
59
60
60
debug ( `determined '${ pattern . from } ' to be read from '${ pattern . absoluteFrom } '` ) ;
61
61
62
- return stat ( inputFileSystem , pattern . absoluteFrom )
63
- . catch ( ( ) => {
62
+ const noStatsHandler = ( ) => {
64
63
// If from doesn't appear to be a glob, then log a warning
65
64
if ( isGlob ( pattern . from ) || pattern . from . indexOf ( '*' ) !== - 1 ) {
66
65
pattern . fromType = 'glob' ;
67
66
pattern . glob = escape ( pattern . context , pattern . from ) ;
68
67
} else {
69
68
const msg = `unable to locate '${ pattern . from } ' at '${ pattern . absoluteFrom } '` ;
70
- warning ( msg ) ;
71
- compilation . errors . push ( `[copy-webpack-plugin] ${ msg } ` ) ;
69
+ const warningMsg = `[copy-webpack-plugin] ${ msg } ` ;
70
+ // only display the same message once
71
+ if ( compilation . errors . indexOf ( warningMsg ) === - 1 ) {
72
+ warning ( msg ) ;
73
+ compilation . errors . push ( warningMsg ) ;
74
+ }
75
+
72
76
pattern . fromType = 'nonexistent' ;
73
77
}
74
- } )
78
+ } ;
79
+
80
+ return stat ( inputFileSystem , pattern . absoluteFrom )
81
+ . catch ( ( ) => noStatsHandler ( ) )
75
82
. then ( ( stat ) => {
76
83
if ( ! stat ) {
84
+ noStatsHandler ( ) ;
77
85
return pattern ;
78
86
}
79
87
Original file line number Diff line number Diff line change @@ -56,6 +56,15 @@ class MockCompiler {
56
56
}
57
57
}
58
58
59
+
60
+ class MockCompilerNoStat extends MockCompiler {
61
+ constructor ( options = { } ) {
62
+ super ( options ) ;
63
+
64
+ this . inputFileSystem . stat = ( file , cb ) => cb ( undefined , undefined ) ;
65
+ }
66
+ }
67
+
59
68
describe ( 'apply function' , ( ) => {
60
69
// Ideally we pass in patterns and confirm the resulting assets
61
70
const run = ( opts ) => {
@@ -621,6 +630,23 @@ describe('apply function', () => {
621
630
. catch ( done ) ;
622
631
} ) ;
623
632
633
+ it ( 'warns when file not found and stats is undefined' , ( done ) => {
634
+ runEmit ( {
635
+ compiler : new MockCompilerNoStat ( ) ,
636
+ expectedAssetKeys : [ ] ,
637
+ expectedErrors : [
638
+ `[copy-webpack-plugin] unable to locate 'nonexistent.txt' at '${ HELPER_DIR } ${ path . sep } nonexistent.txt'`
639
+ ] ,
640
+ patterns : [ {
641
+ from : 'nonexistent.txt' ,
642
+ to : '.' ,
643
+ toType : 'dir'
644
+ } ]
645
+ } )
646
+ . then ( done )
647
+ . catch ( done ) ;
648
+ } ) ;
649
+
624
650
it ( 'warns when tranform failed' , ( done ) => {
625
651
runEmit ( {
626
652
expectedAssetKeys : [ ] ,
You can’t perform that action at this time.
0 commit comments