@@ -33,11 +33,11 @@ export class PlatformFSPlugin {
3333 public apply ( compiler ) {
3434 this . context = compiler . context ;
3535 compiler . inputFileSystem = mapFileSystem ( {
36- fs : compiler . inputFileSystem ,
3736 platform : this . platform ,
3837 platforms : this . platforms ,
3938 ignore : this . ignore ,
40- context : this . context
39+ context : this . context ,
40+ compiler
4141 } ) ;
4242 }
4343}
@@ -46,15 +46,16 @@ export interface MapFileSystemArgs {
4646 /**
4747 * This is the underlying webpack compiler.inputFileSystem, its interface is similar to Node's fs.
4848 */
49- readonly fs : any ;
5049 readonly context : string ;
5150 readonly platform : string ;
5251 readonly platforms : ReadonlyArray < string > ;
5352 readonly ignore : ReadonlyArray < string > ;
53+ readonly compiler : any ;
5454}
5555
5656export function mapFileSystem ( args : MapFileSystemArgs ) : any {
57- let { fs, platform, platforms, ignore, context } = args ;
57+ let { platform, platforms, ignore, context, compiler } = args ;
58+ const fs = compiler . inputFileSystem ;
5859 ignore = args . ignore || [ ] ;
5960
6061 const minimatchFileFilters = ignore . map ( pattern => {
@@ -122,7 +123,8 @@ export function mapFileSystem(args: MapFileSystemArgs): any {
122123 }
123124
124125 const platformSuffix = "." + platform + "." ;
125- mappedFS . watch = function (
126+ const baseWatch = compiler . watchFileSystem . watch ;
127+ compiler . watchFileSystem . watch = function (
126128 files ,
127129 dirs ,
128130 missing ,
@@ -135,11 +137,15 @@ export function mapFileSystem(args: MapFileSystemArgs): any {
135137 missingModified ,
136138 fileTimestamps ,
137139 contextTimestamps
140+ ) => void ,
141+ callbackUndelayed : (
142+ filename ,
143+ timestamp
138144 ) => void ) {
139145
140146 const mappedFiles = listWithPlatformSpecificFiles ( files ) ;
141147
142- const callbackCalled = function (
148+ const newCallback = function (
143149 err ,
144150 filesModified ,
145151 contextModified ,
@@ -148,13 +154,17 @@ export function mapFileSystem(args: MapFileSystemArgs): any {
148154 contextTimestamps ) {
149155
150156 const mappedFilesModified = filterIgnoredFilesAlienFilesAndMap ( filesModified ) ;
151-
152157 const mappedTimestamps = new Map ( ) ;
153- for ( const file in fileTimestamps ) {
154- const timestamp = fileTimestamps [ file ] ;
158+ const fileTimestampsAsArray = Array . from ( fileTimestamps ) ;
159+
160+ for ( const entry of fileTimestampsAsArray ) {
161+ const file = entry [ 0 ] ;
162+ const timestamp = entry [ 1 ] ;
155163 mappedTimestamps . set ( file , timestamp ) ;
164+
156165 const platformSuffixIndex = file . lastIndexOf ( platformSuffix ) ;
157166 if ( platformSuffixIndex != - 1 ) {
167+ // file name without platform suffix
158168 const mappedFile = file . substr ( 0 , platformSuffixIndex ) + file . substr ( platformSuffixIndex + platformSuffix . length - 1 ) ;
159169 if ( ! ( mappedFile in fileTimestamps ) ) {
160170 mappedTimestamps . set ( mappedFile , timestamp ) ;
@@ -165,7 +175,12 @@ export function mapFileSystem(args: MapFileSystemArgs): any {
165175 callback . call ( this , err , mappedFilesModified , contextModified , missingModified , mappedTimestamps , contextTimestamps ) ;
166176 }
167177
168- fs . watch ( mappedFiles , dirs , missing , startTime , watchOptions , callbackCalled ) ;
178+ const newCallbackUndelayed = function ( filename , timestamp ) {
179+ compiler . watchFileSystem . inputFileSystem . purge ( filename ) ;
180+ callbackUndelayed ( filename , timestamp ) ;
181+ } ;
182+
183+ baseWatch . apply ( compiler . watchFileSystem . watch , [ mappedFiles , dirs , missing , startTime , watchOptions , newCallback , newCallbackUndelayed ] ) ;
169184 }
170185
171186 /**
0 commit comments