From eef4ca5dd3bb7f435414117fc42eb9d59a8c8fab Mon Sep 17 00:00:00 2001 From: Pete Bacon Darwin Date: Sun, 28 Apr 2019 20:47:56 +0100 Subject: [PATCH] refactor(ivy): ngcc - tidy up `mainNgcc` (#29643) PR Close #29643 --- packages/compiler-cli/ngcc/src/main.ts | 34 ++++++++++++++------------ 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/packages/compiler-cli/ngcc/src/main.ts b/packages/compiler-cli/ngcc/src/main.ts index 24967430da..63c802a247 100644 --- a/packages/compiler-cli/ngcc/src/main.ts +++ b/packages/compiler-cli/ngcc/src/main.ts @@ -93,20 +93,8 @@ export function mainNgcc({basePath, targetEntryPointPath, const {entryPoints} = finder.findEntryPoints(AbsoluteFsPath.from(basePath), absoluteTargetEntryPointPath); - if (absoluteTargetEntryPointPath && entryPoints.every(entryPoint => { - return entryPoint.path !== absoluteTargetEntryPointPath; - })) { - // If we get here, then the requested entry-point did not contain anything compiled by - // the old Angular compiler. Therefore there is nothing for ngcc to do. - // So mark all formats in this entry-point as processed so that clients of ngcc can avoid - // triggering ngcc for this entry-point in the future. - const packageJsonPath = - AbsoluteFsPath.from(resolve(absoluteTargetEntryPointPath, 'package.json')); - const packageJson = JSON.parse(readFileSync(packageJsonPath, 'utf8')); - propertiesToConsider.forEach(formatProperty => { - if (packageJson[formatProperty]) - markAsProcessed(packageJson, packageJsonPath, formatProperty as EntryPointJsonProperty); - }); + if (absoluteTargetEntryPointPath && entryPoints.length === 0) { + markNonAngularPackageAsProcessed(absoluteTargetEntryPointPath, propertiesToConsider); return; } @@ -116,7 +104,8 @@ export function mainNgcc({basePath, targetEntryPointPath, const compiledFormats = new Set(); const entryPointPackageJson = entryPoint.packageJson; - const entryPointPackageJsonPath = AbsoluteFsPath.from(resolve(entryPoint.path, 'package.json')); + const entryPointPackageJsonPath = + AbsoluteFsPath.fromUnchecked(`${entryPoint.path}/package.json`); const hasProcessedDts = hasBeenProcessed(entryPointPackageJson, 'typings'); @@ -200,3 +189,18 @@ function hasProcessedTargetEntryPoint( // property before the first processed format that was unprocessed. return true; } + +/** + * If we get here, then the requested entry-point did not contain anything compiled by + * the old Angular compiler. Therefore there is nothing for ngcc to do. + * So mark all formats in this entry-point as processed so that clients of ngcc can avoid + * triggering ngcc for this entry-point in the future. + */ +function markNonAngularPackageAsProcessed(path: AbsoluteFsPath, propertiesToConsider: string[]) { + const packageJsonPath = AbsoluteFsPath.from(resolve(path, 'package.json')); + const packageJson = JSON.parse(readFileSync(packageJsonPath, 'utf8')); + propertiesToConsider.forEach(formatProperty => { + if (packageJson[formatProperty]) + markAsProcessed(packageJson, packageJsonPath, formatProperty as EntryPointJsonProperty); + }); +}