fix(ngcc): correctly get config for sub-entry-points when primary entry-point is ignored (#37040)

Previously, when an entry-point was ignored via an ngcc config, ngcc
would scan sub-directories for sub-entry-points, but would not use the
correct `packagePath`. For example, if `@angular/common` was ignored, it
would look at `@angular/common/http` but incorrectly use
`.../@angular/common/http` as the `packagePath` (instead of
`.../@angular/common`). As a result, it would not retrieve the correct
ngcc config for the actual package.

This commit fixes it by ensuring the correct `packagePath` is used, even
if the primary entry-point corresponding to that path is ignored. In
order to do this, a new return value for `getEntryPointInfo()` is added:
`IGNORED_ENTRY_POINT`. This is used to differentiate between directories
that correspond to no or an incompatible entry-point and those that
correspond to an entry-point that could otherwise be valid but is
explicitly ignored. Consumers of `getEntryPointInfo()` can then use this
info to discard ignored entry-points, but still use the correct
`packagePath` when scanning their sub-directories for secondary
entry-points.

PR Close #37040
This commit is contained in:
George Kalpakas
2020-06-08 22:04:25 +03:00
committed by Misko Hevery
parent ab9bc8a9ec
commit e7a0e87c41
11 changed files with 193 additions and 49 deletions

View File

@ -103,6 +103,48 @@ runInEachFileSystem(() => {
expect(entryPoints).toEqual([]);
});
it('should not include ignored entry-points', () => {
const basePath = _Abs('/project/node_modules');
const finder = new DirectoryWalkerEntryPointFinder(
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},
},
});
const {entryPoints} = finder.findEntryPoints();
expect(entryPoints).toEqual([]);
});
it('should look for sub-entry-points even if a containing entry-point is ignored', () => {
const basePath = _Abs('/project/node_modules');
const finder = new DirectoryWalkerEntryPointFinder(
fs, config, logger, resolver, manifest, basePath, undefined);
loadTestFiles([
...createPackage(basePath, 'some-package'),
...createPackage(fs.resolve(basePath, 'some-package'), 'sub-entry-point-1'),
...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},
},
});
const {entryPoints} = finder.findEntryPoints();
expect(dumpEntryPointPaths(basePath, entryPoints)).toEqual([
['some-package', 'some-package'],
['some-package', 'some-package/sub-entry-point-1/sub-entry-point-2'],
]);
});
it('should write an entry-point manifest file if none was found and basePath is `node_modules`',
() => {
const basePath = _Abs('/sub_entry_points/node_modules');

View File

@ -109,6 +109,24 @@ runInEachFileSystem(() => {
expect(entryPoints).toEqual([]);
});
it('should return an empty array if the target path is an ignored entry-point', () => {
const basePath = _Abs('/project/node_modules');
const targetPath = _Abs('/project/node_modules/some-package');
const finder = new TargetedEntryPointFinder(
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},
},
});
const {entryPoints} = finder.findEntryPoints();
expect(entryPoints).toEqual([]);
});
it('should return an empty array if the target path is not an Angular entry-point', () => {
const targetPath = _Abs('/no_valid_entry_points/node_modules/some_package');
loadTestFiles([
@ -390,6 +408,23 @@ runInEachFileSystem(() => {
expect(finder.targetNeedsProcessingOrCleaning(['fesm2015'], true)).toBe(false);
});
it('should return false if the target path is ignored by the config', () => {
const basePath = _Abs('/project/node_modules');
const targetPath = _Abs('/project/node_modules/some-package');
const finder = new TargetedEntryPointFinder(
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},
},
});
expect(finder.targetNeedsProcessingOrCleaning(['fesm2015'], true)).toBe(false);
});
it('should false if the target path has no typings', () => {
const targetPath = _Abs('/no_valid_entry_points/node_modules/some_package');
loadTestFiles([