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:

committed by
Alex Rickabaugh

parent
93d27eefd5
commit
29d3b68554
@ -29,13 +29,6 @@ export type ExecuteFn = (analyzeFn: AnalyzeFn, createCompileFn: CreateCompileFn)
|
||||
|
||||
/** Represents metadata related to the processing of an entry-point. */
|
||||
export interface EntryPointProcessingMetadata {
|
||||
/**
|
||||
* A mapping from a format property (i.e. an `EntryPointJsonProperty`) to the list of format
|
||||
* properties that point to the same format-path and as a result need to be marked as processed,
|
||||
* once the former is processed.
|
||||
*/
|
||||
propertyToPropertiesToMarkAsProcessed: Map<EntryPointJsonProperty, EntryPointJsonProperty[]>;
|
||||
|
||||
/**
|
||||
* Whether the typings for the entry-point have been successfully processed (or were already
|
||||
* processed).
|
||||
@ -60,6 +53,13 @@ export interface Task {
|
||||
*/
|
||||
formatProperty: EntryPointJsonProperty;
|
||||
|
||||
/**
|
||||
* The list of all format properties (including `task.formatProperty`) that should be marked as
|
||||
* processed once the taksk has been completed, because they point to the format-path that will be
|
||||
* processed as part of the task.
|
||||
*/
|
||||
formatPropertiesToMarkAsProcessed: EntryPointJsonProperty[];
|
||||
|
||||
/** Whether to also process typings for this entry-point as part of the task. */
|
||||
processDts: boolean;
|
||||
}
|
||||
|
@ -117,14 +117,15 @@ export function mainNgcc(
|
||||
let processDts = !hasProcessedTypings;
|
||||
|
||||
for (const formatProperty of propertiesToProcess) {
|
||||
tasks.push({entryPoint, formatProperty, processDts});
|
||||
const formatPropertiesToMarkAsProcessed =
|
||||
propertyToPropertiesToMarkAsProcessed.get(formatProperty) !;
|
||||
tasks.push({entryPoint, formatProperty, formatPropertiesToMarkAsProcessed, processDts});
|
||||
|
||||
// Only process typings for the first property (if not already processed).
|
||||
processDts = false;
|
||||
}
|
||||
|
||||
processingMetadataPerEntryPoint.set(entryPoint.path, {
|
||||
propertyToPropertiesToMarkAsProcessed,
|
||||
hasProcessedTypings,
|
||||
hasAnyProcessedFormat: false,
|
||||
});
|
||||
@ -139,7 +140,7 @@ export function mainNgcc(
|
||||
const transformer = new Transformer(fileSystem, logger);
|
||||
|
||||
return (task: Task) => {
|
||||
const {entryPoint, formatProperty, processDts} = task;
|
||||
const {entryPoint, formatProperty, formatPropertiesToMarkAsProcessed, processDts} = task;
|
||||
|
||||
const isCore = entryPoint.name === '@angular/core'; // Are we compiling the Angular core?
|
||||
const packageJson = entryPoint.packageJson;
|
||||
@ -171,7 +172,7 @@ export function mainNgcc(
|
||||
logger.info(`Compiling ${entryPoint.name} : ${formatProperty} as ${format}`);
|
||||
|
||||
const transformedFiles = transformer.transform(bundle);
|
||||
fileWriter.writeBundle(bundle, transformedFiles, formatProperty);
|
||||
fileWriter.writeBundle(bundle, transformedFiles, formatPropertiesToMarkAsProcessed);
|
||||
|
||||
onTaskCompleted(task, TaskProcessingOutcome.Processed);
|
||||
};
|
||||
@ -180,14 +181,15 @@ export function mainNgcc(
|
||||
// The function for actually planning and getting the work done.
|
||||
const executeFn: ExecuteFn = (analyzeFn: AnalyzeFn, createCompileFn: CreateCompileFn) => {
|
||||
const {processingMetadataPerEntryPoint, tasks} = analyzeFn();
|
||||
const compile = createCompileFn(({entryPoint, formatProperty, processDts}, outcome) => {
|
||||
const compile = createCompileFn((task, outcome) => {
|
||||
const {entryPoint, formatPropertiesToMarkAsProcessed, processDts} = task;
|
||||
const processingMeta = processingMetadataPerEntryPoint.get(entryPoint.path) !;
|
||||
processingMeta.hasAnyProcessedFormat = true;
|
||||
|
||||
if (outcome === TaskProcessingOutcome.Processed) {
|
||||
const packageJsonPath = fileSystem.resolve(entryPoint.path, 'package.json');
|
||||
const propsToMarkAsProcessed: (EntryPointJsonProperty | 'typings')[] =
|
||||
processingMeta.propertyToPropertiesToMarkAsProcessed.get(formatProperty) !;
|
||||
[...formatPropertiesToMarkAsProcessed];
|
||||
|
||||
if (processDts) {
|
||||
processingMeta.hasProcessedTypings = true;
|
||||
|
@ -16,5 +16,5 @@ import {FileToWrite} from '../rendering/utils';
|
||||
export interface FileWriter {
|
||||
writeBundle(
|
||||
bundle: EntryPointBundle, transformedFiles: FileToWrite[],
|
||||
formatProperty: EntryPointJsonProperty): void;
|
||||
formatProperties: EntryPointJsonProperty[]): void;
|
||||
}
|
||||
|
@ -21,7 +21,7 @@ export class InPlaceFileWriter implements FileWriter {
|
||||
|
||||
writeBundle(
|
||||
_bundle: EntryPointBundle, transformedFiles: FileToWrite[],
|
||||
_formatProperty?: EntryPointJsonProperty) {
|
||||
_formatProperties?: EntryPointJsonProperty[]) {
|
||||
transformedFiles.forEach(file => this.writeFileAndBackup(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`);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user