refactor(ivy): ngcc - tidy up `mainNgcc` (#29643)

PR Close #29643
This commit is contained in:
Pete Bacon Darwin 2019-04-28 20:47:56 +01:00 committed by Andrew Kushnir
parent 321da5cc83
commit eef4ca5dd3
1 changed files with 19 additions and 15 deletions

View File

@ -93,20 +93,8 @@ export function mainNgcc({basePath, targetEntryPointPath,
const {entryPoints} = const {entryPoints} =
finder.findEntryPoints(AbsoluteFsPath.from(basePath), absoluteTargetEntryPointPath); finder.findEntryPoints(AbsoluteFsPath.from(basePath), absoluteTargetEntryPointPath);
if (absoluteTargetEntryPointPath && entryPoints.every(entryPoint => { if (absoluteTargetEntryPointPath && entryPoints.length === 0) {
return entryPoint.path !== absoluteTargetEntryPointPath; markNonAngularPackageAsProcessed(absoluteTargetEntryPointPath, propertiesToConsider);
})) {
// 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);
});
return; return;
} }
@ -116,7 +104,8 @@ export function mainNgcc({basePath, targetEntryPointPath,
const compiledFormats = new Set<string>(); const compiledFormats = new Set<string>();
const entryPointPackageJson = entryPoint.packageJson; 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'); const hasProcessedDts = hasBeenProcessed(entryPointPackageJson, 'typings');
@ -200,3 +189,18 @@ function hasProcessedTargetEntryPoint(
// property before the first processed format that was unprocessed. // property before the first processed format that was unprocessed.
return true; 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);
});
}