diff --git a/packages/compiler-cli/ngcc/src/packages/entry_point_manifest.ts b/packages/compiler-cli/ngcc/src/packages/entry_point_manifest.ts index 8df1af7900..7cfdf8ca90 100644 --- a/packages/compiler-cli/ngcc/src/packages/entry_point_manifest.ts +++ b/packages/compiler-cli/ngcc/src/packages/entry_point_manifest.ts @@ -99,6 +99,10 @@ export class EntryPointManifest { * @param entryPoints A collection of entry-points to record in the manifest. */ writeEntryPointManifest(basePath: AbsoluteFsPath, entryPoints: EntryPoint[]): void { + if (this.fs.basename(basePath) !== 'node_modules') { + return; + } + const lockFileHash = this.computeLockFileHash(basePath); if (lockFileHash === null) { return; diff --git a/packages/compiler-cli/ngcc/test/entry_point_finder/directory_walker_entry_point_finder_spec.ts b/packages/compiler-cli/ngcc/test/entry_point_finder/directory_walker_entry_point_finder_spec.ts index 9eaf0499d6..386da54f37 100644 --- a/packages/compiler-cli/ngcc/test/entry_point_finder/directory_walker_entry_point_finder_spec.ts +++ b/packages/compiler-cli/ngcc/test/entry_point_finder/directory_walker_entry_point_finder_spec.ts @@ -103,15 +103,37 @@ runInEachFileSystem(() => { expect(entryPoints).toEqual([]); }); - it('should write an entry-point manifest file if none was found', () => { - const basePath = _Abs('/sub_entry_points/node_modules'); + 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'); + 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/node_modules/__ngcc_entry_points__.json'))) + .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: 'MOCM LOCK FILE'}, + {name: _Abs('/sub_entry_points/yarn.lock'), contents: 'MOCK LOCK FILE'}, ]); spyOn(manifest, 'readEntryPointsUsingManifest').and.callThrough(); spyOn(manifest, 'writeEntryPointManifest').and.callThrough(); @@ -120,8 +142,7 @@ runInEachFileSystem(() => { finder.findEntryPoints(); expect(manifest.readEntryPointsUsingManifest).toHaveBeenCalled(); expect(manifest.writeEntryPointManifest).toHaveBeenCalled(); - expect(fs.exists(_Abs('/sub_entry_points/node_modules/__ngcc_entry_points__.json'))) - .toBe(true); + 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', () => { @@ -132,7 +153,7 @@ runInEachFileSystem(() => { ...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: 'MOCM LOCK FILE'}, + {name: _Abs('/sub_entry_points/yarn.lock'), contents: 'MOCK LOCK FILE'}, ]); const finder = new DirectoryWalkerEntryPointFinder( fs, config, logger, resolver, manifest, basePath, undefined); diff --git a/packages/compiler-cli/ngcc/test/packages/entry_point_manifest_spec.ts b/packages/compiler-cli/ngcc/test/packages/entry_point_manifest_spec.ts index 928c32d901..b67eaa73c9 100644 --- a/packages/compiler-cli/ngcc/test/packages/entry_point_manifest_spec.ts +++ b/packages/compiler-cli/ngcc/test/packages/entry_point_manifest_spec.ts @@ -165,6 +165,12 @@ runInEachFileSystem(() => { 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', () => { fs.writeFile(_Abs('/project/yarn.lock'), 'LOCK FILE CONTENTS');