refactor(ngcc): move `PathMappings` to separate file to avoid circular dependency (#36626)
Now that `ngcc/src/ngcc_options` imports `FileWriter` type, there is a circular dependency detected by the `ts-circular-deps:check` lint check: ``` ngcc/src/ngcc_options.ts → ngcc/src/writing/file_writer.ts → ngcc/src/packages/entry_point_bundle.ts → ngcc/src/ngcc_options.ts ``` This commit moves the `PathMappings` type (and related helpers) to a separate file to avoid the circular dependency. NOTE: The circular dependency was only with taking types into account. There was no circular dependency for the actual (JS) code. PR Close #36626
This commit is contained in:
parent
4779c4b94a
commit
45c09416ed
|
@ -12,7 +12,8 @@ import {AsyncNgccOptions, NgccOptions, SyncNgccOptions} from './src/ngcc_options
|
||||||
|
|
||||||
export {ConsoleLogger} from './src/logging/console_logger';
|
export {ConsoleLogger} from './src/logging/console_logger';
|
||||||
export {Logger, LogLevel} from './src/logging/logger';
|
export {Logger, LogLevel} from './src/logging/logger';
|
||||||
export {AsyncNgccOptions, NgccOptions, PathMappings, SyncNgccOptions} from './src/ngcc_options';
|
export {AsyncNgccOptions, NgccOptions, SyncNgccOptions} from './src/ngcc_options';
|
||||||
|
export {PathMappings} from './src/path_mappings';
|
||||||
|
|
||||||
export function process(options: AsyncNgccOptions): Promise<void>;
|
export function process(options: AsyncNgccOptions): Promise<void>;
|
||||||
export function process(options: SyncNgccOptions): void;
|
export function process(options: SyncNgccOptions): void;
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
* found in the LICENSE file at https://angular.io/license
|
* found in the LICENSE file at https://angular.io/license
|
||||||
*/
|
*/
|
||||||
import {AbsoluteFsPath, FileSystem} from '../../../src/ngtsc/file_system';
|
import {AbsoluteFsPath, FileSystem} from '../../../src/ngtsc/file_system';
|
||||||
import {PathMappings} from '../ngcc_options';
|
import {PathMappings} from '../path_mappings';
|
||||||
import {EsmDependencyHost} from './esm_dependency_host';
|
import {EsmDependencyHost} from './esm_dependency_host';
|
||||||
import {ModuleResolver} from './module_resolver';
|
import {ModuleResolver} from './module_resolver';
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
* found in the LICENSE file at https://angular.io/license
|
* found in the LICENSE file at https://angular.io/license
|
||||||
*/
|
*/
|
||||||
import {absoluteFrom, AbsoluteFsPath, dirname, FileSystem, isRoot, join, resolve} from '../../../src/ngtsc/file_system';
|
import {absoluteFrom, AbsoluteFsPath, dirname, FileSystem, isRoot, join, resolve} from '../../../src/ngtsc/file_system';
|
||||||
import {PathMappings} from '../ngcc_options';
|
import {PathMappings} from '../path_mappings';
|
||||||
import {isRelativePath, resolveFileWithPostfixes} from '../utils';
|
import {isRelativePath, resolveFileWithPostfixes} from '../utils';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -9,10 +9,10 @@ import {AbsoluteFsPath, FileSystem, PathSegment} from '../../../src/ngtsc/file_s
|
||||||
import {EntryPointWithDependencies} from '../dependencies/dependency_host';
|
import {EntryPointWithDependencies} from '../dependencies/dependency_host';
|
||||||
import {DependencyResolver, SortedEntryPointsInfo} from '../dependencies/dependency_resolver';
|
import {DependencyResolver, SortedEntryPointsInfo} from '../dependencies/dependency_resolver';
|
||||||
import {Logger} from '../logging/logger';
|
import {Logger} from '../logging/logger';
|
||||||
import {PathMappings} from '../ngcc_options';
|
|
||||||
import {NgccConfiguration} from '../packages/configuration';
|
import {NgccConfiguration} from '../packages/configuration';
|
||||||
import {getEntryPointInfo, INCOMPATIBLE_ENTRY_POINT, NO_ENTRY_POINT} from '../packages/entry_point';
|
import {getEntryPointInfo, INCOMPATIBLE_ENTRY_POINT, NO_ENTRY_POINT} from '../packages/entry_point';
|
||||||
import {EntryPointManifest} from '../packages/entry_point_manifest';
|
import {EntryPointManifest} from '../packages/entry_point_manifest';
|
||||||
|
import {PathMappings} from '../path_mappings';
|
||||||
import {NGCC_DIRECTORY} from '../writing/new_entry_point_file_writer';
|
import {NGCC_DIRECTORY} from '../writing/new_entry_point_file_writer';
|
||||||
|
|
||||||
import {EntryPointFinder} from './interface';
|
import {EntryPointFinder} from './interface';
|
||||||
|
|
|
@ -9,10 +9,10 @@ import {AbsoluteFsPath, FileSystem, join, PathSegment, relative, relativeFrom} f
|
||||||
import {EntryPointWithDependencies} from '../dependencies/dependency_host';
|
import {EntryPointWithDependencies} from '../dependencies/dependency_host';
|
||||||
import {DependencyResolver, SortedEntryPointsInfo} from '../dependencies/dependency_resolver';
|
import {DependencyResolver, SortedEntryPointsInfo} from '../dependencies/dependency_resolver';
|
||||||
import {Logger} from '../logging/logger';
|
import {Logger} from '../logging/logger';
|
||||||
import {PathMappings} from '../ngcc_options';
|
|
||||||
import {hasBeenProcessed} from '../packages/build_marker';
|
import {hasBeenProcessed} from '../packages/build_marker';
|
||||||
import {NgccConfiguration} from '../packages/configuration';
|
import {NgccConfiguration} from '../packages/configuration';
|
||||||
import {EntryPoint, EntryPointJsonProperty, getEntryPointInfo, INCOMPATIBLE_ENTRY_POINT, NO_ENTRY_POINT} from '../packages/entry_point';
|
import {EntryPoint, EntryPointJsonProperty, getEntryPointInfo, INCOMPATIBLE_ENTRY_POINT, NO_ENTRY_POINT} from '../packages/entry_point';
|
||||||
|
import {PathMappings} from '../path_mappings';
|
||||||
|
|
||||||
import {EntryPointFinder} from './interface';
|
import {EntryPointFinder} from './interface';
|
||||||
import {getBasePaths} from './utils';
|
import {getBasePaths} from './utils';
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
*/
|
*/
|
||||||
import {AbsoluteFsPath, getFileSystem, relative, resolve} from '../../../src/ngtsc/file_system';
|
import {AbsoluteFsPath, getFileSystem, relative, resolve} from '../../../src/ngtsc/file_system';
|
||||||
import {Logger} from '../logging/logger';
|
import {Logger} from '../logging/logger';
|
||||||
import {PathMappings} from '../ngcc_options';
|
import {PathMappings} from '../path_mappings';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Extract all the base-paths that we need to search for entry-points.
|
* Extract all the base-paths that we need to search for entry-points.
|
||||||
|
|
|
@ -12,9 +12,9 @@ import {replaceTsWithNgInErrors} from '../../../src/ngtsc/diagnostics';
|
||||||
import {FileSystem} from '../../../src/ngtsc/file_system';
|
import {FileSystem} from '../../../src/ngtsc/file_system';
|
||||||
import {ParsedConfiguration} from '../../../src/perform_compile';
|
import {ParsedConfiguration} from '../../../src/perform_compile';
|
||||||
import {Logger} from '../logging/logger';
|
import {Logger} from '../logging/logger';
|
||||||
import {PathMappings} from '../ngcc_options';
|
|
||||||
import {getEntryPointFormat} from '../packages/entry_point';
|
import {getEntryPointFormat} from '../packages/entry_point';
|
||||||
import {makeEntryPointBundle} from '../packages/entry_point_bundle';
|
import {makeEntryPointBundle} from '../packages/entry_point_bundle';
|
||||||
|
import {PathMappings} from '../path_mappings';
|
||||||
import {FileWriter} from '../writing/file_writer';
|
import {FileWriter} from '../writing/file_writer';
|
||||||
|
|
||||||
import {CreateCompileFn} from './api';
|
import {CreateCompileFn} from './api';
|
||||||
|
|
|
@ -32,10 +32,11 @@ import {AsyncLocker} from './locking/async_locker';
|
||||||
import {LockFileWithChildProcess} from './locking/lock_file_with_child_process';
|
import {LockFileWithChildProcess} from './locking/lock_file_with_child_process';
|
||||||
import {SyncLocker} from './locking/sync_locker';
|
import {SyncLocker} from './locking/sync_locker';
|
||||||
import {Logger} from './logging/logger';
|
import {Logger} from './logging/logger';
|
||||||
import {AsyncNgccOptions, getSharedSetup, NgccOptions, PathMappings, SyncNgccOptions} from './ngcc_options';
|
import {AsyncNgccOptions, getSharedSetup, NgccOptions, SyncNgccOptions} from './ngcc_options';
|
||||||
import {NgccConfiguration} from './packages/configuration';
|
import {NgccConfiguration} from './packages/configuration';
|
||||||
import {EntryPointJsonProperty, SUPPORTED_FORMAT_PROPERTIES} from './packages/entry_point';
|
import {EntryPointJsonProperty, SUPPORTED_FORMAT_PROPERTIES} from './packages/entry_point';
|
||||||
import {EntryPointManifest, InvalidatingEntryPointManifest} from './packages/entry_point_manifest';
|
import {EntryPointManifest, InvalidatingEntryPointManifest} from './packages/entry_point_manifest';
|
||||||
|
import {PathMappings} from './path_mappings';
|
||||||
import {FileWriter} from './writing/file_writer';
|
import {FileWriter} from './writing/file_writer';
|
||||||
import {DirectPackageJsonUpdater, PackageJsonUpdater} from './writing/package_json_updater';
|
import {DirectPackageJsonUpdater, PackageJsonUpdater} from './writing/package_json_updater';
|
||||||
|
|
||||||
|
|
|
@ -5,12 +5,13 @@
|
||||||
* Use of this source code is governed by an MIT-style license that can be
|
* 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
|
* found in the LICENSE file at https://angular.io/license
|
||||||
*/
|
*/
|
||||||
import {absoluteFrom, AbsoluteFsPath, FileSystem, getFileSystem, resolve} from '../../src/ngtsc/file_system';
|
import {absoluteFrom, AbsoluteFsPath, FileSystem, getFileSystem} from '../../src/ngtsc/file_system';
|
||||||
import {ParsedConfiguration, readConfiguration} from '../../src/perform_compile';
|
import {ParsedConfiguration, readConfiguration} from '../../src/perform_compile';
|
||||||
|
|
||||||
import {ConsoleLogger} from './logging/console_logger';
|
import {ConsoleLogger} from './logging/console_logger';
|
||||||
import {Logger, LogLevel} from './logging/logger';
|
import {Logger, LogLevel} from './logging/logger';
|
||||||
import {SUPPORTED_FORMAT_PROPERTIES} from './packages/entry_point';
|
import {SUPPORTED_FORMAT_PROPERTIES} from './packages/entry_point';
|
||||||
|
import {getPathMappingsFromTsConfig, PathMappings} from './path_mappings';
|
||||||
import {FileWriter} from './writing/file_writer';
|
import {FileWriter} from './writing/file_writer';
|
||||||
import {InPlaceFileWriter} from './writing/in_place_file_writer';
|
import {InPlaceFileWriter} from './writing/in_place_file_writer';
|
||||||
import {NewEntryPointFileWriter} from './writing/new_entry_point_file_writer';
|
import {NewEntryPointFileWriter} from './writing/new_entry_point_file_writer';
|
||||||
|
@ -135,25 +136,6 @@ export type AsyncNgccOptions = Omit<SyncNgccOptions, 'async'>&{async: true};
|
||||||
*/
|
*/
|
||||||
export type NgccOptions = AsyncNgccOptions|SyncNgccOptions;
|
export type NgccOptions = AsyncNgccOptions|SyncNgccOptions;
|
||||||
|
|
||||||
export type PathMappings = {
|
|
||||||
baseUrl: string,
|
|
||||||
paths: {[key: string]: string[]}
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export type OptionalNgccOptionKeys = 'targetEntryPointPath'|'tsConfigPath'|'pathMappings';
|
export type OptionalNgccOptionKeys = 'targetEntryPointPath'|'tsConfigPath'|'pathMappings';
|
||||||
export type RequiredNgccOptions = Required<Omit<NgccOptions, OptionalNgccOptionKeys>>;
|
export type RequiredNgccOptions = Required<Omit<NgccOptions, OptionalNgccOptionKeys>>;
|
||||||
export type OptionalNgccOptions = Pick<NgccOptions, OptionalNgccOptionKeys>;
|
export type OptionalNgccOptions = Pick<NgccOptions, OptionalNgccOptionKeys>;
|
||||||
|
@ -183,7 +165,7 @@ export function getSharedSetup(options: NgccOptions): SharedSetup&RequiredNgccOp
|
||||||
compileAllFormats = true,
|
compileAllFormats = true,
|
||||||
createNewEntryPointFormats = false,
|
createNewEntryPointFormats = false,
|
||||||
logger = new ConsoleLogger(LogLevel.info),
|
logger = new ConsoleLogger(LogLevel.info),
|
||||||
pathMappings,
|
pathMappings = getPathMappingsFromTsConfig(tsConfig, projectPath),
|
||||||
async = false,
|
async = false,
|
||||||
errorOnFailedEntryPoint = false,
|
errorOnFailedEntryPoint = false,
|
||||||
enableI18nLegacyMessageIdFormat = true,
|
enableI18nLegacyMessageIdFormat = true,
|
||||||
|
@ -191,9 +173,7 @@ export function getSharedSetup(options: NgccOptions): SharedSetup&RequiredNgccOp
|
||||||
tsConfigPath,
|
tsConfigPath,
|
||||||
} = options;
|
} = options;
|
||||||
|
|
||||||
pathMappings = options.pathMappings || getPathMappingsFromTsConfig(tsConfig, projectPath);
|
if (!!targetEntryPointPath) {
|
||||||
|
|
||||||
if (!!options.targetEntryPointPath) {
|
|
||||||
// targetEntryPointPath forces us to error if an entry-point fails.
|
// targetEntryPointPath forces us to error if an entry-point fails.
|
||||||
errorOnFailedEntryPoint = true;
|
errorOnFailedEntryPoint = true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
*/
|
*/
|
||||||
import * as ts from 'typescript';
|
import * as ts from 'typescript';
|
||||||
import {AbsoluteFsPath, FileSystem, NgtscCompilerHost} from '../../../src/ngtsc/file_system';
|
import {AbsoluteFsPath, FileSystem, NgtscCompilerHost} from '../../../src/ngtsc/file_system';
|
||||||
import {PathMappings} from '../ngcc_options';
|
import {PathMappings} from '../path_mappings';
|
||||||
import {BundleProgram, makeBundleProgram} from './bundle_program';
|
import {BundleProgram, makeBundleProgram} from './bundle_program';
|
||||||
import {EntryPoint, EntryPointFormat} from './entry_point';
|
import {EntryPoint, EntryPointFormat} from './entry_point';
|
||||||
import {NgccSourcesCompilerHost} from './ngcc_compiler_host';
|
import {NgccSourcesCompilerHost} from './ngcc_compiler_host';
|
||||||
|
|
|
@ -0,0 +1,29 @@
|
||||||
|
/**
|
||||||
|
* @license
|
||||||
|
* Copyright Google Inc. All Rights Reserved.
|
||||||
|
*
|
||||||
|
* 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 {AbsoluteFsPath, resolve} from '../../src/ngtsc/file_system';
|
||||||
|
import {ParsedConfiguration} from '../../src/perform_compile';
|
||||||
|
|
||||||
|
|
||||||
|
export type PathMappings = {
|
||||||
|
baseUrl: string,
|
||||||
|
paths: {[key: string]: string[]}
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
|
@ -13,10 +13,10 @@ import {DtsDependencyHost} from '../../src/dependencies/dts_dependency_host';
|
||||||
import {EsmDependencyHost} from '../../src/dependencies/esm_dependency_host';
|
import {EsmDependencyHost} from '../../src/dependencies/esm_dependency_host';
|
||||||
import {ModuleResolver} from '../../src/dependencies/module_resolver';
|
import {ModuleResolver} from '../../src/dependencies/module_resolver';
|
||||||
import {DirectoryWalkerEntryPointFinder} from '../../src/entry_point_finder/directory_walker_entry_point_finder';
|
import {DirectoryWalkerEntryPointFinder} from '../../src/entry_point_finder/directory_walker_entry_point_finder';
|
||||||
import {PathMappings} from '../../src/ngcc_options';
|
|
||||||
import {NgccConfiguration} from '../../src/packages/configuration';
|
import {NgccConfiguration} from '../../src/packages/configuration';
|
||||||
import {EntryPoint} from '../../src/packages/entry_point';
|
import {EntryPoint} from '../../src/packages/entry_point';
|
||||||
import {EntryPointManifest, EntryPointManifestFile} from '../../src/packages/entry_point_manifest';
|
import {EntryPointManifest, EntryPointManifestFile} from '../../src/packages/entry_point_manifest';
|
||||||
|
import {PathMappings} from '../../src/path_mappings';
|
||||||
import {MockLogger} from '../helpers/mock_logger';
|
import {MockLogger} from '../helpers/mock_logger';
|
||||||
|
|
||||||
runInEachFileSystem(() => {
|
runInEachFileSystem(() => {
|
||||||
|
|
|
@ -13,10 +13,10 @@ import {DtsDependencyHost} from '../../src/dependencies/dts_dependency_host';
|
||||||
import {EsmDependencyHost} from '../../src/dependencies/esm_dependency_host';
|
import {EsmDependencyHost} from '../../src/dependencies/esm_dependency_host';
|
||||||
import {ModuleResolver} from '../../src/dependencies/module_resolver';
|
import {ModuleResolver} from '../../src/dependencies/module_resolver';
|
||||||
import {TargetedEntryPointFinder} from '../../src/entry_point_finder/targeted_entry_point_finder';
|
import {TargetedEntryPointFinder} from '../../src/entry_point_finder/targeted_entry_point_finder';
|
||||||
import {PathMappings} from '../../src/ngcc_options';
|
|
||||||
import {NGCC_VERSION} from '../../src/packages/build_marker';
|
import {NGCC_VERSION} from '../../src/packages/build_marker';
|
||||||
import {NgccConfiguration} from '../../src/packages/configuration';
|
import {NgccConfiguration} from '../../src/packages/configuration';
|
||||||
import {EntryPoint} from '../../src/packages/entry_point';
|
import {EntryPoint} from '../../src/packages/entry_point';
|
||||||
|
import {PathMappings} from '../../src/path_mappings';
|
||||||
import {MockLogger} from '../helpers/mock_logger';
|
import {MockLogger} from '../helpers/mock_logger';
|
||||||
|
|
||||||
runInEachFileSystem(() => {
|
runInEachFileSystem(() => {
|
||||||
|
|
Loading…
Reference in New Issue