fix(ivy): ngcc - correctly update package.json when createNewEntryPointFormats is true (#32052)

Previously, when run with `createNewEntryPointFormats: true`, `ngcc`
would only update `package.json` with the new entry-point for the first
format property that mapped to a format-path. Subsequent properties
mapping to the same format-path would be detected as processed and not
have their new entry-point format recorded in `package.json`.

This commit fixes this by ensuring `package.json` is updated for all
matching format properties, when writing an `EntryPointBundle`.

PR Close #32052
This commit is contained in:
George Kalpakas
2019-08-08 03:23:46 +03:00
committed by Alex Rickabaugh
parent 93d27eefd5
commit 29d3b68554
7 changed files with 152 additions and 44 deletions

View File

@ -16,5 +16,5 @@ import {FileToWrite} from '../rendering/utils';
export interface FileWriter {
writeBundle(
bundle: EntryPointBundle, transformedFiles: FileToWrite[],
formatProperty: EntryPointJsonProperty): void;
formatProperties: EntryPointJsonProperty[]): void;
}

View File

@ -21,7 +21,7 @@ export class InPlaceFileWriter implements FileWriter {
writeBundle(
_bundle: EntryPointBundle, transformedFiles: FileToWrite[],
_formatProperty?: EntryPointJsonProperty) {
_formatProperties?: EntryPointJsonProperty[]) {
transformedFiles.forEach(file => this.writeFileAndBackup(file));
}

View File

@ -27,13 +27,13 @@ const NGCC_DIRECTORY = '__ivy_ngcc__';
export class NewEntryPointFileWriter extends InPlaceFileWriter {
writeBundle(
bundle: EntryPointBundle, transformedFiles: FileToWrite[],
formatProperty: EntryPointJsonProperty) {
formatProperties: 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));
this.updatePackageJson(entryPoint, formatProperty, ngccFolder);
this.updatePackageJson(entryPoint, formatProperties, ngccFolder);
}
protected copyBundle(
@ -63,12 +63,18 @@ export class NewEntryPointFileWriter extends InPlaceFileWriter {
}
protected updatePackageJson(
entryPoint: EntryPoint, formatProperty: EntryPointJsonProperty, ngccFolder: AbsoluteFsPath) {
const formatPath = join(entryPoint.path, entryPoint.packageJson[formatProperty] !);
const newFormatPath = join(ngccFolder, relative(entryPoint.package, formatPath));
const newFormatProperty = formatProperty + '_ivy_ngcc';
(entryPoint.packageJson as any)[newFormatProperty] = relative(entryPoint.path, newFormatPath);
entryPoint: EntryPoint, formatProperties: EntryPointJsonProperty[],
ngccFolder: AbsoluteFsPath) {
const packageJson = entryPoint.packageJson;
for (const formatProperty of formatProperties) {
const formatPath = join(entryPoint.path, packageJson[formatProperty] !);
const newFormatPath = join(ngccFolder, relative(entryPoint.package, formatPath));
const newFormatProperty = formatProperty + '_ivy_ngcc';
(packageJson as any)[newFormatProperty] = relative(entryPoint.path, newFormatPath);
}
this.fs.writeFile(
join(entryPoint.path, 'package.json'), JSON.stringify(entryPoint.packageJson));
join(entryPoint.path, 'package.json'), `${JSON.stringify(packageJson, null, 2)}\n`);
}
}