66 * found in the LICENSE file at https://angular.io/license
77 */
88import { dirname , normalize , resolve , virtualFs } from '@angular-devkit/core' ;
9+ import { NodeJsSyncHost } from '@angular-devkit/core/node' ;
910import { ChildProcess , ForkOptions , fork } from 'child_process' ;
1011import * as fs from 'fs' ;
1112import * as path from 'path' ;
@@ -288,11 +289,21 @@ export class AngularCompilerPlugin {
288289 this . _contextElementDependencyConstructor = options . contextElementDependencyConstructor
289290 || require ( 'webpack/lib/dependencies/ContextElementDependency' ) ;
290291
292+
293+ let host : virtualFs . Host < fs . Stats > = options . host || new NodeJsSyncHost ( ) ;
294+ if ( options . hostReplacementPaths ) {
295+ const aliasHost = new virtualFs . AliasHost ( host ) ;
296+ for ( const from in options . hostReplacementPaths ) {
297+ aliasHost . aliases . set ( normalize ( from ) , normalize ( options . hostReplacementPaths [ from ] ) ) ;
298+ }
299+ host = aliasHost ;
300+ }
301+
291302 // Create the webpack compiler host.
292303 const webpackCompilerHost = new WebpackCompilerHost (
293304 this . _compilerOptions ,
294305 this . _basePath ,
295- this . _options . host ,
306+ host ,
296307 ) ;
297308 webpackCompilerHost . enableCaching ( ) ;
298309
@@ -306,17 +317,6 @@ export class AngularCompilerPlugin {
306317 tsHost : webpackCompilerHost ,
307318 } ) as CompilerHost & WebpackCompilerHost ;
308319
309- // Override some files in the FileSystem with paths from the actual file system.
310- if ( this . _options . hostReplacementPaths ) {
311- for ( const filePath of Object . keys ( this . _options . hostReplacementPaths ) ) {
312- const replacementFilePath = this . _options . hostReplacementPaths [ filePath ] ;
313- const content = this . _compilerHost . readFile ( replacementFilePath ) ;
314- if ( content ) {
315- this . _compilerHost . writeFile ( filePath , content , false ) ;
316- }
317- }
318- }
319-
320320 // Resolve mainPath if provided.
321321 if ( options . mainPath ) {
322322 this . _mainPath = this . _compilerHost . resolve ( options . mainPath ) ;
0 commit comments