@@ -15,6 +15,8 @@ import cacache from 'cacache';
15
15
import isGzip from 'is-gzip' ;
16
16
import zlib from 'zlib' ;
17
17
18
+ import removeIllegalCharacterForWindows from './utils/removeIllegalCharacterForWindows' ;
19
+
18
20
const BUILD_DIR = path . join ( __dirname , 'build' ) ;
19
21
const HELPER_DIR = path . join ( __dirname , 'helpers' ) ;
20
22
const TEMP_DIR = path . join ( __dirname , 'tempdir' ) ;
@@ -58,6 +60,13 @@ describe('apply function', () => {
58
60
// Ideally we pass in patterns and confirm the resulting assets
59
61
const run = ( opts ) => {
60
62
return new Promise ( ( resolve , reject ) => {
63
+ if ( Array . isArray ( opts . patterns ) ) {
64
+ opts . patterns . forEach ( function ( pattern ) {
65
+ if ( pattern . context ) {
66
+ pattern . context = removeIllegalCharacterForWindows ( pattern . context ) ;
67
+ }
68
+ } ) ;
69
+ }
61
70
const plugin = CopyWebpackPlugin ( opts . patterns , opts . options ) ;
62
71
63
72
// Get a mock compiler to pass to plugin.apply
@@ -109,7 +118,7 @@ describe('apply function', () => {
109
118
return run ( opts )
110
119
. then ( ( compilation ) => {
111
120
if ( opts . expectedAssetKeys && opts . expectedAssetKeys . length > 0 ) {
112
- expect ( compilation . assets ) . to . have . all . keys ( opts . expectedAssetKeys ) ;
121
+ expect ( compilation . assets ) . to . have . all . keys ( opts . expectedAssetKeys . map ( removeIllegalCharacterForWindows ) ) ;
113
122
} else {
114
123
expect ( compilation . assets ) . to . deep . equal ( { } ) ;
115
124
}
@@ -268,6 +277,7 @@ describe('apply function', () => {
268
277
it ( 'can use a glob to move multiple files to the root directory' , ( done ) => {
269
278
runEmit ( {
270
279
expectedAssetKeys : [
280
+ '[!]/hello.txt' ,
271
281
'binextension.bin' ,
272
282
'file.txt' ,
273
283
'file.txt.gz' ,
@@ -289,6 +299,7 @@ describe('apply function', () => {
289
299
it ( 'can use a glob to move multiple files to a non-root directory' , ( done ) => {
290
300
runEmit ( {
291
301
expectedAssetKeys : [
302
+ 'nested/[!]/hello.txt' ,
292
303
'nested/binextension.bin' ,
293
304
'nested/file.txt' ,
294
305
'nested/file.txt.gz' ,
@@ -405,6 +416,7 @@ describe('apply function', () => {
405
416
it ( 'can use a glob with a full path to move multiple files to the root directory' , ( done ) => {
406
417
runEmit ( {
407
418
expectedAssetKeys : [
419
+ '[!]/hello.txt' ,
408
420
'file.txt' ,
409
421
'directory/directoryfile.txt' ,
410
422
'directory/nested/nestedfile.txt' ,
@@ -423,6 +435,7 @@ describe('apply function', () => {
423
435
it ( 'can use a glob to move multiple files to a non-root directory with name, hash and ext' , ( done ) => {
424
436
runEmit ( {
425
437
expectedAssetKeys : [
438
+ 'nested/[!]/hello-d41d8c.txt' ,
426
439
'nested/binextension-d41d8c.bin' ,
427
440
'nested/file-22af64.txt' ,
428
441
'nested/file.txt-5b311c.gz' ,
@@ -445,13 +458,14 @@ describe('apply function', () => {
445
458
it ( 'can flatten or normalize glob matches' , ( done ) => {
446
459
runEmit ( {
447
460
expectedAssetKeys : [
461
+ '[!]-hello.txt' ,
448
462
'[special?directory]-(special-*file).txt' ,
449
463
'[special?directory]-directoryfile.txt' ,
450
464
'directory-directoryfile.txt'
451
465
] ,
452
466
patterns : [ {
453
467
from : '*/*.*' ,
454
- test : / ( [ ^ \/ ] + ) \/ ( [ ^ \/ ] + ) \. \ w+ $ / ,
468
+ test : ` ([^\\ ${ path . sep } ]+)\\ ${ path . sep } ([^\\ ${ path . sep } ]+)\\.\\ w+$` ,
455
469
to : '[1]-[2].[ext]'
456
470
} ]
457
471
} )
@@ -887,6 +901,7 @@ describe('apply function', () => {
887
901
it ( 'ignores files in pattern' , ( done ) => {
888
902
runEmit ( {
889
903
expectedAssetKeys : [
904
+ '[!]/hello.txt' ,
890
905
'binextension.bin' ,
891
906
'directory/directoryfile.txt' ,
892
907
'directory/nested/nestedfile.txt' ,
@@ -984,7 +999,7 @@ describe('apply function', () => {
984
999
'nested/nestedfile.txt'
985
1000
] ,
986
1001
patterns : [ {
987
- from : ' [special?directory]'
1002
+ from : ( path . sep === '/' ? ' [special?directory]' : '[specialdirectory]' )
988
1003
} ]
989
1004
} )
990
1005
. then ( done )
@@ -1324,6 +1339,7 @@ describe('apply function', () => {
1324
1339
it ( 'ignores files that start with a dot' , ( done ) => {
1325
1340
runEmit ( {
1326
1341
expectedAssetKeys : [
1342
+ '[!]/hello.txt' ,
1327
1343
'binextension.bin' ,
1328
1344
'file.txt' ,
1329
1345
'file.txt.gz' ,
@@ -1384,13 +1400,14 @@ describe('apply function', () => {
1384
1400
it ( 'ignores nested directory' , ( done ) => {
1385
1401
runEmit ( {
1386
1402
expectedAssetKeys : [
1403
+ '[!]/hello.txt' ,
1387
1404
'binextension.bin' ,
1388
1405
'file.txt' ,
1389
1406
'file.txt.gz' ,
1390
1407
'noextension'
1391
1408
] ,
1392
1409
options : {
1393
- ignore : [ 'directory/**/*' , '\\[ special\\? directory\\ ]/**/*' ]
1410
+ ignore : [ 'directory/**/*' , `[[] special${ process . platform === 'win32' ? '' : '[?]' } directory]/**/*` ]
1394
1411
} ,
1395
1412
patterns : [ {
1396
1413
from : '.'
@@ -1401,6 +1418,29 @@ describe('apply function', () => {
1401
1418
. catch ( done ) ;
1402
1419
} ) ;
1403
1420
1421
+ if ( path . sep === '/' ) {
1422
+ it ( 'ignores nested directory(can use "\\" to escape if path.sep is "/")' , ( done ) => {
1423
+ runEmit ( {
1424
+ expectedAssetKeys : [
1425
+ '[!]/hello.txt' ,
1426
+ 'binextension.bin' ,
1427
+ 'file.txt' ,
1428
+ 'file.txt.gz' ,
1429
+ 'noextension'
1430
+ ] ,
1431
+ options : {
1432
+ ignore : [ 'directory/**/*' , '\\[special\\?directory\\]/**/*' ]
1433
+ } ,
1434
+ patterns : [ {
1435
+ from : '.'
1436
+ } ]
1437
+
1438
+ } )
1439
+ . then ( done )
1440
+ . catch ( done ) ;
1441
+ } ) ;
1442
+ }
1443
+
1404
1444
it ( 'ignores nested directory (glob)' , ( done ) => {
1405
1445
runEmit ( {
1406
1446
expectedAssetKeys : [
0 commit comments