fix(ngcc): correctly get config for packages in nested node_modules/
(#37040)
Previously, ngcc would only be able to match an ngcc configuration to packages that were located inside the project's top-level `node_modules/`. However, if there are multiple versions of a package in a project (e.g. as a transitive dependency of other packages), multiple copies of a package (at different versions) may exist in nested `node_modules/` directories. For example, one at `<project-root>/node_modules/some-package/` and one at `<project-root>/node_modules/other-package/node_modules/some-package/`. In such cases, ngcc was only able to detect the config for the first copy but not for the second. This commit fixes this by returning a new instance of `ProcessedNgccPackageConfig` for each different package path (even if they refer to the same package name). In these `ProcessedNgccPackageConfig`, the `entryPoints` paths have been processed to take the package path into account. PR Close #37040
This commit is contained in:

committed by
Misko Hevery

parent
8f3695e20e
commit
bf682d73d4
@ -13,7 +13,7 @@ import {DtsDependencyHost} from '../../src/dependencies/dts_dependency_host';
|
||||
import {EsmDependencyHost} from '../../src/dependencies/esm_dependency_host';
|
||||
import {ModuleResolver} from '../../src/dependencies/module_resolver';
|
||||
import {DirectoryWalkerEntryPointFinder} from '../../src/entry_point_finder/directory_walker_entry_point_finder';
|
||||
import {NgccConfiguration} from '../../src/packages/configuration';
|
||||
import {NgccConfiguration, ProcessedNgccPackageConfig} from '../../src/packages/configuration';
|
||||
import {EntryPoint} from '../../src/packages/entry_point';
|
||||
import {EntryPointManifest, EntryPointManifestFile} from '../../src/packages/entry_point_manifest';
|
||||
import {PathMappings} from '../../src/path_mappings';
|
||||
@ -109,12 +109,13 @@ runInEachFileSystem(() => {
|
||||
fs, config, logger, resolver, manifest, basePath, undefined);
|
||||
|
||||
loadTestFiles(createPackage(basePath, 'some-package'));
|
||||
spyOn(config, 'getPackageConfig').and.returnValue({
|
||||
versionRange: '*',
|
||||
entryPoints: {
|
||||
[_Abs('/project/node_modules/some-package')]: {ignore: true},
|
||||
},
|
||||
});
|
||||
spyOn(config, 'getPackageConfig')
|
||||
.and.returnValue(
|
||||
new ProcessedNgccPackageConfig(_Abs('/project/node_modules/some-package'), {
|
||||
entryPoints: {
|
||||
'.': {ignore: true},
|
||||
},
|
||||
}));
|
||||
|
||||
const {entryPoints} = finder.findEntryPoints();
|
||||
expect(entryPoints).toEqual([]);
|
||||
@ -131,12 +132,13 @@ runInEachFileSystem(() => {
|
||||
...createPackage(
|
||||
fs.resolve(basePath, 'some-package/sub-entry-point-1'), 'sub-entry-point-2'),
|
||||
]);
|
||||
spyOn(config, 'getPackageConfig').and.returnValue({
|
||||
versionRange: '*',
|
||||
entryPoints: {
|
||||
[_Abs('/project/node_modules/some-package/sub-entry-point-1')]: {ignore: true},
|
||||
},
|
||||
});
|
||||
spyOn(config, 'getPackageConfig')
|
||||
.and.returnValue(
|
||||
new ProcessedNgccPackageConfig(_Abs('/project/node_modules/some-package'), {
|
||||
entryPoints: {
|
||||
'./sub-entry-point-1': {ignore: true},
|
||||
},
|
||||
}));
|
||||
|
||||
const {entryPoints} = finder.findEntryPoints();
|
||||
expect(dumpEntryPointPaths(basePath, entryPoints)).toEqual([
|
||||
|
@ -14,7 +14,7 @@ import {EsmDependencyHost} from '../../src/dependencies/esm_dependency_host';
|
||||
import {ModuleResolver} from '../../src/dependencies/module_resolver';
|
||||
import {TargetedEntryPointFinder} from '../../src/entry_point_finder/targeted_entry_point_finder';
|
||||
import {NGCC_VERSION} from '../../src/packages/build_marker';
|
||||
import {NgccConfiguration} from '../../src/packages/configuration';
|
||||
import {NgccConfiguration, ProcessedNgccPackageConfig} from '../../src/packages/configuration';
|
||||
import {EntryPoint} from '../../src/packages/entry_point';
|
||||
import {PathMappings} from '../../src/path_mappings';
|
||||
import {MockLogger} from '../helpers/mock_logger';
|
||||
@ -116,12 +116,13 @@ runInEachFileSystem(() => {
|
||||
fs, config, logger, resolver, basePath, undefined, targetPath);
|
||||
|
||||
loadTestFiles(createPackage(basePath, 'some-package'));
|
||||
spyOn(config, 'getPackageConfig').and.returnValue({
|
||||
versionRange: '*',
|
||||
entryPoints: {
|
||||
[_Abs('/project/node_modules/some-package')]: {ignore: true},
|
||||
},
|
||||
});
|
||||
spyOn(config, 'getPackageConfig')
|
||||
.and.returnValue(
|
||||
new ProcessedNgccPackageConfig(_Abs('/project/node_modules/some-package'), {
|
||||
entryPoints: {
|
||||
'.': {ignore: true},
|
||||
},
|
||||
}));
|
||||
|
||||
const {entryPoints} = finder.findEntryPoints();
|
||||
expect(entryPoints).toEqual([]);
|
||||
@ -416,12 +417,13 @@ runInEachFileSystem(() => {
|
||||
fs, config, logger, resolver, basePath, undefined, targetPath);
|
||||
|
||||
loadTestFiles(createPackage(basePath, 'some-package'));
|
||||
spyOn(config, 'getPackageConfig').and.returnValue({
|
||||
versionRange: '*',
|
||||
entryPoints: {
|
||||
[_Abs('/project/node_modules/some-package')]: {ignore: true},
|
||||
},
|
||||
});
|
||||
spyOn(config, 'getPackageConfig')
|
||||
.and.returnValue(
|
||||
new ProcessedNgccPackageConfig(_Abs('/project/node_modules/some-package'), {
|
||||
entryPoints: {
|
||||
'.': {ignore: true},
|
||||
},
|
||||
}));
|
||||
|
||||
expect(finder.targetNeedsProcessingOrCleaning(['fesm2015'], true)).toBe(false);
|
||||
});
|
||||
|
Reference in New Issue
Block a user