fix(ngcc): only lock ngcc after targeted entry-point check (#34722)
The Angular CLI will continue to call ngcc on all possible packages, even if they have already been processed by ngcc in a postinstall script. In a parallel build environment, this was causing ngcc to complain that it was being run in more than one process at the same time. This commit moves the check for whether the targeted package has been processed outside the locked code section, since there is no issue with multiple ngcc processes from doing this check. PR Close #34722
This commit is contained in:
parent
a107e9edc6
commit
03465b621b
|
@ -149,6 +149,20 @@ export function mainNgcc(
|
||||||
// NOTE: Avoid eagerly instantiating anything that might not be used when running sync/async or in
|
// NOTE: Avoid eagerly instantiating anything that might not be used when running sync/async or in
|
||||||
// master/worker process.
|
// master/worker process.
|
||||||
const fileSystem = getFileSystem();
|
const fileSystem = getFileSystem();
|
||||||
|
|
||||||
|
|
||||||
|
// Bail out early if the work is already done.
|
||||||
|
const supportedPropertiesToConsider = ensureSupportedProperties(propertiesToConsider);
|
||||||
|
const absoluteTargetEntryPointPath =
|
||||||
|
targetEntryPointPath !== undefined ? resolve(basePath, targetEntryPointPath) : undefined;
|
||||||
|
if (absoluteTargetEntryPointPath !== undefined &&
|
||||||
|
hasProcessedTargetEntryPoint(
|
||||||
|
fileSystem, absoluteTargetEntryPointPath, supportedPropertiesToConsider,
|
||||||
|
compileAllFormats)) {
|
||||||
|
logger.debug('The target entry-point has already been processed');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// NOTE: To avoid file corruption, ensure that each `ngcc` invocation only creates _one_ instance
|
// NOTE: To avoid file corruption, ensure that each `ngcc` invocation only creates _one_ instance
|
||||||
// of `PackageJsonUpdater` that actually writes to disk (across all processes).
|
// of `PackageJsonUpdater` that actually writes to disk (across all processes).
|
||||||
// This is hard to enforce automatically, when running on multiple processes, so needs to be
|
// This is hard to enforce automatically, when running on multiple processes, so needs to be
|
||||||
|
@ -160,8 +174,6 @@ export function mainNgcc(
|
||||||
logger.debug('Analyzing entry-points...');
|
logger.debug('Analyzing entry-points...');
|
||||||
const startTime = Date.now();
|
const startTime = Date.now();
|
||||||
|
|
||||||
const supportedPropertiesToConsider = ensureSupportedProperties(propertiesToConsider);
|
|
||||||
|
|
||||||
const moduleResolver = new ModuleResolver(fileSystem, pathMappings);
|
const moduleResolver = new ModuleResolver(fileSystem, pathMappings);
|
||||||
const esmDependencyHost = new EsmDependencyHost(fileSystem, moduleResolver);
|
const esmDependencyHost = new EsmDependencyHost(fileSystem, moduleResolver);
|
||||||
const umdDependencyHost = new UmdDependencyHost(fileSystem, moduleResolver);
|
const umdDependencyHost = new UmdDependencyHost(fileSystem, moduleResolver);
|
||||||
|
@ -180,7 +192,7 @@ export function mainNgcc(
|
||||||
const config = new NgccConfiguration(fileSystem, dirname(absBasePath));
|
const config = new NgccConfiguration(fileSystem, dirname(absBasePath));
|
||||||
const {entryPoints, graph} = getEntryPoints(
|
const {entryPoints, graph} = getEntryPoints(
|
||||||
fileSystem, pkgJsonUpdater, logger, dependencyResolver, config, absBasePath,
|
fileSystem, pkgJsonUpdater, logger, dependencyResolver, config, absBasePath,
|
||||||
targetEntryPointPath, pathMappings, supportedPropertiesToConsider, compileAllFormats);
|
absoluteTargetEntryPointPath, pathMappings);
|
||||||
|
|
||||||
const unprocessableEntryPointPaths: string[] = [];
|
const unprocessableEntryPointPaths: string[] = [];
|
||||||
// The tasks are partially ordered by virtue of the entry-points being partially ordered too.
|
// The tasks are partially ordered by virtue of the entry-points being partially ordered too.
|
||||||
|
@ -348,13 +360,12 @@ function getExecutor(
|
||||||
function getEntryPoints(
|
function getEntryPoints(
|
||||||
fs: FileSystem, pkgJsonUpdater: PackageJsonUpdater, logger: Logger,
|
fs: FileSystem, pkgJsonUpdater: PackageJsonUpdater, logger: Logger,
|
||||||
resolver: DependencyResolver, config: NgccConfiguration, basePath: AbsoluteFsPath,
|
resolver: DependencyResolver, config: NgccConfiguration, basePath: AbsoluteFsPath,
|
||||||
targetEntryPointPath: string | undefined, pathMappings: PathMappings | undefined,
|
targetEntryPointPath: AbsoluteFsPath | undefined, pathMappings: PathMappings |
|
||||||
propertiesToConsider: string[], compileAllFormats: boolean):
|
undefined): {entryPoints: PartiallyOrderedEntryPoints, graph: DepGraph<EntryPoint>} {
|
||||||
{entryPoints: PartiallyOrderedEntryPoints, graph: DepGraph<EntryPoint>} {
|
|
||||||
const {entryPoints, invalidEntryPoints, graph} = (targetEntryPointPath !== undefined) ?
|
const {entryPoints, invalidEntryPoints, graph} = (targetEntryPointPath !== undefined) ?
|
||||||
getTargetedEntryPoints(
|
getTargetedEntryPoints(
|
||||||
fs, pkgJsonUpdater, logger, resolver, config, basePath, targetEntryPointPath,
|
fs, pkgJsonUpdater, logger, resolver, config, basePath, targetEntryPointPath,
|
||||||
propertiesToConsider, compileAllFormats, pathMappings) :
|
pathMappings) :
|
||||||
getAllEntryPoints(fs, config, logger, resolver, basePath, pathMappings);
|
getAllEntryPoints(fs, config, logger, resolver, basePath, pathMappings);
|
||||||
logInvalidEntryPoints(logger, invalidEntryPoints);
|
logInvalidEntryPoints(logger, invalidEntryPoints);
|
||||||
return {entryPoints, graph};
|
return {entryPoints, graph};
|
||||||
|
@ -363,19 +374,8 @@ function getEntryPoints(
|
||||||
function getTargetedEntryPoints(
|
function getTargetedEntryPoints(
|
||||||
fs: FileSystem, pkgJsonUpdater: PackageJsonUpdater, logger: Logger,
|
fs: FileSystem, pkgJsonUpdater: PackageJsonUpdater, logger: Logger,
|
||||||
resolver: DependencyResolver, config: NgccConfiguration, basePath: AbsoluteFsPath,
|
resolver: DependencyResolver, config: NgccConfiguration, basePath: AbsoluteFsPath,
|
||||||
targetEntryPointPath: string, propertiesToConsider: string[], compileAllFormats: boolean,
|
absoluteTargetEntryPointPath: AbsoluteFsPath,
|
||||||
pathMappings: PathMappings | undefined): SortedEntryPointsInfo {
|
pathMappings: PathMappings | undefined): SortedEntryPointsInfo {
|
||||||
const absoluteTargetEntryPointPath = resolve(basePath, targetEntryPointPath);
|
|
||||||
if (hasProcessedTargetEntryPoint(
|
|
||||||
fs, absoluteTargetEntryPointPath, propertiesToConsider, compileAllFormats)) {
|
|
||||||
logger.debug('The target entry-point has already been processed');
|
|
||||||
return {
|
|
||||||
entryPoints: [] as unknown as PartiallyOrderedEntryPoints,
|
|
||||||
invalidEntryPoints: [],
|
|
||||||
ignoredDependencies: [],
|
|
||||||
graph: EMPTY_GRAPH,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
const finder = new TargetedEntryPointFinder(
|
const finder = new TargetedEntryPointFinder(
|
||||||
fs, config, logger, resolver, basePath, absoluteTargetEntryPointPath, pathMappings);
|
fs, config, logger, resolver, basePath, absoluteTargetEntryPointPath, pathMappings);
|
||||||
const entryPointInfo = finder.findEntryPoints();
|
const entryPointInfo = finder.findEntryPoints();
|
||||||
|
|
Loading…
Reference in New Issue