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:
George Kalpakas
2020-06-08 22:04:38 +03:00
committed by Misko Hevery
parent 8f3695e20e
commit bf682d73d4
9 changed files with 541 additions and 320 deletions

View File

@ -280,7 +280,7 @@ runInEachFileSystem(() => {
it('should not log a warning for ignored deep imports', () => {
spyOn(host, 'collectDependencies').and.callFake(createFakeComputeDependencies({
[_('/project/node_modules/test-package/index.js')]: {
[_('/project/node_modules/test-package/test-entry-point/index.js')]: {
resolved: [],
missing: [],
deepImports: [
@ -290,7 +290,10 @@ runInEachFileSystem(() => {
},
}));
spyOn(dtsHost, 'collectDependencies').and.callFake(createFakeComputeDependencies({
[_('/project/node_modules/test-package/index.d.ts')]: {resolved: [], missing: []},
[_('/project/node_modules/test-package/test-entry-point/index.d.ts')]: {
resolved: [],
missing: [],
},
}));
// Setup the configuration to ignore deep imports that contain either "deep/" or "two".
fs.ensureDir(_('/project'));
@ -300,12 +303,12 @@ runInEachFileSystem(() => {
config = new NgccConfiguration(fs, _('/project'));
resolver = new DependencyResolver(fs, logger, config, {esm5: host, esm2015: host}, dtsHost);
const testEntryPoint = {
name: 'test-package',
path: _('/project/node_modules/test-package'),
name: 'test-package/test-entry-point',
path: _('/project/node_modules/test-package/test-entry-point'),
packageName: 'test-package',
packagePath: _('/project/node_modules/test-package'),
packageJson: {esm5: './index.js'},
typings: _('/project/node_modules/test-package/index.d.ts'),
typings: _('/project/node_modules/test-package/test-entry-point/index.d.ts'),
compiledByAngular: true,
ignoreMissingDependencies: false,
} as EntryPoint;
@ -314,7 +317,7 @@ runInEachFileSystem(() => {
getEntryPointsWithDeps(resolver, [testEntryPoint]));
expect(result.entryPoints).toEqual([testEntryPoint]);
expect(logger.logs.warn).toEqual([[
`Entry point 'test-package' contains deep imports into '${
`Entry point 'test-package/test-entry-point' contains deep imports into '${
_('/project/node_modules/deeper/one')}'. This is probably not a problem, but may cause the compilation of entry points to be out of order.`
]]);
});