@@ -40,21 +40,32 @@ const sortData = (a, b) => {
40
40
return 0 ;
41
41
} ;
42
42
43
- const buildSnapshotReadyDeps = ( deps ) =>
44
- deps . map ( ( dep ) => Object . assign ( { } , dep , { mtime : null , path : dep . path } ) ) ;
45
-
46
- const buildCacheLoaderCallsData = ( calls ) =>
43
+ const buildSnapshotReadyDeps = ( deps , normalizePaths = true ) =>
44
+ deps . map ( ( dep ) =>
45
+ Object . assign ( { } , dep , {
46
+ mtime : null ,
47
+ path : normalizePaths ? normalizePath ( dep . path ) : dep . path ,
48
+ } )
49
+ ) ;
50
+
51
+ const buildCacheLoaderCallsData = ( calls , normalizePaths = true ) =>
47
52
Array . from (
48
53
calls
49
54
. reduce ( ( builtCalls , call ) => {
50
55
const [ , rawData ] = call ;
51
56
52
57
return builtCalls . set ( rawData . remainingRequest , {
53
58
...rawData ,
54
- remainingRequest : rawData . remainingRequest ,
55
- dependencies : buildSnapshotReadyDeps ( rawData . dependencies ) ,
59
+ remainingRequest : normalizePaths
60
+ ? normalizePath ( rawData . remainingRequest )
61
+ : rawData . remainingRequest ,
62
+ dependencies : buildSnapshotReadyDeps (
63
+ rawData . dependencies ,
64
+ normalizePaths
65
+ ) ,
56
66
contextDependencies : buildSnapshotReadyDeps (
57
- rawData . contextDependencies
67
+ rawData . contextDependencies ,
68
+ normalizePaths
58
69
) ,
59
70
} ) ;
60
71
} , new Map ( ) )
@@ -82,19 +93,32 @@ describe('cacheContext option', () => {
82
93
expect ( stats . compilation . errors ) . toMatchSnapshot ( 'errors' ) ;
83
94
} ) ;
84
95
85
- it ( 'should generate normalized relative paths to the project root' , async ( ) => {
96
+ it ( 'should generate non normalized relative paths to the project root on windows ' , async ( ) => {
86
97
const testId = './basic/index.js' ;
87
98
await webpack ( testId , mockRelativeWebpackConfig ) ;
88
99
89
100
const cacheLoaderCallsData = buildCacheLoaderCallsData (
90
- mockCacheLoaderWriteFn . mock . calls
101
+ mockCacheLoaderWriteFn . mock . calls ,
102
+ false
91
103
) ;
92
104
93
- expect (
94
- cacheLoaderCallsData . every (
95
- ( call ) => call . remainingRequest === normalizePath ( call . remainingRequest )
96
- )
97
- ) . toBeTruthy ( ) ;
105
+ // NOTE: this test prevents to generate normalized paths for the generated cache assets
106
+ // under windows which will break the watcher due to a bug on watchpack/chokidar
107
+ if ( process . platform === 'win32' ) {
108
+ expect (
109
+ cacheLoaderCallsData . every (
110
+ ( call ) =>
111
+ call . remainingRequest !== normalizePath ( call . remainingRequest )
112
+ )
113
+ ) . toBeTruthy ( ) ;
114
+ } else {
115
+ expect (
116
+ cacheLoaderCallsData . every (
117
+ ( call ) =>
118
+ call . remainingRequest === normalizePath ( call . remainingRequest )
119
+ )
120
+ ) . toBeTruthy ( ) ;
121
+ }
98
122
} ) ;
99
123
100
124
it ( 'should generate absolute paths to the project root' , async ( ) => {
0 commit comments