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
This commit is contained in:
George Kalpakas 2019-08-08 02:35:22 +03:00 committed by Alex Rickabaugh
parent ed70f73794
commit 93d27eefd5
6 changed files with 27 additions and 30 deletions

View File

@ -171,7 +171,7 @@ export function mainNgcc(
logger.info(`Compiling ${entryPoint.name} : ${formatProperty} as ${format}`); logger.info(`Compiling ${entryPoint.name} : ${formatProperty} as ${format}`);
const transformedFiles = transformer.transform(bundle); const transformedFiles = transformer.transform(bundle);
fileWriter.writeBundle(entryPoint, bundle, transformedFiles, formatProperty); fileWriter.writeBundle(bundle, transformedFiles, formatProperty);
onTaskCompleted(task, TaskProcessingOutcome.Processed); onTaskCompleted(task, TaskProcessingOutcome.Processed);
}; };

View File

@ -6,7 +6,7 @@
* Use of this source code is governed by an MIT-style license that can be * 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 * 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 {EntryPointBundle} from '../packages/entry_point_bundle';
import {FileToWrite} from '../rendering/utils'; import {FileToWrite} from '../rendering/utils';
@ -15,6 +15,6 @@ import {FileToWrite} from '../rendering/utils';
*/ */
export interface FileWriter { export interface FileWriter {
writeBundle( writeBundle(
entryPoint: EntryPoint, bundle: EntryPointBundle, transformedFiles: FileToWrite[], bundle: EntryPointBundle, transformedFiles: FileToWrite[],
formatProperty: EntryPointJsonProperty): void; formatProperty: EntryPointJsonProperty): void;
} }

View File

@ -7,7 +7,7 @@
* found in the LICENSE file at https://angular.io/license * found in the LICENSE file at https://angular.io/license
*/ */
import {FileSystem, absoluteFrom, dirname} from '../../../src/ngtsc/file_system'; 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 {EntryPointBundle} from '../packages/entry_point_bundle';
import {FileToWrite} from '../rendering/utils'; import {FileToWrite} from '../rendering/utils';
import {FileWriter} from './file_writer'; import {FileWriter} from './file_writer';
@ -20,7 +20,7 @@ export class InPlaceFileWriter implements FileWriter {
constructor(protected fs: FileSystem) {} constructor(protected fs: FileSystem) {}
writeBundle( writeBundle(
_entryPoint: EntryPoint, _bundle: EntryPointBundle, transformedFiles: FileToWrite[], _bundle: EntryPointBundle, transformedFiles: FileToWrite[],
_formatProperty?: EntryPointJsonProperty) { _formatProperty?: EntryPointJsonProperty) {
transformedFiles.forEach(file => this.writeFileAndBackup(file)); transformedFiles.forEach(file => this.writeFileAndBackup(file));
} }

View File

@ -26,9 +26,10 @@ const NGCC_DIRECTORY = '__ivy_ngcc__';
*/ */
export class NewEntryPointFileWriter extends InPlaceFileWriter { export class NewEntryPointFileWriter extends InPlaceFileWriter {
writeBundle( writeBundle(
entryPoint: EntryPoint, bundle: EntryPointBundle, transformedFiles: FileToWrite[], bundle: EntryPointBundle, transformedFiles: FileToWrite[],
formatProperty: EntryPointJsonProperty) { formatProperty: EntryPointJsonProperty) {
// The new folder is at the root of the overall package // The new folder is at the root of the overall package
const entryPoint = bundle.entryPoint;
const ngccFolder = join(entryPoint.package, NGCC_DIRECTORY); const ngccFolder = join(entryPoint.package, NGCC_DIRECTORY);
this.copyBundle(bundle, entryPoint.package, ngccFolder); this.copyBundle(bundle, entryPoint.package, ngccFolder);
transformedFiles.forEach(file => this.writeFile(file, entryPoint.package, ngccFolder)); transformedFiles.forEach(file => this.writeFile(file, entryPoint.package, ngccFolder));

View File

@ -8,7 +8,6 @@
import {absoluteFrom, getFileSystem} from '../../../src/ngtsc/file_system'; import {absoluteFrom, getFileSystem} from '../../../src/ngtsc/file_system';
import {runInEachFileSystem} from '../../../src/ngtsc/file_system/testing'; import {runInEachFileSystem} from '../../../src/ngtsc/file_system/testing';
import {loadTestFiles} from '../../../test/helpers'; import {loadTestFiles} from '../../../test/helpers';
import {EntryPoint} from '../../src/packages/entry_point';
import {EntryPointBundle} from '../../src/packages/entry_point_bundle'; import {EntryPointBundle} from '../../src/packages/entry_point_bundle';
import {InPlaceFileWriter} from '../../src/writing/in_place_file_writer'; import {InPlaceFileWriter} from '../../src/writing/in_place_file_writer';
@ -32,7 +31,7 @@ runInEachFileSystem(() => {
it('should write all the FileInfo to the disk', () => { it('should write all the FileInfo to the disk', () => {
const fs = getFileSystem(); const fs = getFileSystem();
const fileWriter = new InPlaceFileWriter(fs); 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/top-level.js'), contents: 'MODIFIED TOP LEVEL'},
{path: _('/package/path/folder-1/file-1.js'), contents: 'MODIFIED FILE 1'}, {path: _('/package/path/folder-1/file-1.js'), contents: 'MODIFIED FILE 1'},
{path: _('/package/path/folder-2/file-4.js'), contents: 'MODIFIED FILE 4'}, {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', () => { it('should create backups of all files that previously existed', () => {
const fs = getFileSystem(); const fs = getFileSystem();
const fileWriter = new InPlaceFileWriter(fs); 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/top-level.js'), contents: 'MODIFIED TOP LEVEL'},
{path: _('/package/path/folder-1/file-1.js'), contents: 'MODIFIED FILE 1'}, {path: _('/package/path/folder-1/file-1.js'), contents: 'MODIFIED FILE 1'},
{path: _('/package/path/folder-2/file-4.js'), contents: 'MODIFIED FILE 4'}, {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'); const absoluteBackupPath = _('/package/path/already-backed-up.js');
expect( expect(
() => fileWriter.writeBundle( () => fileWriter.writeBundle(
{} as EntryPoint, {} as EntryPointBundle, {} as EntryPointBundle, [{path: absoluteBackupPath, contents: 'MODIFIED BACKED UP'}]))
[
{path: absoluteBackupPath, contents: 'MODIFIED BACKED UP'},
]))
.toThrowError( .toThrowError(
`Tried to overwrite ${absoluteBackupPath}.__ivy_ngcc_bak with an ngcc back up file, which is disallowed.`); `Tried to overwrite ${absoluteBackupPath}.__ivy_ngcc_bak with an ngcc back up file, which is disallowed.`);
}); });

View File

@ -96,7 +96,7 @@ runInEachFileSystem(() => {
it('should write the modified files to a new folder', () => { it('should write the modified files to a new folder', () => {
fileWriter.writeBundle( fileWriter.writeBundle(
entryPoint, esm5bundle, esm5bundle,
[ [
{ {
path: _('/node_modules/test/esm5.js'), path: _('/node_modules/test/esm5.js'),
@ -115,7 +115,7 @@ runInEachFileSystem(() => {
it('should also copy unmodified files in the program', () => { it('should also copy unmodified files in the program', () => {
fileWriter.writeBundle( fileWriter.writeBundle(
entryPoint, esm2015bundle, esm2015bundle,
[ [
{ {
path: _('/node_modules/test/es2015/foo.js'), path: _('/node_modules/test/es2015/foo.js'),
@ -135,7 +135,7 @@ runInEachFileSystem(() => {
it('should update the package.json properties', () => { it('should update the package.json properties', () => {
fileWriter.writeBundle( fileWriter.writeBundle(
entryPoint, esm5bundle, esm5bundle,
[ [
{ {
path: _('/node_modules/test/esm5.js'), path: _('/node_modules/test/esm5.js'),
@ -148,7 +148,7 @@ runInEachFileSystem(() => {
})); }));
fileWriter.writeBundle( fileWriter.writeBundle(
entryPoint, esm2015bundle, esm2015bundle,
[ [
{ {
path: _('/node_modules/test/es2015/foo.js'), path: _('/node_modules/test/es2015/foo.js'),
@ -164,7 +164,7 @@ runInEachFileSystem(() => {
it('should overwrite and backup typings files', () => { it('should overwrite and backup typings files', () => {
fileWriter.writeBundle( fileWriter.writeBundle(
entryPoint, esm2015bundle, esm2015bundle,
[ [
{ {
path: _('/node_modules/test/index.d.ts'), path: _('/node_modules/test/index.d.ts'),
@ -200,7 +200,7 @@ runInEachFileSystem(() => {
it('should write the modified file to a new folder', () => { it('should write the modified file to a new folder', () => {
fileWriter.writeBundle( fileWriter.writeBundle(
entryPoint, esm5bundle, esm5bundle,
[ [
{ {
path: _('/node_modules/test/a/esm5.js'), path: _('/node_modules/test/a/esm5.js'),
@ -215,7 +215,7 @@ runInEachFileSystem(() => {
it('should also copy unmodified files in the program', () => { it('should also copy unmodified files in the program', () => {
fileWriter.writeBundle( fileWriter.writeBundle(
entryPoint, esm2015bundle, esm2015bundle,
[ [
{ {
path: _('/node_modules/test/a/es2015/foo.js'), path: _('/node_modules/test/a/es2015/foo.js'),
@ -235,7 +235,7 @@ runInEachFileSystem(() => {
it('should update the package.json properties', () => { it('should update the package.json properties', () => {
fileWriter.writeBundle( fileWriter.writeBundle(
entryPoint, esm5bundle, esm5bundle,
[ [
{ {
path: _('/node_modules/test/a/esm5.js'), path: _('/node_modules/test/a/esm5.js'),
@ -248,7 +248,7 @@ runInEachFileSystem(() => {
})); }));
fileWriter.writeBundle( fileWriter.writeBundle(
entryPoint, esm2015bundle, esm2015bundle,
[ [
{ {
path: _('/node_modules/test/a/es2015/foo.js'), path: _('/node_modules/test/a/es2015/foo.js'),
@ -264,7 +264,7 @@ runInEachFileSystem(() => {
it('should overwrite and backup typings files', () => { it('should overwrite and backup typings files', () => {
fileWriter.writeBundle( fileWriter.writeBundle(
entryPoint, esm2015bundle, esm2015bundle,
[ [
{ {
path: _('/node_modules/test/a/index.d.ts'), path: _('/node_modules/test/a/index.d.ts'),
@ -293,7 +293,7 @@ runInEachFileSystem(() => {
it('should write the modified file to a new folder', () => { it('should write the modified file to a new folder', () => {
fileWriter.writeBundle( fileWriter.writeBundle(
entryPoint, esm5bundle, esm5bundle,
[ [
{ {
path: _('/node_modules/test/lib/esm5.js'), path: _('/node_modules/test/lib/esm5.js'),
@ -309,7 +309,7 @@ runInEachFileSystem(() => {
it('should also copy unmodified files in the program', () => { it('should also copy unmodified files in the program', () => {
fileWriter.writeBundle( fileWriter.writeBundle(
entryPoint, esm2015bundle, esm2015bundle,
[ [
{ {
path: _('/node_modules/test/lib/es2015/foo.js'), 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)', it('should not copy typings files within the package (i.e. from a different entry-point)',
() => { () => {
fileWriter.writeBundle( fileWriter.writeBundle(
entryPoint, esm2015bundle, esm2015bundle,
[ [
{ {
path: _('/node_modules/test/lib/es2015/foo.js'), path: _('/node_modules/test/lib/es2015/foo.js'),
@ -343,7 +343,7 @@ runInEachFileSystem(() => {
it('should not copy files outside of the package', () => { it('should not copy files outside of the package', () => {
fileWriter.writeBundle( fileWriter.writeBundle(
entryPoint, esm2015bundle, esm2015bundle,
[ [
{ {
path: _('/node_modules/test/lib/es2015/foo.js'), path: _('/node_modules/test/lib/es2015/foo.js'),
@ -357,7 +357,7 @@ runInEachFileSystem(() => {
it('should update the package.json properties', () => { it('should update the package.json properties', () => {
fileWriter.writeBundle( fileWriter.writeBundle(
entryPoint, esm5bundle, esm5bundle,
[ [
{ {
path: _('/node_modules/test/lib/esm5.js'), path: _('/node_modules/test/lib/esm5.js'),
@ -370,7 +370,7 @@ runInEachFileSystem(() => {
})); }));
fileWriter.writeBundle( fileWriter.writeBundle(
entryPoint, esm2015bundle, esm2015bundle,
[ [
{ {
path: _('/node_modules/test/lib/es2015/foo.js'), path: _('/node_modules/test/lib/es2015/foo.js'),
@ -386,7 +386,7 @@ runInEachFileSystem(() => {
it('should overwrite and backup typings files', () => { it('should overwrite and backup typings files', () => {
fileWriter.writeBundle( fileWriter.writeBundle(
entryPoint, esm2015bundle, esm2015bundle,
[ [
{ {
path: _('/node_modules/test/typings/index.d.ts'), path: _('/node_modules/test/typings/index.d.ts'),