refactor(ivy): ngcc - remove formatProperty from EntryPointBundle (#32052)

Remove the `formatProperty` property from the `EntryPointBundle`
interface, because the property is not directly related to that type.

It was only used in one place, when calling `fileWriter.writeBundle()`,
but we can pass `formatProperty` directrly to `writeBundle()`.

PR Close #32052
This commit is contained in:
George Kalpakas
2019-08-08 02:19:52 +03:00
committed by Alex Rickabaugh
parent ef12e10e59
commit ed70f73794
19 changed files with 194 additions and 155 deletions

View File

@ -166,13 +166,12 @@ export function mainNgcc(
}
const bundle = makeEntryPointBundle(
fileSystem, entryPoint, formatPath, isCore, formatProperty, format, processDts,
pathMappings, true);
fileSystem, entryPoint, formatPath, isCore, format, processDts, pathMappings, true);
logger.info(`Compiling ${entryPoint.name} : ${formatProperty} as ${format}`);
const transformedFiles = transformer.transform(bundle);
fileWriter.writeBundle(entryPoint, bundle, transformedFiles);
fileWriter.writeBundle(entryPoint, bundle, transformedFiles, formatProperty);
onTaskCompleted(task, TaskProcessingOutcome.Processed);
};

View File

@ -10,7 +10,7 @@ import {AbsoluteFsPath, FileSystem, absoluteFrom} from '../../../src/ngtsc/file_
import {NgtscCompilerHost} from '../../../src/ngtsc/file_system/src/compiler_host';
import {PathMappings} from '../utils';
import {BundleProgram, makeBundleProgram} from './bundle_program';
import {EntryPoint, EntryPointFormat, EntryPointJsonProperty} from './entry_point';
import {EntryPoint, EntryPointFormat} from './entry_point';
import {NgccSourcesCompilerHost} from './ngcc_compiler_host';
/**
@ -19,7 +19,6 @@ import {NgccSourcesCompilerHost} from './ngcc_compiler_host';
*/
export interface EntryPointBundle {
entryPoint: EntryPoint;
formatProperty: EntryPointJsonProperty;
format: EntryPointFormat;
isCore: boolean;
isFlatCore: boolean;
@ -34,7 +33,6 @@ export interface EntryPointBundle {
* @param entryPoint The entry-point that contains the bundle.
* @param formatPath The path to the source files for this bundle.
* @param isCore This entry point is the Angular core package.
* @param formatProperty The property in the package.json that holds the formatPath.
* @param format The underlying format of the bundle.
* @param transformDts Whether to transform the typings along with this bundle.
* @param pathMappings An optional set of mappings to use when compiling files.
@ -43,8 +41,8 @@ export interface EntryPointBundle {
*/
export function makeEntryPointBundle(
fs: FileSystem, entryPoint: EntryPoint, formatPath: string, isCore: boolean,
formatProperty: EntryPointJsonProperty, format: EntryPointFormat, transformDts: boolean,
pathMappings?: PathMappings, mirrorDtsFromSrc: boolean = false): EntryPointBundle {
format: EntryPointFormat, transformDts: boolean, pathMappings?: PathMappings,
mirrorDtsFromSrc: boolean = false): EntryPointBundle {
// Create the TS program and necessary helpers.
const options: ts.CompilerOptions = {
allowJs: true,
@ -69,7 +67,7 @@ export function makeEntryPointBundle(
null;
const isFlatCore = isCore && src.r3SymbolsFile === null;
return {entryPoint, format, formatProperty, rootDirs, isCore, isFlatCore, src, dts};
return {entryPoint, format, rootDirs, isCore, isFlatCore, src, dts};
}
function computePotentialDtsFilesFromJsFiles(

View File

@ -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} from '../packages/entry_point';
import {EntryPoint, EntryPointJsonProperty} from '../packages/entry_point';
import {EntryPointBundle} from '../packages/entry_point_bundle';
import {FileToWrite} from '../rendering/utils';
@ -14,6 +14,7 @@ import {FileToWrite} from '../rendering/utils';
* Responsible for writing out the transformed files to disk.
*/
export interface FileWriter {
writeBundle(entryPoint: EntryPoint, bundle: EntryPointBundle, transformedFiles: FileToWrite[]):
void;
writeBundle(
entryPoint: EntryPoint, bundle: EntryPointBundle, transformedFiles: FileToWrite[],
formatProperty: EntryPointJsonProperty): void;
}

View File

@ -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} from '../packages/entry_point';
import {EntryPoint, EntryPointJsonProperty} from '../packages/entry_point';
import {EntryPointBundle} from '../packages/entry_point_bundle';
import {FileToWrite} from '../rendering/utils';
import {FileWriter} from './file_writer';
@ -19,7 +19,9 @@ import {FileWriter} from './file_writer';
export class InPlaceFileWriter implements FileWriter {
constructor(protected fs: FileSystem) {}
writeBundle(_entryPoint: EntryPoint, _bundle: EntryPointBundle, transformedFiles: FileToWrite[]) {
writeBundle(
_entryPoint: EntryPoint, _bundle: EntryPointBundle, transformedFiles: FileToWrite[],
_formatProperty?: EntryPointJsonProperty) {
transformedFiles.forEach(file => this.writeFileAndBackup(file));
}

View File

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