@@ -152,19 +152,49 @@ export class WebpackCompilerHost implements ts.CompilerHost {
152
152
return ;
153
153
}
154
154
155
+ /**
156
+ * storageDataSetter is a temporary hack to address these two issues:
157
+ * - https://github.com/angular/angular-cli/issues/7113
158
+ * - https://github.com/angular/angular-cli/issues/7136
159
+ *
160
+ * This way we set values correctly in both a Map (enhanced-resove>=3.4.0) and
161
+ * object (enhanced-resolve >= 3.1.0 <3.4.0).
162
+ *
163
+ * The right solution is to create a virtual filesystem by decorating the filesystem,
164
+ * instead of injecting data into the private cache of the filesystem.
165
+ *
166
+ * Doing it the right way should fix other related bugs, but meanwhile we hack it since:
167
+ * - it's affecting a lot of users.
168
+ * - the real solution is non-trivial.
169
+ */
170
+ function storageDataSetter ( data : Map < string , any > | { [ k : string ] : any } , k : string , v : any ) {
171
+
172
+ if ( data instanceof Map ) {
173
+ data . set ( k , v ) ;
174
+ } else {
175
+ data [ k ] = v ;
176
+ }
177
+ }
178
+
179
+
180
+
155
181
const isWindows = process . platform . startsWith ( 'win' ) ;
156
182
for ( const fileName of this . getChangedFilePaths ( ) ) {
157
183
const stats = this . _files [ fileName ] ;
158
184
if ( stats ) {
159
185
// If we're on windows, we need to populate with the proper path separator.
160
186
const path = isWindows ? fileName . replace ( / \/ / g, '\\' ) : fileName ;
161
- fs . _statStorage . data [ path ] = [ null , stats ] ;
162
- fs . _readFileStorage . data [ path ] = [ null , stats . content ] ;
187
+ // fs._statStorage.data[path] = [null, stats];
188
+ // fs._readFileStorage.data[path] = [null, stats.content];
189
+ storageDataSetter ( fs . _statStorage . data , path , [ null , stats ] ) ;
190
+ storageDataSetter ( fs . _readFileStorage . data , path , [ null , stats . content ] ) ;
163
191
} else {
164
192
// Support removing files as well.
165
193
const path = isWindows ? fileName . replace ( / \/ / g, '\\' ) : fileName ;
166
- fs . _statStorage . data [ path ] = [ new Error ( ) , null ] ;
167
- fs . _readFileStorage . data [ path ] = [ new Error ( ) , null ] ;
194
+ // fs._statStorage.data[path] = [new Error(), null];
195
+ // fs._readFileStorage.data[path] = [new Error(), null];
196
+ storageDataSetter ( fs . _statStorage . data , path , [ new Error ( ) , null ] ) ;
197
+ storageDataSetter ( fs . _readFileStorage . data , path , [ new Error ( ) , null ] ) ;
168
198
}
169
199
}
170
200
for ( const dirName of Object . keys ( this . _changedDirs ) ) {
@@ -173,8 +203,10 @@ export class WebpackCompilerHost implements ts.CompilerHost {
173
203
const files = this . getFiles ( dirName ) ;
174
204
// If we're on windows, we need to populate with the proper path separator.
175
205
const path = isWindows ? dirName . replace ( / \/ / g, '\\' ) : dirName ;
176
- fs . _statStorage . data [ path ] = [ null , stats ] ;
177
- fs . _readdirStorage . data [ path ] = [ null , files . concat ( dirs ) ] ;
206
+ // fs._statStorage.data[path] = [null, stats];
207
+ // fs._readdirStorage.data[path] = [null, files.concat(dirs)];
208
+ storageDataSetter ( fs . _statStorage . data , path , [ null , stats ] ) ;
209
+ storageDataSetter ( fs . _readFileStorage . data , path , [ null , files . concat ( dirs ) ] ) ;
178
210
}
179
211
}
180
212
0 commit comments