refactor(ivy): ngcc - use a fixed set of properties to compile if none provided (#29092)
Previously we always considered all the properties in the package.json if no `propertiesToConsidere` were provided. But this results in computing a new set of properties for each entry-point plus iterating through many of the package.json properties that are not related to bundle-format paths. PR Close #29092
This commit is contained in:
parent
bdcbd9ed4b
commit
7ea0d1bd3a
|
@ -7,14 +7,16 @@
|
|||
*/
|
||||
|
||||
import {AbsoluteFsPath} from '../../src/ngtsc/path';
|
||||
|
||||
import {checkMarker, writeMarker} from './packages/build_marker';
|
||||
import {DependencyHost} from './packages/dependency_host';
|
||||
import {DependencyResolver} from './packages/dependency_resolver';
|
||||
import {EntryPointFormat, EntryPointJsonProperty, getEntryPointFormat} from './packages/entry_point';
|
||||
import {EntryPointFormat, EntryPointJsonProperty, SUPPORTED_FORMAT_PROPERTIES, getEntryPointFormat} from './packages/entry_point';
|
||||
import {makeEntryPointBundle} from './packages/entry_point_bundle';
|
||||
import {EntryPointFinder} from './packages/entry_point_finder';
|
||||
import {Transformer} from './packages/transformer';
|
||||
|
||||
|
||||
/**
|
||||
* The options to configure the ngcc compiler.
|
||||
*/
|
||||
|
@ -48,7 +50,8 @@ const SUPPORTED_FORMATS: EntryPointFormat[] = ['esm5', 'esm2015'];
|
|||
*
|
||||
* @param options The options telling ngcc what to compile and how.
|
||||
*/
|
||||
export function mainNgcc({baseSourcePath, targetEntryPointPath, propertiesToConsider,
|
||||
export function mainNgcc({baseSourcePath, targetEntryPointPath,
|
||||
propertiesToConsider = SUPPORTED_FORMAT_PROPERTIES,
|
||||
compileAllFormats = true}: NgccOptions): void {
|
||||
const transformer = new Transformer(baseSourcePath, baseSourcePath);
|
||||
const host = new DependencyHost();
|
||||
|
@ -61,12 +64,10 @@ export function mainNgcc({baseSourcePath, targetEntryPointPath, propertiesToCons
|
|||
// Are we compiling the Angular core?
|
||||
const isCore = entryPoint.name === '@angular/core';
|
||||
|
||||
const propertiesToCompile =
|
||||
propertiesToConsider || Object.keys(entryPoint.packageJson) as EntryPointJsonProperty[];
|
||||
const compiledFormats = new Set<string>();
|
||||
|
||||
for (let i = 0; i < propertiesToCompile.length; i++) {
|
||||
const property = propertiesToCompile[i];
|
||||
for (let i = 0; i < propertiesToConsider.length; i++) {
|
||||
const property = propertiesToConsider[i];
|
||||
const formatPath = entryPoint.packageJson[property];
|
||||
const format = getEntryPointFormat(property);
|
||||
|
||||
|
@ -106,7 +107,7 @@ export function mainNgcc({baseSourcePath, targetEntryPointPath, propertiesToCons
|
|||
|
||||
if (compiledFormats.size === 0) {
|
||||
throw new Error(
|
||||
`Failed to compile any formats for entry-point at (${entryPoint.path}). Tried ${propertiesToCompile}.`);
|
||||
`Failed to compile any formats for entry-point at (${entryPoint.path}). Tried ${propertiesToConsider}.`);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
@ -55,6 +55,9 @@ export interface EntryPointPackageJson extends PackageJsonFormatProperties {
|
|||
}
|
||||
|
||||
export type EntryPointJsonProperty = keyof(PackageJsonFormatProperties);
|
||||
// We need to keep the elements of this const and the `EntryPointJsonProperty` type in sync.
|
||||
export const SUPPORTED_FORMAT_PROPERTIES: EntryPointJsonProperty[] =
|
||||
['fesm2015', 'fesm5', 'es2015', 'esm2015', 'esm5', 'main', 'module'];
|
||||
|
||||
/**
|
||||
* Try to create an entry-point from the given paths and properties.
|
||||
|
|
Loading…
Reference in New Issue