refactor(ngcc): move pathMapping processing to utils (#36637)

PR Close #36637
This commit is contained in:
Pete Bacon Darwin 2020-04-15 16:23:30 +01:00 committed by Matias Niemelä
parent 33df4b74da
commit 7e5e60b757
2 changed files with 20 additions and 10 deletions

View File

@ -29,7 +29,7 @@ import {ClusterExecutor} from './execution/cluster/executor';
import {ClusterPackageJsonUpdater} from './execution/cluster/package_json_updater';
import {getCreateCompileFn} from './execution/create_compile_function';
import {SingleProcessExecutorAsync, SingleProcessExecutorSync} from './execution/single_process_executor';
import {CreateTaskCompletedCallback, Task, TaskProcessingOutcome} from './execution/tasks/api';
import {CreateTaskCompletedCallback, TaskProcessingOutcome} from './execution/tasks/api';
import {composeTaskCompletedCallbacks, createLogErrorHandler, createMarkAsProcessedHandler, createThrowErrorHandler} from './execution/tasks/completion';
import {AsyncLocker} from './locking/async_locker';
import {LockFileWithChildProcess} from './locking/lock_file_with_child_process';
@ -39,7 +39,7 @@ import {Logger, LogLevel} from './logging/logger';
import {NgccConfiguration} from './packages/configuration';
import {EntryPointJsonProperty, SUPPORTED_FORMAT_PROPERTIES} from './packages/entry_point';
import {EntryPointManifest, InvalidatingEntryPointManifest} from './packages/entry_point_manifest';
import {PathMappings} from './utils';
import {getPathMappingsFromTsConfig, PathMappings} from './utils';
import {DirectPackageJsonUpdater, PackageJsonUpdater} from './writing/package_json_updater';
/**
@ -83,13 +83,8 @@ export function mainNgcc({
const config = new NgccConfiguration(fileSystem, projectPath);
const tsConfig = tsConfigPath !== null ? readConfiguration(tsConfigPath || projectPath) : null;
// If `pathMappings` is not provided directly, then try getting it from `tsConfig`, if available.
if (tsConfig !== null && pathMappings === undefined && tsConfig.options.baseUrl !== undefined &&
tsConfig.options.paths) {
pathMappings = {
baseUrl: resolve(projectPath, tsConfig.options.baseUrl),
paths: tsConfig.options.paths,
};
if (pathMappings === undefined) {
pathMappings = getPathMappingsFromTsConfig(tsConfig, projectPath);
}
const dependencyResolver = getDependencyResolver(fileSystem, logger, config, pathMappings);

View File

@ -5,9 +5,10 @@
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
import {ParsedConfiguration} from '@angular/compiler-cli/src/perform_compile';
import * as ts from 'typescript';
import {absoluteFrom, AbsoluteFsPath, FileSystem, isRooted} from '../../src/ngtsc/file_system';
import {absoluteFrom, AbsoluteFsPath, FileSystem, isRooted, resolve} from '../../src/ngtsc/file_system';
import {KnownDeclaration} from '../../src/ngtsc/reflection';
/**
@ -185,3 +186,17 @@ export function stripDollarSuffix(value: string): string {
export function stripExtension(fileName: string): string {
return fileName.replace(/\..+$/, '');
}
/**
* If `pathMappings` is not provided directly, then try getting it from `tsConfig`, if available.
*/
export function getPathMappingsFromTsConfig(
tsConfig: ParsedConfiguration|null, projectPath: AbsoluteFsPath): PathMappings|undefined {
if (tsConfig !== null && tsConfig.options.baseUrl !== undefined &&
tsConfig.options.paths !== undefined) {
return {
baseUrl: resolve(projectPath, tsConfig.options.baseUrl),
paths: tsConfig.options.paths,
};
}
}