From f9fb8338f56a7fa5b033c9a71a917af0f8a84a4f Mon Sep 17 00:00:00 2001 From: Pete Bacon Darwin Date: Fri, 3 Apr 2020 22:00:51 +0100 Subject: [PATCH] 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 --- .../ngcc/src/packages/configuration.ts | 4 +- .../ngcc/test/packages/configuration_spec.ts | 48 ++++++++++++++++++- 2 files changed, 49 insertions(+), 3 deletions(-) diff --git a/packages/compiler-cli/ngcc/src/packages/configuration.ts b/packages/compiler-cli/ngcc/src/packages/configuration.ts index 10b45e9b31..5b718f7ca2 100644 --- a/packages/compiler-cli/ngcc/src/packages/configuration.ts +++ b/packages/compiler-cli/ngcc/src/packages/configuration.ts @@ -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); diff --git a/packages/compiler-cli/ngcc/test/packages/configuration_spec.ts b/packages/compiler-cli/ngcc/test/packages/configuration_spec.ts index b9c0667397..edf2a718cc 100644 --- a/packages/compiler-cli/ngcc/test/packages/configuration_spec.ts +++ b/packages/compiler-cli/ngcc/test/packages/configuration_spec.ts @@ -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`),