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:
parent
6b3aa60446
commit
f9fb8338f5
|
@ -241,9 +241,11 @@ export class NgccConfiguration {
|
||||||
const configFilePath = join(packagePath, NGCC_CONFIG_FILENAME);
|
const configFilePath = join(packagePath, NGCC_CONFIG_FILENAME);
|
||||||
if (this.fs.exists(configFilePath)) {
|
if (this.fs.exists(configFilePath)) {
|
||||||
try {
|
try {
|
||||||
|
const packageConfig = this.evalSrcFile(configFilePath);
|
||||||
return {
|
return {
|
||||||
|
...packageConfig,
|
||||||
versionRange: version || '*',
|
versionRange: version || '*',
|
||||||
entryPoints: this.processEntryPoints(packagePath, this.evalSrcFile(configFilePath)),
|
entryPoints: this.processEntryPoints(packagePath, packageConfig),
|
||||||
};
|
};
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
throw new Error(`Invalid package configuration file at "${configFilePath}": ` + e.message);
|
throw new Error(`Invalid package configuration file at "${configFilePath}": ` + e.message);
|
||||||
|
|
|
@ -102,6 +102,20 @@ runInEachFileSystem(() => {
|
||||||
.toHaveBeenCalledWith(_Abs('/project-1/node_modules/package-1/ngcc.config.js'));
|
.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', () => {
|
it('should used cached configuration for a package if available', () => {
|
||||||
loadTestFiles(packageWithConfigFiles('package-1', 'entry-point-1', '1.0.0'));
|
loadTestFiles(packageWithConfigFiles('package-1', 'entry-point-1', '1.0.0'));
|
||||||
const configuration = new NgccConfiguration(fs, _Abs('/project-1'));
|
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',
|
it('should return configuration for the correct version of a package found in a project level file',
|
||||||
() => {
|
() => {
|
||||||
loadTestFiles([{
|
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 [
|
return [
|
||||||
{
|
{
|
||||||
name: _Abs(`/project-1/node_modules/${packageName}/ngcc.config.js`),
|
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`),
|
name: _Abs(`/project-1/node_modules/${packageName}/package.json`),
|
||||||
|
|
Loading…
Reference in New Issue