Skip to content

Commit

Permalink
Revert "refactor(migrations): support parallel tsurge metadata merging (
Browse files Browse the repository at this point in the history
angular#58280)"

This reverts commit 21b6613.
  • Loading branch information
AndrewKushnir committed Oct 22, 2024
1 parent 30525e0 commit 9b4ddc6
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 70 deletions.
18 changes: 2 additions & 16 deletions packages/core/schematics/utils/tsurge/base_migration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,22 +73,8 @@ export abstract class TsurgeBaseMigration<UnitAnalysisMetadata, CombinedGlobalMe
/** Analyzes the given TypeScript project and returns serializable compilation unit data. */
abstract analyze(info: ProgramInfo): Promise<Serializable<UnitAnalysisMetadata>>;

/**
* Combines two unit analyses into a single analysis metadata.
* This is necessary to allow for parallel merging of metadata.
*/
abstract combine(
unitA: UnitAnalysisMetadata,
unitB: UnitAnalysisMetadata,
): Promise<Serializable<UnitAnalysisMetadata>>;

/**
* Converts combined compilation into global metadata result that
* is then available for migrate and stats stages.
*/
abstract globalMeta(
combinedData: UnitAnalysisMetadata,
): Promise<Serializable<CombinedGlobalMetadata>>;
/** Merges all compilation unit data from previous analysis phases into a global result. */
abstract merge(units: UnitAnalysisMetadata[]): Promise<Serializable<CombinedGlobalMetadata>>;

/** Extract statistics based on the global metadata. */
abstract stats(globalMetadata: CombinedGlobalMetadata): Promise<MigrationStats>;
Expand Down
24 changes: 0 additions & 24 deletions packages/core/schematics/utils/tsurge/executors/combine_exec.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ import {Serializable} from '../helpers/serializable';
import {TsurgeMigration} from '../migration';

/**
* Executes the `globalMeta` stage for the given migration
* to convert the combined unit data into global meta.
* Executes the merge phase for the given migration against
* the given set of analysis unit data.
*
* @returns the serializable global meta.
* @returns the serializable migration global data.
*/
export async function executeGlobalMetaPhase<UnitData, GlobalData>(
export async function executeMergePhase<UnitData, GlobalData>(
migration: TsurgeMigration<UnitData, GlobalData>,
combinedUnitData: UnitData,
units: UnitData[],
): Promise<Serializable<GlobalData>> {
return await migration.globalMeta(combinedUnitData);
return await migration.merge(units);
}
29 changes: 9 additions & 20 deletions packages/core/schematics/utils/tsurge/test/output_migration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import {DtsMetadataReader} from '@angular/compiler-cli/src/ngtsc/metadata';
import {TypeScriptReflectionHost} from '@angular/compiler-cli/src/ngtsc/reflection';
import {confirmAsSerializable, Serializable} from '../helpers/serializable';
import {confirmAsSerializable} from '../helpers/serializable';
import {TsurgeComplexMigration} from '../migration';
import {ProgramInfo} from '../program_info';
import {Replacement, TextUpdate} from '../replacement';
Expand Down Expand Up @@ -52,39 +52,28 @@ export class OutputMigration extends TsurgeComplexMigration<AnalysisUnit, Global
return confirmAsSerializable(discoveredOutputs);
}

override async combine(unitA: AnalysisUnit, unitB: AnalysisUnit) {
const merged: AnalysisUnit = {};
override async merge(data: AnalysisUnit[]) {
const merged: GlobalMetadata = {};

// Merge information from two compilation units. Mark
// Merge information from all compilation units. Mark
// outputs that cannot be migrated due to seen problematic usages.
for (const unit of [unitA, unitB]) {
for (const unit of data) {
for (const [idStr, info] of Object.entries(unit)) {
const id = idStr as OutputID;
const existing = merged[id];

if (existing === undefined) {
merged[id] = {seenProblematicUsage: info.seenProblematicUsage};
} else if (!existing.seenProblematicUsage && info.seenProblematicUsage) {
merged[id].seenProblematicUsage = true;
merged[id] = {canBeMigrated: info.seenProblematicUsage === false};
} else if (existing.canBeMigrated && info.seenProblematicUsage) {
merged[id].canBeMigrated = false;
}
}
}

// merge units into global metadata.
return confirmAsSerializable(merged);
}

override async globalMeta(combinedData: AnalysisUnit) {
const globalMeta: GlobalMetadata = {};

for (const [idStr, info] of Object.entries(combinedData)) {
globalMeta[idStr as OutputID] = {
canBeMigrated: info.seenProblematicUsage === false,
};
}

return confirmAsSerializable(globalMeta);
}

override async migrate(globalAnalysisData: GlobalMetadata, info: ProgramInfo) {
const program = info.program;
const typeChecker = program.getTypeChecker();
Expand Down
8 changes: 4 additions & 4 deletions packages/core/schematics/utils/tsurge/testing/run_single.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,11 @@ export async function runTsurgeMigration<UnitData, GlobalData>(
const info = migration.prepareProgram(baseInfo);

const unitData = await migration.analyze(info);
const globalMeta = await migration.globalMeta(unitData);
const merged = await migration.merge([unitData]);
const {replacements} =
migration instanceof TsurgeFunnelMigration
? await migration.migrate(globalMeta)
: await migration.migrate(globalMeta, info);
? await migration.migrate(merged)
: await migration.migrate(merged, info);

const updates = groupReplacementsByFile(replacements);
for (const [rootRelativePath, changes] of updates.entries()) {
Expand All @@ -76,6 +76,6 @@ export async function runTsurgeMigration<UnitData, GlobalData>(

return {
fs: mockFs,
getStatistics: () => migration.stats(globalMeta),
getStatistics: () => migration.stats(merged),
};
}

0 comments on commit 9b4ddc6

Please sign in to comment.