@@ -146,70 +146,6 @@ export class WebpackCompilerHost implements ts.CompilerHost {
146
146
this . _cache = true ;
147
147
}
148
148
149
- populateWebpackResolver ( resolver : any ) {
150
- const fs = resolver . fileSystem ;
151
- if ( ! this . dirty ) {
152
- return ;
153
- }
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
-
181
- const isWindows = process . platform . startsWith ( 'win' ) ;
182
- for ( const fileName of this . getChangedFilePaths ( ) ) {
183
- const stats = this . _files [ fileName ] ;
184
- if ( stats ) {
185
- // If we're on windows, we need to populate with the proper path separator.
186
- const path = isWindows ? fileName . replace ( / \/ / g, '\\' ) : fileName ;
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 ] ) ;
191
- } else {
192
- // Support removing files as well.
193
- const path = isWindows ? fileName . replace ( / \/ / g, '\\' ) : fileName ;
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 ] ) ;
198
- }
199
- }
200
- for ( const dirName of Object . keys ( this . _changedDirs ) ) {
201
- const stats = this . _directories [ dirName ] ;
202
- const dirs = this . getDirectories ( dirName ) ;
203
- const files = this . getFiles ( dirName ) ;
204
- // If we're on windows, we need to populate with the proper path separator.
205
- const path = isWindows ? dirName . replace ( / \/ / g, '\\' ) : dirName ;
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 ) ] ) ;
210
- }
211
- }
212
-
213
149
resetChangedFileTracker ( ) {
214
150
this . _changedFiles = Object . create ( null ) ;
215
151
this . _changedDirs = Object . create ( null ) ;
@@ -226,9 +162,9 @@ export class WebpackCompilerHost implements ts.CompilerHost {
226
162
}
227
163
}
228
164
229
- fileExists ( fileName : string ) : boolean {
165
+ fileExists ( fileName : string , delegate = true ) : boolean {
230
166
fileName = this . _resolve ( fileName ) ;
231
- return this . _files [ fileName ] != null || this . _delegate . fileExists ( fileName ) ;
167
+ return this . _files [ fileName ] != null || ( delegate && this . _delegate . fileExists ( fileName ) ) ;
232
168
}
233
169
234
170
readFile ( fileName : string ) : string {
@@ -247,10 +183,17 @@ export class WebpackCompilerHost implements ts.CompilerHost {
247
183
return stats . content ;
248
184
}
249
185
250
- directoryExists ( directoryName : string ) : boolean {
186
+ // Does not delegate, use with `fileExists/directoryExists()`.
187
+ stat ( path : string ) : VirtualStats {
188
+ path = this . _resolve ( path ) ;
189
+ return this . _files [ path ] || this . _directories [ path ] ;
190
+ }
191
+
192
+ directoryExists ( directoryName : string , delegate = true ) : boolean {
251
193
directoryName = this . _resolve ( directoryName ) ;
252
194
return ( this . _directories [ directoryName ] != null )
253
- || ( this . _delegate . directoryExists != undefined
195
+ || ( delegate
196
+ && this . _delegate . directoryExists != undefined
254
197
&& this . _delegate . directoryExists ( directoryName ) ) ;
255
198
}
256
199
0 commit comments