File tree Expand file tree Collapse file tree 2 files changed +53
-2
lines changed Expand file tree Collapse file tree 2 files changed +53
-2
lines changed Original file line number Diff line number Diff line change @@ -148,11 +148,25 @@ class ConfigGenerator {
148
148
entry [ sharedEntryTmpName ] = tmpFilename ;
149
149
}
150
150
151
- if ( this . webpackConfig . copyFilesConfigs . length > 0 ) {
151
+ const copyFilesConfigs = this . webpackConfig . copyFilesConfigs . filter ( entry => {
152
+ const copyFrom = path . resolve (
153
+ this . webpackConfig . getContext ( ) ,
154
+ entry . from
155
+ ) ;
156
+
157
+ if ( ! fs . existsSync ( copyFrom ) || ! fs . lstatSync ( copyFrom ) . isDirectory ( ) ) {
158
+ logger . warning ( `The "from" option of copyFiles() should be set to an existing directory but "${ entry . from } " does not seem to be one. No file will be copied for this entry.` ) ;
159
+ return false ;
160
+ }
161
+
162
+ return true ;
163
+ } ) ;
164
+
165
+ if ( copyFilesConfigs . length > 0 ) {
152
166
const tmpFileObject = tmp . fileSync ( ) ;
153
167
fs . writeFileSync (
154
168
tmpFileObject . name ,
155
- this . webpackConfig . copyFilesConfigs . reduce ( ( buffer , entry , index ) => {
169
+ copyFilesConfigs . reduce ( ( buffer , entry , index ) => {
156
170
const copyFrom = path . resolve (
157
171
this . webpackConfig . getContext ( ) ,
158
172
entry . from
Original file line number Diff line number Diff line change @@ -1603,6 +1603,43 @@ module.exports = {
1603
1603
done ( ) ;
1604
1604
} ) ;
1605
1605
} ) ;
1606
+
1607
+ it ( 'Do not try to copy files from an invalid path' , ( done ) => {
1608
+ const config = createWebpackConfig ( 'www/build' , 'production' ) ;
1609
+ config . addEntry ( 'main' , './js/no_require' ) ;
1610
+ config . setPublicPath ( '/build' ) ;
1611
+ config . copyFiles ( [ {
1612
+ from : './images' ,
1613
+ to : 'assets/[path][name].[ext]' ,
1614
+ includeSubdirectories : false
1615
+ } , {
1616
+ from : './foo' ,
1617
+ to : 'assets/[path][name].[ext]' ,
1618
+ includeSubdirectories : false
1619
+ } , {
1620
+ from : './fonts' ,
1621
+ to : 'assets/[path][name].[ext]' ,
1622
+ includeSubdirectories : false
1623
+ } , {
1624
+ from : './bar/baz' ,
1625
+ includeSubdirectories : true
1626
+ } ] ) ;
1627
+
1628
+ testSetup . runWebpack ( config , ( webpackAssert , stats , stdout ) => {
1629
+ expect ( config . outputPath ) . to . be . a . directory ( )
1630
+ . with . files ( [
1631
+ 'entrypoints.json' ,
1632
+ 'runtime.js' ,
1633
+ 'main.js' ,
1634
+ 'manifest.json'
1635
+ ] ) ;
1636
+
1637
+ expect ( stdout ) . to . contain ( 'should be set to an existing directory but "./foo" does not seem to be one' ) ;
1638
+ expect ( stdout ) . to . contain ( 'should be set to an existing directory but "./bar/baz" does not seem to be one' ) ;
1639
+
1640
+ done ( ) ;
1641
+ } ) ;
1642
+ } ) ;
1606
1643
} ) ;
1607
1644
1608
1645
describe ( 'entrypoints.json' , ( ) => {
You can’t perform that action at this time.
0 commit comments