@@ -40,21 +40,32 @@ const sortData = (a, b) => {
4040 return 0 ;
4141} ;
4242
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 ) =>
4752 Array . from (
4853 calls
4954 . reduce ( ( builtCalls , call ) => {
5055 const [ , rawData ] = call ;
5156
5257 return builtCalls . set ( rawData . remainingRequest , {
5358 ...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+ ) ,
5666 contextDependencies : buildSnapshotReadyDeps (
57- rawData . contextDependencies
67+ rawData . contextDependencies ,
68+ normalizePaths
5869 ) ,
5970 } ) ;
6071 } , new Map ( ) )
@@ -82,19 +93,32 @@ describe('cacheContext option', () => {
8293 expect ( stats . compilation . errors ) . toMatchSnapshot ( 'errors' ) ;
8394 } ) ;
8495
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 ( ) => {
8697 const testId = './basic/index.js' ;
8798 await webpack ( testId , mockRelativeWebpackConfig ) ;
8899
89100 const cacheLoaderCallsData = buildCacheLoaderCallsData (
90- mockCacheLoaderWriteFn . mock . calls
101+ mockCacheLoaderWriteFn . mock . calls ,
102+ false
91103 ) ;
92104
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+ }
98122 } ) ;
99123
100124 it ( 'should generate absolute paths to the project root' , async ( ) => {
0 commit comments