Skip to content

Commit

Permalink
feat(@ngtools/webpack): add path mappings resolution to NGCC
Browse files Browse the repository at this point in the history
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 #14594
  • Loading branch information
alan-agius4 authored and Keen Yee Liau committed Jun 11, 2019
1 parent 905f3ac commit efe4633
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
1 change: 1 addition & 0 deletions packages/ngtools/webpack/src/angular_compiler_plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -667,6 +667,7 @@ export class AngularCompilerPlugin {
this._warnings,
this._errors,
this._basePath,
this._compilerOptions,
);
}

Expand Down
13 changes: 12 additions & 1 deletion packages/ngtools/webpack/src/ngcc_processor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* found in the LICENSE file at https://angular.io/license
*/

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

constructor(
private readonly propertiesToConsider: string[],
private readonly inputFileSystem: InputFileSystem,
private readonly compilationWarnings: (Error | string)[],
private readonly compilationErrors: (Error | string)[],
private readonly basePath: string,
private readonly compilerOptions: ts.CompilerOptions,
) {
this._logger = new NgccLogger(this.compilationWarnings, this.compilationErrors);
this._nodeModulesDirectory = this.findNodeModulesDirectory(this.basePath);

const { baseUrl, paths } = this.compilerOptions;
if (baseUrl && paths) {
this._pathMappings = {
baseUrl,
paths,
};
}
}

processModule(
Expand Down Expand Up @@ -69,6 +79,7 @@ export class NgccProcessor {
compileAllFormats: false,
createNewEntryPointFormats: true,
logger: this._logger,
pathMappings: this._pathMappings,
});
timeEnd(timeLabel);

Expand Down
8 changes: 0 additions & 8 deletions tests/legacy-cli/e2e/tests/misc/module-resolution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,9 @@ import { appendToFile, createDir, moveFile, prependToFile } from '../../utils/fs
import { ng, silentNpm } from '../../utils/process';
import { updateJsonFile } from '../../utils/project';
import { expectToFail } from '../../utils/utils';
import { getGlobalVariable } from '../../utils/env';


export default async function () {
if (getGlobalVariable('argv')['ivy']) {
// todo: enable when NGCC supports this.
// this test is not yet supported under IVY because can only transform packages from a single basePaths.
// https://angular-team.atlassian.net/browse/FW-1204
return;
}

await updateJsonFile('tsconfig.json', tsconfig => {
tsconfig.compilerOptions.paths = {
'*': ['./node_modules/*'],
Expand Down

0 comments on commit efe4633

Please sign in to comment.