From 52b5e5975fbe4401a0fcfea8c83d715b935f8b7e Mon Sep 17 00:00:00 2001 From: Andrew Kushnir Date: Tue, 22 Oct 2024 12:01:21 -0700 Subject: [PATCH] Revert "test: support parallel tsurge unit combining in batch test infra (#58280)" This reverts commit cb34e406baf2c8ede5d49054e7cea8ddb4d601f9. --- .../signal-migration/src/batch/test_bin.ts | 18 ++++----- .../signal-migration/test/BUILD.bazel | 3 +- .../signal-migration/test/batch_runner.ts | 14 ++----- .../utils/tsurge/helpers/combine_units.ts | 37 ------------------- 4 files changed, 14 insertions(+), 58 deletions(-) delete mode 100644 packages/core/schematics/utils/tsurge/helpers/combine_units.ts diff --git a/packages/core/schematics/migrations/signal-migration/src/batch/test_bin.ts b/packages/core/schematics/migrations/signal-migration/src/batch/test_bin.ts index e9ab0b29d9120..28ad0bb8bee2c 100644 --- a/packages/core/schematics/migrations/signal-migration/src/batch/test_bin.ts +++ b/packages/core/schematics/migrations/signal-migration/src/batch/test_bin.ts @@ -9,12 +9,12 @@ import fs from 'fs'; import path from 'path'; import {executeAnalyzePhase} from '../../../../utils/tsurge/executors/analyze_exec'; +import {executeCombinePhase} from '../../../../utils/tsurge/executors/combine_exec'; import {executeMigratePhase} from '../../../../utils/tsurge/executors/migrate_exec'; import {SignalInputMigration} from '../migration'; import {writeMigrationReplacements} from '../write_replacements'; import {CompilationUnitData} from './unit_data'; import {executeGlobalMetaPhase} from '../../../../utils/tsurge/executors/global_meta_exec'; -import {synchronouslyCombineUnitData} from '../../../../utils/tsurge/helpers/combine_units'; main().catch((e) => { console.error(e); @@ -28,16 +28,16 @@ async function main() { if (mode === 'extract') { const analyzeResult = await executeAnalyzePhase(migration, path.resolve(args[0])); process.stdout.write(JSON.stringify(analyzeResult)); - } else if (mode === 'combine-all') { - const unitPromises = args.map((f) => readUnitMeta(path.resolve(f))); - const units = await Promise.all(unitPromises); - const mergedResult = await synchronouslyCombineUnitData(migration, units); + } else if (mode === 'combine') { + const unitAPromise = readUnitMeta(path.resolve(args[0])); + const unitBPromise = readUnitMeta(path.resolve(args[1])); - process.stdout.write(JSON.stringify(mergedResult)); - } else if (mode === 'global-meta') { - const metaResult = await executeGlobalMetaPhase(migration, await readUnitMeta(args[0])); + const [unitA, unitB] = await Promise.all([unitAPromise, unitBPromise]); + const mergedResult = await executeCombinePhase(migration, unitA, unitB); - process.stdout.write(JSON.stringify(metaResult)); + process.stdout.write(JSON.stringify(mergedResult)); + } else if (mode === 'globalMeta') { + await executeGlobalMetaPhase(migration, await readUnitMeta(args[0])); } else if (mode === 'migrate') { const {replacements, projectRoot} = await executeMigratePhase( migration, diff --git a/packages/core/schematics/migrations/signal-migration/test/BUILD.bazel b/packages/core/schematics/migrations/signal-migration/test/BUILD.bazel index 86df54706db90..9f8cc30b4f407 100644 --- a/packages/core/schematics/migrations/signal-migration/test/BUILD.bazel +++ b/packages/core/schematics/migrations/signal-migration/test/BUILD.bazel @@ -103,8 +103,7 @@ integration_test( ], commands = [ "$(rootpath :batch_runner) analyze ./golden-test", - "$(rootpath :batch_runner) combine-all ./golden-test", - "$(rootpath :batch_runner) global-meta ./golden-test", + "$(rootpath :batch_runner) merge ./golden-test", "$(rootpath :batch_runner) migrate ./golden-test", "$(rootpath :golden_test_runner) ./golden-test ./golden.txt", ], diff --git a/packages/core/schematics/migrations/signal-migration/test/batch_runner.ts b/packages/core/schematics/migrations/signal-migration/test/batch_runner.ts index 7cd1dc0672404..e96bc25328105 100644 --- a/packages/core/schematics/migrations/signal-migration/test/batch_runner.ts +++ b/packages/core/schematics/migrations/signal-migration/test/batch_runner.ts @@ -53,24 +53,18 @@ async function main() { // write individual result. await fs.promises.writeFile(extractResultFile, extractResult); }); - } else if (mode === 'combine-all') { + } else if (mode === 'merge') { const metadataFiles = files.map((f) => path.resolve(path.join(sourceDir, `${f}.extract.json`))); - const mergeResult = await promiseExec(`migration combine-all ${metadataFiles.join(' ')}`); + const mergeResult = await promiseExec(`migration merge ${metadataFiles.join(' ')}`); // write merge result. - await fs.promises.writeFile(path.join(sourceDir, 'combined.json'), mergeResult); - } else if (mode === 'global-meta') { - const combinedUnitFile = path.join(sourceDir, 'combined.json'); - const globalMeta = await promiseExec(`migration global-meta ${combinedUnitFile}`); - - // write global meta result. - await fs.promises.writeFile(path.join(sourceDir, 'global_meta.json'), globalMeta); + await fs.promises.writeFile(path.join(sourceDir, 'merged.json'), mergeResult); } else if (mode === 'migrate') { schedule(files, maxParallel, async (fileName) => { const filePath = path.join(sourceDir, fileName); // tsconfig should exist from analyze phase. const tmpTsconfigName = path.join(sourceDir, `${fileName}.tsconfig.json`); - const mergeMetadataFile = path.join(sourceDir, 'global_meta.json'); + const mergeMetadataFile = path.join(sourceDir, 'merged.json'); // migrate in parallel. await promiseExec( diff --git a/packages/core/schematics/utils/tsurge/helpers/combine_units.ts b/packages/core/schematics/utils/tsurge/helpers/combine_units.ts deleted file mode 100644 index 2405dfb6a3945..0000000000000 --- a/packages/core/schematics/utils/tsurge/helpers/combine_units.ts +++ /dev/null @@ -1,37 +0,0 @@ -/** - * @license - * Copyright Google LLC All Rights Reserved. - * - * Use of this source code is governed by an MIT-style license that can be - * found in the LICENSE file at https://angular.dev/license - */ - -import {TsurgeMigration} from '../migration'; - -/** - * Synchronously combines unit data for the given migration. - * - * Note: This helper is useful for testing and execution of - * Tsurge migrations in non-batchable environments. In general, - * prefer parallel execution of combining via e.g. Beam combiners. - */ -export async function synchronouslyCombineUnitData( - migration: TsurgeMigration, - unitDatas: UnitData[], -): Promise { - if (unitDatas.length === 0) { - return null; - } - if (unitDatas.length === 1) { - return unitDatas[0]; - } - - let combined = unitDatas[0]; - - for (let i = 1; i < unitDatas.length; i++) { - const other = unitDatas[i]; - combined = await migration.combine(combined, other); - } - - return combined; -}