@@ -33,11 +33,11 @@ export class PlatformFSPlugin {
33
33
public apply ( compiler ) {
34
34
this . context = compiler . context ;
35
35
compiler . inputFileSystem = mapFileSystem ( {
36
- fs : compiler . inputFileSystem ,
37
36
platform : this . platform ,
38
37
platforms : this . platforms ,
39
38
ignore : this . ignore ,
40
- context : this . context
39
+ context : this . context ,
40
+ compiler
41
41
} ) ;
42
42
}
43
43
}
@@ -46,15 +46,16 @@ export interface MapFileSystemArgs {
46
46
/**
47
47
* This is the underlying webpack compiler.inputFileSystem, its interface is similar to Node's fs.
48
48
*/
49
- readonly fs : any ;
50
49
readonly context : string ;
51
50
readonly platform : string ;
52
51
readonly platforms : ReadonlyArray < string > ;
53
52
readonly ignore : ReadonlyArray < string > ;
53
+ readonly compiler : any ;
54
54
}
55
55
56
56
export 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 ;
58
59
ignore = args . ignore || [ ] ;
59
60
60
61
const minimatchFileFilters = ignore . map ( pattern => {
@@ -122,7 +123,8 @@ export function mapFileSystem(args: MapFileSystemArgs): any {
122
123
}
123
124
124
125
const platformSuffix = "." + platform + "." ;
125
- mappedFS . watch = function (
126
+ const baseWatch = compiler . watchFileSystem . watch ;
127
+ compiler . watchFileSystem . watch = function (
126
128
files ,
127
129
dirs ,
128
130
missing ,
@@ -135,11 +137,15 @@ export function mapFileSystem(args: MapFileSystemArgs): any {
135
137
missingModified ,
136
138
fileTimestamps ,
137
139
contextTimestamps
140
+ ) => void ,
141
+ callbackUndelayed : (
142
+ filename ,
143
+ timestamp
138
144
) => void ) {
139
145
140
146
const mappedFiles = listWithPlatformSpecificFiles ( files ) ;
141
147
142
- const callbackCalled = function (
148
+ const newCallback = function (
143
149
err ,
144
150
filesModified ,
145
151
contextModified ,
@@ -148,13 +154,17 @@ export function mapFileSystem(args: MapFileSystemArgs): any {
148
154
contextTimestamps ) {
149
155
150
156
const mappedFilesModified = filterIgnoredFilesAlienFilesAndMap ( filesModified ) ;
151
-
152
157
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 ] ;
155
163
mappedTimestamps . set ( file , timestamp ) ;
164
+
156
165
const platformSuffixIndex = file . lastIndexOf ( platformSuffix ) ;
157
166
if ( platformSuffixIndex != - 1 ) {
167
+ // file name without platform suffix
158
168
const mappedFile = file . substr ( 0 , platformSuffixIndex ) + file . substr ( platformSuffixIndex + platformSuffix . length - 1 ) ;
159
169
if ( ! ( mappedFile in fileTimestamps ) ) {
160
170
mappedTimestamps . set ( mappedFile , timestamp ) ;
@@ -165,7 +175,12 @@ export function mapFileSystem(args: MapFileSystemArgs): any {
165
175
callback . call ( this , err , mappedFilesModified , contextModified , missingModified , mappedTimestamps , contextTimestamps ) ;
166
176
}
167
177
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 ] ) ;
169
184
}
170
185
171
186
/**
0 commit comments