feat(ngcc): support for new APF where module
points to esm2015 output (#36944)
As of version 10, libraries following the APF will no longer contain ESM5 output. Hence, tests in ngcc need to be updated as they currently rely on the release output of `@angular/core`. Additionally, we'd need to support in ngcc that the `module` property of entry-points no longer necessarily refers to `esm5` output, but instead can also target `esm2015`. We currently achieve this by checking the path the `module` property points to. We can do this because as per APF, the folder name is known for the esm2015 output. Long-term for more coverage, we want to sniff the format by looking for known ES2015 constructs in the file `module` refers to. PR Close #36944
This commit is contained in:

committed by
Alex Rickabaugh

parent
d5293d2aa3
commit
c98a4d6ddd
@ -27,7 +27,7 @@ export function parseCommandLineOptions(args: string[]): NgccOptions {
|
||||
alias: 'properties',
|
||||
array: true,
|
||||
describe:
|
||||
'An array of names of properties in package.json to compile (e.g. `module` or `es2015`)\n' +
|
||||
'An array of names of properties in package.json to compile (e.g. `module` or `main`)\n' +
|
||||
'Each of these properties should hold the path to a bundle-format.\n' +
|
||||
'If provided, only the specified properties are considered for processing.\n' +
|
||||
'If not provided, all the supported format properties (e.g. fesm2015, fesm5, es2015, esm2015, esm5, main, module) in the package.json are considered.'
|
||||
@ -136,4 +136,4 @@ export function parseCommandLineOptions(args: string[]): NgccOptions {
|
||||
errorOnFailedEntryPoint,
|
||||
tsConfigPath
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -207,6 +207,15 @@ export function getEntryPointFormat(
|
||||
}
|
||||
return sniffModuleFormat(fs, join(entryPoint.path, mainFile));
|
||||
case 'module':
|
||||
const moduleFilePath = entryPoint.packageJson['module'];
|
||||
// As of version 10, the `module` property in `package.json` should point to
|
||||
// the ESM2015 format output as per Angular Package format specification. This
|
||||
// means that the `module` property captures multiple formats, as old libraries
|
||||
// built with the old APF can still be processed. We detect the format by checking
|
||||
// the paths that should be used as per APF specification.
|
||||
if (typeof moduleFilePath === 'string' && moduleFilePath.includes('esm2015')) {
|
||||
return `esm2015`;
|
||||
}
|
||||
return 'esm5';
|
||||
default:
|
||||
return undefined;
|
||||
|
Reference in New Issue
Block a user