@@ -152,19 +152,49 @@ export class WebpackCompilerHost implements ts.CompilerHost {
152152 return ;
153153 }
154154
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+
155181 const isWindows = process . platform . startsWith ( 'win' ) ;
156182 for ( const fileName of this . getChangedFilePaths ( ) ) {
157183 const stats = this . _files [ fileName ] ;
158184 if ( stats ) {
159185 // If we're on windows, we need to populate with the proper path separator.
160186 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 ] ) ;
163191 } else {
164192 // Support removing files as well.
165193 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 ] ) ;
168198 }
169199 }
170200 for ( const dirName of Object . keys ( this . _changedDirs ) ) {
@@ -173,8 +203,10 @@ export class WebpackCompilerHost implements ts.CompilerHost {
173203 const files = this . getFiles ( dirName ) ;
174204 // If we're on windows, we need to populate with the proper path separator.
175205 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 ) ] ) ;
178210 }
179211 }
180212
0 commit comments