Skip to content

Commit c01461a

Browse files
alan-agius4Keen Yee Liau
authored and
Keen Yee Liau
committed
feat(@ngtools/webpack): add path mappings resolution to NGCC
In version 8.1, similar to TypeScript Compiler, NGCC supports Path Mappings. This enable NGCC to process workspace libraries similar to what it is currently being done for `node_modules` Closes angular#14594
1 parent 9972cfb commit c01461a

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

src/angular_compiler_plugin.ts

+1
Original file line numberDiff line numberDiff line change
@@ -667,6 +667,7 @@ export class AngularCompilerPlugin {
667667
this._warnings,
668668
this._errors,
669669
this._basePath,
670+
this._compilerOptions,
670671
);
671672
}
672673

src/ngcc_processor.ts

+12-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9-
import { Logger, process as mainNgcc } from '@angular/compiler-cli/ngcc';
9+
import { Logger, PathMappings, process as mainNgcc } from '@angular/compiler-cli/ngcc';
1010
import { existsSync } from 'fs';
1111
import * as path from 'path';
1212
import * as ts from 'typescript';
@@ -27,16 +27,26 @@ export class NgccProcessor {
2727
private _processedModules = new Set<string>();
2828
private _logger: NgccLogger;
2929
private _nodeModulesDirectory: string;
30+
private _pathMappings: PathMappings | undefined;
3031

3132
constructor(
3233
private readonly propertiesToConsider: string[],
3334
private readonly inputFileSystem: InputFileSystem,
3435
private readonly compilationWarnings: (Error | string)[],
3536
private readonly compilationErrors: (Error | string)[],
3637
private readonly basePath: string,
38+
private readonly compilerOptions: ts.CompilerOptions,
3739
) {
3840
this._logger = new NgccLogger(this.compilationWarnings, this.compilationErrors);
3941
this._nodeModulesDirectory = this.findNodeModulesDirectory(this.basePath);
42+
43+
const { baseUrl, paths } = this.compilerOptions;
44+
if (baseUrl && paths) {
45+
this._pathMappings = {
46+
baseUrl,
47+
paths,
48+
};
49+
}
4050
}
4151

4252
processModule(
@@ -69,6 +79,7 @@ export class NgccProcessor {
6979
compileAllFormats: false,
7080
createNewEntryPointFormats: true,
7181
logger: this._logger,
82+
pathMappings: this._pathMappings,
7283
});
7384
timeEnd(timeLabel);
7485

0 commit comments

Comments
 (0)