6
6
* found in the LICENSE file at https://angular.io/license
7
7
*/
8
8
import { dirname , normalize , resolve , virtualFs } from '@angular-devkit/core' ;
9
+ import { NodeJsSyncHost } from '@angular-devkit/core/node' ;
9
10
import { ChildProcess , ForkOptions , fork } from 'child_process' ;
10
11
import * as fs from 'fs' ;
11
12
import * as path from 'path' ;
@@ -288,11 +289,21 @@ export class AngularCompilerPlugin {
288
289
this . _contextElementDependencyConstructor = options . contextElementDependencyConstructor
289
290
|| require ( 'webpack/lib/dependencies/ContextElementDependency' ) ;
290
291
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
+
291
302
// Create the webpack compiler host.
292
303
const webpackCompilerHost = new WebpackCompilerHost (
293
304
this . _compilerOptions ,
294
305
this . _basePath ,
295
- this . _options . host ,
306
+ host ,
296
307
) ;
297
308
webpackCompilerHost . enableCaching ( ) ;
298
309
@@ -306,17 +317,6 @@ export class AngularCompilerPlugin {
306
317
tsHost : webpackCompilerHost ,
307
318
} ) as CompilerHost & WebpackCompilerHost ;
308
319
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
-
320
320
// Resolve mainPath if provided.
321
321
if ( options . mainPath ) {
322
322
this . _mainPath = this . _compilerHost . resolve ( options . mainPath ) ;
0 commit comments