fix(ngcc): do not write entry-point manifest outside node_modules (#36299)
Fixes #36296 PR Close #36299
This commit is contained in:
parent
5ac308060d
commit
c6dd900f60
@ -99,6 +99,10 @@ export class EntryPointManifest {
|
|||||||
* @param entryPoints A collection of entry-points to record in the manifest.
|
* @param entryPoints A collection of entry-points to record in the manifest.
|
||||||
*/
|
*/
|
||||||
writeEntryPointManifest(basePath: AbsoluteFsPath, entryPoints: EntryPoint[]): void {
|
writeEntryPointManifest(basePath: AbsoluteFsPath, entryPoints: EntryPoint[]): void {
|
||||||
|
if (this.fs.basename(basePath) !== 'node_modules') {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const lockFileHash = this.computeLockFileHash(basePath);
|
const lockFileHash = this.computeLockFileHash(basePath);
|
||||||
if (lockFileHash === null) {
|
if (lockFileHash === null) {
|
||||||
return;
|
return;
|
||||||
|
@ -103,7 +103,8 @@ runInEachFileSystem(() => {
|
|||||||
expect(entryPoints).toEqual([]);
|
expect(entryPoints).toEqual([]);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should write an entry-point manifest file if none was found', () => {
|
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');
|
const basePath = _Abs('/sub_entry_points/node_modules');
|
||||||
loadTestFiles([
|
loadTestFiles([
|
||||||
...createPackage(basePath, 'common'),
|
...createPackage(basePath, 'common'),
|
||||||
@ -111,7 +112,7 @@ runInEachFileSystem(() => {
|
|||||||
...createPackage(
|
...createPackage(
|
||||||
fs.resolve(basePath, 'common/http'), 'testing', ['common/http', 'common/testing']),
|
fs.resolve(basePath, 'common/http'), 'testing', ['common/http', 'common/testing']),
|
||||||
...createPackage(fs.resolve(basePath, 'common'), 'testing', ['common']),
|
...createPackage(fs.resolve(basePath, 'common'), 'testing', ['common']),
|
||||||
{name: _Abs('/sub_entry_points/yarn.lock'), contents: 'MOCM LOCK FILE'},
|
{name: _Abs('/sub_entry_points/yarn.lock'), contents: 'MOCK LOCK FILE'},
|
||||||
]);
|
]);
|
||||||
spyOn(manifest, 'readEntryPointsUsingManifest').and.callThrough();
|
spyOn(manifest, 'readEntryPointsUsingManifest').and.callThrough();
|
||||||
spyOn(manifest, 'writeEntryPointManifest').and.callThrough();
|
spyOn(manifest, 'writeEntryPointManifest').and.callThrough();
|
||||||
@ -124,6 +125,26 @@ runInEachFileSystem(() => {
|
|||||||
.toBe(true);
|
.toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should not write an entry-point manifest file if basePath is not `node_modules`', () => {
|
||||||
|
const basePath = _Abs('/sub_entry_points/dist');
|
||||||
|
loadTestFiles([
|
||||||
|
...createPackage(basePath, 'common'),
|
||||||
|
...createPackage(fs.resolve(basePath, 'common'), 'http', ['common']),
|
||||||
|
...createPackage(
|
||||||
|
fs.resolve(basePath, 'common/http'), 'testing', ['common/http', 'common/testing']),
|
||||||
|
...createPackage(fs.resolve(basePath, 'common'), 'testing', ['common']),
|
||||||
|
{name: _Abs('/sub_entry_points/yarn.lock'), contents: 'MOCK LOCK FILE'},
|
||||||
|
]);
|
||||||
|
spyOn(manifest, 'readEntryPointsUsingManifest').and.callThrough();
|
||||||
|
spyOn(manifest, 'writeEntryPointManifest').and.callThrough();
|
||||||
|
const finder = new DirectoryWalkerEntryPointFinder(
|
||||||
|
fs, config, logger, resolver, manifest, basePath, undefined);
|
||||||
|
finder.findEntryPoints();
|
||||||
|
expect(manifest.readEntryPointsUsingManifest).toHaveBeenCalled();
|
||||||
|
expect(manifest.writeEntryPointManifest).toHaveBeenCalled();
|
||||||
|
expect(fs.exists(_Abs('/sub_entry_points/dist/__ngcc_entry_points__.json'))).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
it('should read from the entry-point manifest file if found', () => {
|
it('should read from the entry-point manifest file if found', () => {
|
||||||
const basePath = _Abs('/sub_entry_points/node_modules');
|
const basePath = _Abs('/sub_entry_points/node_modules');
|
||||||
loadTestFiles([
|
loadTestFiles([
|
||||||
@ -132,7 +153,7 @@ runInEachFileSystem(() => {
|
|||||||
...createPackage(
|
...createPackage(
|
||||||
fs.resolve(basePath, 'common/http'), 'testing', ['common/http', 'common/testing']),
|
fs.resolve(basePath, 'common/http'), 'testing', ['common/http', 'common/testing']),
|
||||||
...createPackage(fs.resolve(basePath, 'common'), 'testing', ['common']),
|
...createPackage(fs.resolve(basePath, 'common'), 'testing', ['common']),
|
||||||
{name: _Abs('/sub_entry_points/yarn.lock'), contents: 'MOCM LOCK FILE'},
|
{name: _Abs('/sub_entry_points/yarn.lock'), contents: 'MOCK LOCK FILE'},
|
||||||
]);
|
]);
|
||||||
const finder = new DirectoryWalkerEntryPointFinder(
|
const finder = new DirectoryWalkerEntryPointFinder(
|
||||||
fs, config, logger, resolver, manifest, basePath, undefined);
|
fs, config, logger, resolver, manifest, basePath, undefined);
|
||||||
|
@ -165,6 +165,12 @@ runInEachFileSystem(() => {
|
|||||||
expect(fs.exists(_Abs('/project/node_modules/__ngcc_entry_points__.json'))).toBe(false);
|
expect(fs.exists(_Abs('/project/node_modules/__ngcc_entry_points__.json'))).toBe(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should do nothing if the basePath is not node_modules', () => {
|
||||||
|
fs.writeFile(_Abs('/project/yarn.lock'), 'LOCK FILE CONTENTS');
|
||||||
|
manifest.writeEntryPointManifest(_Abs('/project/dist'), []);
|
||||||
|
expect(fs.exists(_Abs('/project/dist/__ngcc_entry_points__.json'))).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
it('should write an __ngcc_entry_points__.json file below the base path if there is a yarn.lock file',
|
it('should write an __ngcc_entry_points__.json file below the base path if there is a yarn.lock file',
|
||||||
() => {
|
() => {
|
||||||
fs.writeFile(_Abs('/project/yarn.lock'), 'LOCK FILE CONTENTS');
|
fs.writeFile(_Abs('/project/yarn.lock'), 'LOCK FILE CONTENTS');
|
||||||
|
Loading…
x
Reference in New Issue
Block a user