|
5 | 5 | * Use of this source code is governed by an MIT-style license that can be
|
6 | 6 | * found in the LICENSE file at https://angular.io/license
|
7 | 7 | */
|
8 |
| -import { logging } from '@angular-devkit/core'; |
| 8 | +import { logging, normalize, resolve, virtualFs } from '@angular-devkit/core'; |
9 | 9 | import { NodeJsSyncHost } from '@angular-devkit/core/node';
|
10 | 10 | import {
|
11 | 11 | CompilerHost,
|
@@ -40,6 +40,7 @@ export class InitMessage extends TypeCheckerMessage {
|
40 | 40 | public basePath: string,
|
41 | 41 | public jitMode: boolean,
|
42 | 42 | public rootNames: string[],
|
| 43 | + public hostReplacementPaths: { [path: string]: string }, |
43 | 44 | ) {
|
44 | 45 | super(MESSAGE_KIND.Init);
|
45 | 46 | }
|
@@ -68,12 +69,25 @@ export class TypeChecker {
|
68 | 69 | _basePath: string,
|
69 | 70 | private _JitMode: boolean,
|
70 | 71 | private _rootNames: string[],
|
| 72 | + hostReplacementPaths: { [path: string]: string }, |
71 | 73 | ) {
|
72 | 74 | time('TypeChecker.constructor');
|
| 75 | + const host = new virtualFs.AliasHost(new NodeJsSyncHost()); |
| 76 | + |
| 77 | + // Add file replacements. |
| 78 | + for (const from in hostReplacementPaths) { |
| 79 | + const normalizedFrom = resolve(normalize(_basePath), normalize(from)); |
| 80 | + const normalizedWith = resolve( |
| 81 | + normalize(_basePath), |
| 82 | + normalize(hostReplacementPaths[from]), |
| 83 | + ); |
| 84 | + host.aliases.set(normalizedFrom, normalizedWith); |
| 85 | + } |
| 86 | + |
73 | 87 | const compilerHost = new WebpackCompilerHost(
|
74 | 88 | _compilerOptions,
|
75 | 89 | _basePath,
|
76 |
| - new NodeJsSyncHost(), |
| 90 | + host, |
77 | 91 | );
|
78 | 92 | // We don't set a async resource loader on the compiler host because we only support
|
79 | 93 | // html templates, which are the only ones that can throw errors, and those can be loaded
|
|
0 commit comments