Skip to content

Commit f9fb833

Browse files
petebacondarwinkara
authored andcommitted
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
1 parent 6b3aa60 commit f9fb833

File tree

2 files changed

+49
-3
lines changed

2 files changed

+49
-3
lines changed

packages/compiler-cli/ngcc/src/packages/configuration.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,9 +241,11 @@ export class NgccConfiguration {
241241
const configFilePath = join(packagePath, NGCC_CONFIG_FILENAME);
242242
if (this.fs.exists(configFilePath)) {
243243
try {
244+
const packageConfig = this.evalSrcFile(configFilePath);
244245
return {
246+
...packageConfig,
245247
versionRange: version || '*',
246-
entryPoints: this.processEntryPoints(packagePath, this.evalSrcFile(configFilePath)),
248+
entryPoints: this.processEntryPoints(packagePath, packageConfig),
247249
};
248250
} catch (e) {
249251
throw new Error(`Invalid package configuration file at "${configFilePath}": ` + e.message);

packages/compiler-cli/ngcc/test/packages/configuration_spec.ts

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,20 @@ runInEachFileSystem(() => {
102102
.toHaveBeenCalledWith(_Abs('/project-1/node_modules/package-1/ngcc.config.js'));
103103
});
104104

105+
it('should read extra package config from package level file', () => {
106+
loadTestFiles(packageWithConfigFiles(
107+
'package-1', 'entry-point-1', '1.0.0', 'ignorableDeepImportMatchers: [ /xxx/ ]'));
108+
const configuration = new NgccConfiguration(fs, _Abs('/project-1'));
109+
const config =
110+
configuration.getConfig(_Abs('/project-1/node_modules/package-1'), '1.0.0');
111+
112+
expect(config).toEqual({
113+
versionRange: '1.0.0',
114+
entryPoints: {[_Abs('/project-1/node_modules/package-1/entry-point-1')]: {}},
115+
ignorableDeepImportMatchers: [/xxx/],
116+
});
117+
});
118+
105119
it('should used cached configuration for a package if available', () => {
106120
loadTestFiles(packageWithConfigFiles('package-1', 'entry-point-1', '1.0.0'));
107121
const configuration = new NgccConfiguration(fs, _Abs('/project-1'));
@@ -169,6 +183,31 @@ runInEachFileSystem(() => {
169183
});
170184
});
171185

186+
it('should return configuration for a package found in a project level file', () => {
187+
loadTestFiles([{
188+
name: _Abs('/project-1/ngcc.config.js'),
189+
contents: `
190+
module.exports = {
191+
packages: {
192+
'package-1': {
193+
entryPoints: {
194+
'./entry-point-1': {}
195+
},
196+
ignorableDeepImportMatchers: [ /xxx/ ],
197+
},
198+
},
199+
};`
200+
}]);
201+
const configuration = new NgccConfiguration(fs, _Abs('/project-1'));
202+
const config =
203+
configuration.getConfig(_Abs('/project-1/node_modules/package-1'), '1.0.0');
204+
expect(config).toEqual({
205+
versionRange: '*',
206+
entryPoints: {[_Abs('/project-1/node_modules/package-1/entry-point-1')]: {}},
207+
ignorableDeepImportMatchers: [/xxx/],
208+
});
209+
});
210+
172211
it('should return configuration for the correct version of a package found in a project level file',
173212
() => {
174213
loadTestFiles([{
@@ -569,11 +608,16 @@ runInEachFileSystem(() => {
569608
});
570609
});
571610

572-
function packageWithConfigFiles(packageName: string, entryPointName: string, version: string) {
611+
function packageWithConfigFiles(
612+
packageName: string, entryPointName: string, version: string, extraConfig: string = '') {
573613
return [
574614
{
575615
name: _Abs(`/project-1/node_modules/${packageName}/ngcc.config.js`),
576-
contents: `module.exports = {entryPoints: { './${entryPointName}': {}}}`
616+
contents: `
617+
module.exports = {
618+
entryPoints: { './${entryPointName}': {} },
619+
${extraConfig}
620+
};`
577621
},
578622
{
579623
name: _Abs(`/project-1/node_modules/${packageName}/package.json`),

0 commit comments

Comments
 (0)