fix(ngcc): support ignoring deep-imports via package config (#36423)

Recently we added support for ignoring specified deep-import
warnings by providing sets of regular expressions within the
`ngcc.config.js` file. But this was only working for the project
level configuration.

This commit fixes ngcc so that it will also read these regular
expressions from package level configuration too.

Fixes #35750

PR Close #36423
This commit is contained in:
Pete Bacon Darwin 2020-04-03 22:00:51 +01:00 committed by Kara Erickson
parent 6b3aa60446
commit f9fb8338f5
2 changed files with 49 additions and 3 deletions

View File

@ -241,9 +241,11 @@ export class NgccConfiguration {
const configFilePath = join(packagePath, NGCC_CONFIG_FILENAME);
if (this.fs.exists(configFilePath)) {
try {
const packageConfig = this.evalSrcFile(configFilePath);
return {
...packageConfig,
versionRange: version || '*',
entryPoints: this.processEntryPoints(packagePath, this.evalSrcFile(configFilePath)),
entryPoints: this.processEntryPoints(packagePath, packageConfig),
};
} catch (e) {
throw new Error(`Invalid package configuration file at "${configFilePath}": ` + e.message);

View File

@ -102,6 +102,20 @@ runInEachFileSystem(() => {
.toHaveBeenCalledWith(_Abs('/project-1/node_modules/package-1/ngcc.config.js'));
});
it('should read extra package config from package level file', () => {
loadTestFiles(packageWithConfigFiles(
'package-1', 'entry-point-1', '1.0.0', 'ignorableDeepImportMatchers: [ /xxx/ ]'));
const configuration = new NgccConfiguration(fs, _Abs('/project-1'));
const config =
configuration.getConfig(_Abs('/project-1/node_modules/package-1'), '1.0.0');
expect(config).toEqual({
versionRange: '1.0.0',
entryPoints: {[_Abs('/project-1/node_modules/package-1/entry-point-1')]: {}},
ignorableDeepImportMatchers: [/xxx/],
});
});
it('should used cached configuration for a package if available', () => {
loadTestFiles(packageWithConfigFiles('package-1', 'entry-point-1', '1.0.0'));
const configuration = new NgccConfiguration(fs, _Abs('/project-1'));
@ -169,6 +183,31 @@ runInEachFileSystem(() => {
});
});
it('should return configuration for a package found in a project level file', () => {
loadTestFiles([{
name: _Abs('/project-1/ngcc.config.js'),
contents: `
module.exports = {
packages: {
'package-1': {
entryPoints: {
'./entry-point-1': {}
},
ignorableDeepImportMatchers: [ /xxx/ ],
},
},
};`
}]);
const configuration = new NgccConfiguration(fs, _Abs('/project-1'));
const config =
configuration.getConfig(_Abs('/project-1/node_modules/package-1'), '1.0.0');
expect(config).toEqual({
versionRange: '*',
entryPoints: {[_Abs('/project-1/node_modules/package-1/entry-point-1')]: {}},
ignorableDeepImportMatchers: [/xxx/],
});
});
it('should return configuration for the correct version of a package found in a project level file',
() => {
loadTestFiles([{
@ -569,11 +608,16 @@ runInEachFileSystem(() => {
});
});
function packageWithConfigFiles(packageName: string, entryPointName: string, version: string) {
function packageWithConfigFiles(
packageName: string, entryPointName: string, version: string, extraConfig: string = '') {
return [
{
name: _Abs(`/project-1/node_modules/${packageName}/ngcc.config.js`),
contents: `module.exports = {entryPoints: { './${entryPointName}': {}}}`
contents: `
module.exports = {
entryPoints: { './${entryPointName}': {} },
${extraConfig}
};`
},
{
name: _Abs(`/project-1/node_modules/${packageName}/package.json`),