From 93d27eefd58c28967433eb509ef55e5671c4e467 Mon Sep 17 00:00:00 2001 From: George Kalpakas Date: Thu, 8 Aug 2019 02:35:22 +0300 Subject: [PATCH] refactor(ivy): ngcc - remove redundant `entryPoint` argument from `writeBundle()` (#32052) The entry-point is already available through the `bundle` argument, so passing it separately is redundant. PR Close #32052 --- packages/compiler-cli/ngcc/src/main.ts | 2 +- .../ngcc/src/writing/file_writer.ts | 4 +-- .../ngcc/src/writing/in_place_file_writer.ts | 4 +-- .../writing/new_entry_point_file_writer.ts | 3 +- .../test/writing/in_place_file_writer_spec.ts | 10 ++---- .../new_entry_point_file_writer_spec.ts | 34 +++++++++---------- 6 files changed, 27 insertions(+), 30 deletions(-) diff --git a/packages/compiler-cli/ngcc/src/main.ts b/packages/compiler-cli/ngcc/src/main.ts index 5cd785f15f..0f71551d28 100644 --- a/packages/compiler-cli/ngcc/src/main.ts +++ b/packages/compiler-cli/ngcc/src/main.ts @@ -171,7 +171,7 @@ export function mainNgcc( logger.info(`Compiling ${entryPoint.name} : ${formatProperty} as ${format}`); const transformedFiles = transformer.transform(bundle); - fileWriter.writeBundle(entryPoint, bundle, transformedFiles, formatProperty); + fileWriter.writeBundle(bundle, transformedFiles, formatProperty); onTaskCompleted(task, TaskProcessingOutcome.Processed); }; diff --git a/packages/compiler-cli/ngcc/src/writing/file_writer.ts b/packages/compiler-cli/ngcc/src/writing/file_writer.ts index 093b8ba6cd..319dd85e2c 100644 --- a/packages/compiler-cli/ngcc/src/writing/file_writer.ts +++ b/packages/compiler-cli/ngcc/src/writing/file_writer.ts @@ -6,7 +6,7 @@ * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file at https://angular.io/license */ -import {EntryPoint, EntryPointJsonProperty} from '../packages/entry_point'; +import {EntryPointJsonProperty} from '../packages/entry_point'; import {EntryPointBundle} from '../packages/entry_point_bundle'; import {FileToWrite} from '../rendering/utils'; @@ -15,6 +15,6 @@ import {FileToWrite} from '../rendering/utils'; */ export interface FileWriter { writeBundle( - entryPoint: EntryPoint, bundle: EntryPointBundle, transformedFiles: FileToWrite[], + bundle: EntryPointBundle, transformedFiles: FileToWrite[], formatProperty: EntryPointJsonProperty): void; } diff --git a/packages/compiler-cli/ngcc/src/writing/in_place_file_writer.ts b/packages/compiler-cli/ngcc/src/writing/in_place_file_writer.ts index ea3639b84b..a75946a898 100644 --- a/packages/compiler-cli/ngcc/src/writing/in_place_file_writer.ts +++ b/packages/compiler-cli/ngcc/src/writing/in_place_file_writer.ts @@ -7,7 +7,7 @@ * found in the LICENSE file at https://angular.io/license */ import {FileSystem, absoluteFrom, dirname} from '../../../src/ngtsc/file_system'; -import {EntryPoint, EntryPointJsonProperty} from '../packages/entry_point'; +import {EntryPointJsonProperty} from '../packages/entry_point'; import {EntryPointBundle} from '../packages/entry_point_bundle'; import {FileToWrite} from '../rendering/utils'; import {FileWriter} from './file_writer'; @@ -20,7 +20,7 @@ export class InPlaceFileWriter implements FileWriter { constructor(protected fs: FileSystem) {} writeBundle( - _entryPoint: EntryPoint, _bundle: EntryPointBundle, transformedFiles: FileToWrite[], + _bundle: EntryPointBundle, transformedFiles: FileToWrite[], _formatProperty?: EntryPointJsonProperty) { transformedFiles.forEach(file => this.writeFileAndBackup(file)); } diff --git a/packages/compiler-cli/ngcc/src/writing/new_entry_point_file_writer.ts b/packages/compiler-cli/ngcc/src/writing/new_entry_point_file_writer.ts index 7f548c41e7..b833b06620 100644 --- a/packages/compiler-cli/ngcc/src/writing/new_entry_point_file_writer.ts +++ b/packages/compiler-cli/ngcc/src/writing/new_entry_point_file_writer.ts @@ -26,9 +26,10 @@ const NGCC_DIRECTORY = '__ivy_ngcc__'; */ export class NewEntryPointFileWriter extends InPlaceFileWriter { writeBundle( - entryPoint: EntryPoint, bundle: EntryPointBundle, transformedFiles: FileToWrite[], + bundle: EntryPointBundle, transformedFiles: FileToWrite[], formatProperty: EntryPointJsonProperty) { // The new folder is at the root of the overall package + const entryPoint = bundle.entryPoint; const ngccFolder = join(entryPoint.package, NGCC_DIRECTORY); this.copyBundle(bundle, entryPoint.package, ngccFolder); transformedFiles.forEach(file => this.writeFile(file, entryPoint.package, ngccFolder)); diff --git a/packages/compiler-cli/ngcc/test/writing/in_place_file_writer_spec.ts b/packages/compiler-cli/ngcc/test/writing/in_place_file_writer_spec.ts index b86f10fe95..646f2f9bb1 100644 --- a/packages/compiler-cli/ngcc/test/writing/in_place_file_writer_spec.ts +++ b/packages/compiler-cli/ngcc/test/writing/in_place_file_writer_spec.ts @@ -8,7 +8,6 @@ import {absoluteFrom, getFileSystem} from '../../../src/ngtsc/file_system'; import {runInEachFileSystem} from '../../../src/ngtsc/file_system/testing'; import {loadTestFiles} from '../../../test/helpers'; -import {EntryPoint} from '../../src/packages/entry_point'; import {EntryPointBundle} from '../../src/packages/entry_point_bundle'; import {InPlaceFileWriter} from '../../src/writing/in_place_file_writer'; @@ -32,7 +31,7 @@ runInEachFileSystem(() => { it('should write all the FileInfo to the disk', () => { const fs = getFileSystem(); const fileWriter = new InPlaceFileWriter(fs); - fileWriter.writeBundle({} as EntryPoint, {} as EntryPointBundle, [ + fileWriter.writeBundle({} as EntryPointBundle, [ {path: _('/package/path/top-level.js'), contents: 'MODIFIED TOP LEVEL'}, {path: _('/package/path/folder-1/file-1.js'), contents: 'MODIFIED FILE 1'}, {path: _('/package/path/folder-2/file-4.js'), contents: 'MODIFIED FILE 4'}, @@ -49,7 +48,7 @@ runInEachFileSystem(() => { it('should create backups of all files that previously existed', () => { const fs = getFileSystem(); const fileWriter = new InPlaceFileWriter(fs); - fileWriter.writeBundle({} as EntryPoint, {} as EntryPointBundle, [ + fileWriter.writeBundle({} as EntryPointBundle, [ {path: _('/package/path/top-level.js'), contents: 'MODIFIED TOP LEVEL'}, {path: _('/package/path/folder-1/file-1.js'), contents: 'MODIFIED FILE 1'}, {path: _('/package/path/folder-2/file-4.js'), contents: 'MODIFIED FILE 4'}, @@ -72,10 +71,7 @@ runInEachFileSystem(() => { const absoluteBackupPath = _('/package/path/already-backed-up.js'); expect( () => fileWriter.writeBundle( - {} as EntryPoint, {} as EntryPointBundle, - [ - {path: absoluteBackupPath, contents: 'MODIFIED BACKED UP'}, - ])) + {} as EntryPointBundle, [{path: absoluteBackupPath, contents: 'MODIFIED BACKED UP'}])) .toThrowError( `Tried to overwrite ${absoluteBackupPath}.__ivy_ngcc_bak with an ngcc back up file, which is disallowed.`); }); diff --git a/packages/compiler-cli/ngcc/test/writing/new_entry_point_file_writer_spec.ts b/packages/compiler-cli/ngcc/test/writing/new_entry_point_file_writer_spec.ts index a3be2d0ee7..e45e3f7c86 100644 --- a/packages/compiler-cli/ngcc/test/writing/new_entry_point_file_writer_spec.ts +++ b/packages/compiler-cli/ngcc/test/writing/new_entry_point_file_writer_spec.ts @@ -96,7 +96,7 @@ runInEachFileSystem(() => { it('should write the modified files to a new folder', () => { fileWriter.writeBundle( - entryPoint, esm5bundle, + esm5bundle, [ { path: _('/node_modules/test/esm5.js'), @@ -115,7 +115,7 @@ runInEachFileSystem(() => { it('should also copy unmodified files in the program', () => { fileWriter.writeBundle( - entryPoint, esm2015bundle, + esm2015bundle, [ { path: _('/node_modules/test/es2015/foo.js'), @@ -135,7 +135,7 @@ runInEachFileSystem(() => { it('should update the package.json properties', () => { fileWriter.writeBundle( - entryPoint, esm5bundle, + esm5bundle, [ { path: _('/node_modules/test/esm5.js'), @@ -148,7 +148,7 @@ runInEachFileSystem(() => { })); fileWriter.writeBundle( - entryPoint, esm2015bundle, + esm2015bundle, [ { path: _('/node_modules/test/es2015/foo.js'), @@ -164,7 +164,7 @@ runInEachFileSystem(() => { it('should overwrite and backup typings files', () => { fileWriter.writeBundle( - entryPoint, esm2015bundle, + esm2015bundle, [ { path: _('/node_modules/test/index.d.ts'), @@ -200,7 +200,7 @@ runInEachFileSystem(() => { it('should write the modified file to a new folder', () => { fileWriter.writeBundle( - entryPoint, esm5bundle, + esm5bundle, [ { path: _('/node_modules/test/a/esm5.js'), @@ -215,7 +215,7 @@ runInEachFileSystem(() => { it('should also copy unmodified files in the program', () => { fileWriter.writeBundle( - entryPoint, esm2015bundle, + esm2015bundle, [ { path: _('/node_modules/test/a/es2015/foo.js'), @@ -235,7 +235,7 @@ runInEachFileSystem(() => { it('should update the package.json properties', () => { fileWriter.writeBundle( - entryPoint, esm5bundle, + esm5bundle, [ { path: _('/node_modules/test/a/esm5.js'), @@ -248,7 +248,7 @@ runInEachFileSystem(() => { })); fileWriter.writeBundle( - entryPoint, esm2015bundle, + esm2015bundle, [ { path: _('/node_modules/test/a/es2015/foo.js'), @@ -264,7 +264,7 @@ runInEachFileSystem(() => { it('should overwrite and backup typings files', () => { fileWriter.writeBundle( - entryPoint, esm2015bundle, + esm2015bundle, [ { path: _('/node_modules/test/a/index.d.ts'), @@ -293,7 +293,7 @@ runInEachFileSystem(() => { it('should write the modified file to a new folder', () => { fileWriter.writeBundle( - entryPoint, esm5bundle, + esm5bundle, [ { path: _('/node_modules/test/lib/esm5.js'), @@ -309,7 +309,7 @@ runInEachFileSystem(() => { it('should also copy unmodified files in the program', () => { fileWriter.writeBundle( - entryPoint, esm2015bundle, + esm2015bundle, [ { path: _('/node_modules/test/lib/es2015/foo.js'), @@ -330,7 +330,7 @@ runInEachFileSystem(() => { it('should not copy typings files within the package (i.e. from a different entry-point)', () => { fileWriter.writeBundle( - entryPoint, esm2015bundle, + esm2015bundle, [ { path: _('/node_modules/test/lib/es2015/foo.js'), @@ -343,7 +343,7 @@ runInEachFileSystem(() => { it('should not copy files outside of the package', () => { fileWriter.writeBundle( - entryPoint, esm2015bundle, + esm2015bundle, [ { path: _('/node_modules/test/lib/es2015/foo.js'), @@ -357,7 +357,7 @@ runInEachFileSystem(() => { it('should update the package.json properties', () => { fileWriter.writeBundle( - entryPoint, esm5bundle, + esm5bundle, [ { path: _('/node_modules/test/lib/esm5.js'), @@ -370,7 +370,7 @@ runInEachFileSystem(() => { })); fileWriter.writeBundle( - entryPoint, esm2015bundle, + esm2015bundle, [ { path: _('/node_modules/test/lib/es2015/foo.js'), @@ -386,7 +386,7 @@ runInEachFileSystem(() => { it('should overwrite and backup typings files', () => { fileWriter.writeBundle( - entryPoint, esm2015bundle, + esm2015bundle, [ { path: _('/node_modules/test/typings/index.d.ts'),