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:

committed by
Misko Hevery

parent
ab9bc8a9ec
commit
e7a0e87c41
@ -185,6 +185,53 @@ runInEachFileSystem(() => {
|
||||
const entryPoints = manifest.readEntryPointsUsingManifest(_Abs('/project/node_modules'));
|
||||
expect(entryPoints).toEqual(null);
|
||||
});
|
||||
|
||||
it('should return null if any of the entry-points are ignored by a config', () => {
|
||||
fs.ensureDir(_Abs('/project/node_modules'));
|
||||
fs.writeFile(_Abs('/project/yarn.lock'), 'LOCK FILE CONTENTS');
|
||||
loadTestFiles([
|
||||
{
|
||||
name: _Abs('/project/node_modules/some_package/valid_entry_point/package.json'),
|
||||
contents: createPackageJson('valid_entry_point'),
|
||||
},
|
||||
{
|
||||
name: _Abs(
|
||||
'/project/node_modules/some_package/valid_entry_point/valid_entry_point.metadata.json'),
|
||||
contents: 'some meta data',
|
||||
},
|
||||
{
|
||||
name: _Abs('/project/node_modules/some_package/ignored_entry_point/package.json'),
|
||||
contents: createPackageJson('ignored_entry_point'),
|
||||
},
|
||||
{
|
||||
name: _Abs(
|
||||
'/project/node_modules/some_package/ignored_entry_point/ignored_entry_point.metadata.json'),
|
||||
contents: 'some meta data',
|
||||
},
|
||||
]);
|
||||
manifestFile.entryPointPaths.push(
|
||||
[
|
||||
_Abs('/project/node_modules/some_package'),
|
||||
_Abs('/project/node_modules/some_package/valid_entry_point'), [], [], []
|
||||
],
|
||||
[
|
||||
_Abs('/project/node_modules/some_package'),
|
||||
_Abs('/project/node_modules/some_package/ignored_entry_point'), [], [], []
|
||||
],
|
||||
);
|
||||
fs.writeFile(
|
||||
_Abs('/project/node_modules/__ngcc_entry_points__.json'), JSON.stringify(manifestFile));
|
||||
|
||||
spyOn(config, 'getPackageConfig').and.returnValue({
|
||||
versionRange: '*',
|
||||
entryPoints: {
|
||||
[_Abs('/project/node_modules/some_package/ignored_entry_point')]: {ignore: true},
|
||||
},
|
||||
});
|
||||
|
||||
const entryPoints = manifest.readEntryPointsUsingManifest(_Abs('/project/node_modules'));
|
||||
expect(entryPoints).toEqual(null);
|
||||
});
|
||||
});
|
||||
|
||||
describe('writeEntryPointManifest()', () => {
|
||||
|
@ -10,7 +10,7 @@ import {absoluteFrom, AbsoluteFsPath, FileSystem, getFileSystem} from '../../../
|
||||
import {runInEachFileSystem} from '../../../src/ngtsc/file_system/testing';
|
||||
import {loadTestFiles} from '../../../test/helpers';
|
||||
import {NgccConfiguration} from '../../src/packages/configuration';
|
||||
import {EntryPoint, EntryPointJsonProperty, getEntryPointFormat, getEntryPointInfo, INCOMPATIBLE_ENTRY_POINT, NO_ENTRY_POINT, SUPPORTED_FORMAT_PROPERTIES} from '../../src/packages/entry_point';
|
||||
import {EntryPoint, EntryPointJsonProperty, getEntryPointFormat, getEntryPointInfo, IGNORED_ENTRY_POINT, INCOMPATIBLE_ENTRY_POINT, isEntryPoint, NO_ENTRY_POINT, SUPPORTED_FORMAT_PROPERTIES} from '../../src/packages/entry_point';
|
||||
import {MockLogger} from '../helpers/mock_logger';
|
||||
|
||||
runInEachFileSystem(() => {
|
||||
@ -55,7 +55,7 @@ runInEachFileSystem(() => {
|
||||
});
|
||||
});
|
||||
|
||||
it('should return `NO_ENTRY_POINT` if configured to ignore the specified entry-point', () => {
|
||||
it('should return `IGNORED_ENTRY_POINT` if configured to ignore the specified entry-point', () => {
|
||||
loadTestFiles([
|
||||
{
|
||||
name: _('/project/node_modules/some_package/valid_entry_point/package.json'),
|
||||
@ -74,7 +74,7 @@ runInEachFileSystem(() => {
|
||||
const entryPoint = getEntryPointInfo(
|
||||
fs, config, new MockLogger(), SOME_PACKAGE,
|
||||
_('/project/node_modules/some_package/valid_entry_point'));
|
||||
expect(entryPoint).toBe(NO_ENTRY_POINT);
|
||||
expect(entryPoint).toBe(IGNORED_ENTRY_POINT);
|
||||
});
|
||||
|
||||
it('should override the properties on package.json if the entry-point is configured', () => {
|
||||
@ -381,7 +381,7 @@ runInEachFileSystem(() => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('getEntryPointFormat', () => {
|
||||
describe('getEntryPointFormat()', () => {
|
||||
let SOME_PACKAGE: AbsoluteFsPath;
|
||||
let _: typeof absoluteFrom;
|
||||
let fs: FileSystem;
|
||||
@ -399,10 +399,10 @@ runInEachFileSystem(() => {
|
||||
const result = getEntryPointInfo(
|
||||
fs, config, new MockLogger(), SOME_PACKAGE,
|
||||
_('/project/node_modules/some_package/valid_entry_point'));
|
||||
if (result === NO_ENTRY_POINT || result === INCOMPATIBLE_ENTRY_POINT) {
|
||||
if (!isEntryPoint(result)) {
|
||||
return fail(`Expected an entry point but got ${result}`);
|
||||
}
|
||||
entryPoint = result as any;
|
||||
entryPoint = result;
|
||||
});
|
||||
|
||||
it('should return `esm2015` format for `fesm2015` property', () => {
|
||||
|
Reference in New Issue
Block a user