Skip to content

Commit 3238640

Browse files
filipesilvaKeen Yee Liau
authored and
Keen Yee Liau
committed
feat(@ngtools/webpack): support hostReplacementPaths
Fix #12197
1 parent 61871d3 commit 3238640

File tree

3 files changed

+22
-2
lines changed

3 files changed

+22
-2
lines changed

packages/ngtools/webpack/src/angular_compiler_plugin.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -602,8 +602,13 @@ export class AngularCompilerPlugin {
602602
private _updateForkedTypeChecker(rootNames: string[], changedCompilationFiles: string[]) {
603603
if (this._typeCheckerProcess) {
604604
if (!this._forkedTypeCheckerInitialized) {
605+
let hostReplacementPaths = {};
606+
if (this._options.hostReplacementPaths
607+
&& typeof this._options.hostReplacementPaths != 'function') {
608+
hostReplacementPaths = this._options.hostReplacementPaths;
609+
}
605610
this._typeCheckerProcess.send(new InitMessage(this._compilerOptions, this._basePath,
606-
this._JitMode, this._rootNames));
611+
this._JitMode, this._rootNames, hostReplacementPaths));
607612
this._forkedTypeCheckerInitialized = true;
608613
}
609614
this._typeCheckerProcess.send(new UpdateMessage(rootNames, changedCompilationFiles));

packages/ngtools/webpack/src/type_checker.ts

+15-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
* Use of this source code is governed by an MIT-style license that can be
66
* found in the LICENSE file at https://angular.io/license
77
*/
8+
import { normalize, resolve, virtualFs } from '@angular-devkit/core';
89
import { NodeJsSyncHost } from '@angular-devkit/core/node';
910
import {
1011
CompilerHost,
@@ -33,12 +34,25 @@ export class TypeChecker {
3334
_basePath: string,
3435
private _JitMode: boolean,
3536
private _rootNames: string[],
37+
hostReplacementPaths: { [path: string]: string },
3638
) {
3739
time('TypeChecker.constructor');
40+
const host = new virtualFs.AliasHost(new NodeJsSyncHost());
41+
42+
// Add file replacements.
43+
for (const from in hostReplacementPaths) {
44+
const normalizedFrom = resolve(normalize(_basePath), normalize(from));
45+
const normalizedWith = resolve(
46+
normalize(_basePath),
47+
normalize(hostReplacementPaths[from]),
48+
);
49+
host.aliases.set(normalizedFrom, normalizedWith);
50+
}
51+
3852
const compilerHost = new WebpackCompilerHost(
3953
_compilerOptions,
4054
_basePath,
41-
new NodeJsSyncHost(),
55+
host,
4256
);
4357
// We don't set a async resource loader on the compiler host because we only support
4458
// html templates, which are the only ones that can throw errors, and those can be loaded

packages/ngtools/webpack/src/type_checker_worker.ts

+1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ if (process.argv.indexOf(AUTO_START_ARG) >= 0) {
3434
initMessage.basePath,
3535
initMessage.jitMode,
3636
initMessage.rootNames,
37+
initMessage.hostReplacementPaths,
3738
);
3839
break;
3940
case MESSAGE_KIND.Update:

0 commit comments

Comments
 (0)