Skip to content

Commit 18de342

Browse files
authored
feat(migrate): add stop migration functionality and update commands (#2567)
* feat(migrate): add stop migration functionality and update commands - When we run a migration via the migrate UI it runs as a separate process - Ensure that the webview is updated after changes have been made via run migration - Add stop command to kill a currently running migration * fix(migrate): remove nx marked as external * chore(migrate): Add Todo and cast migrateUIApi as any
1 parent d30d99a commit 18de342

File tree

4 files changed

+37
-6
lines changed

4 files changed

+37
-6
lines changed

libs/vscode/migrate/src/lib/commands/finish-migration.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
11
import { getNxWorkspacePath } from '@nx-console/vscode-configuration';
2-
import { execSync } from 'child_process';
3-
import { existsSync, readFileSync, rmSync } from 'fs';
4-
import { join } from 'path';
52
import { window, commands } from 'vscode';
63
import { importMigrateUIApi, readMigrationsJsonMetadata } from './utils';
74
import { logAndShowError } from '@nx-console/vscode-output-channels';

libs/vscode/migrate/src/lib/commands/migrate-commands.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,3 +200,28 @@ export async function viewDocumentation(migration: MigrationDetailsWithId) {
200200

201201
commands.executeCommand('vscode.open', url);
202202
}
203+
204+
export async function stopMigration(migration: MigrationDetailsWithId) {
205+
try {
206+
const workspacePath = getNxWorkspacePath();
207+
// TODO: Remove the `as any` cast once the repository is updated to use the latest Nx version that exports the `killMigrationProcess` function.
208+
const migrateUIApi = (await importMigrateUIApi(workspacePath)) as any;
209+
210+
const isStopped = migrateUIApi.killMigrationProcess(
211+
migration.id,
212+
workspacePath,
213+
);
214+
215+
if (isStopped) {
216+
window.showInformationMessage(
217+
`Migration "${migration.name}" has been stopped.`,
218+
);
219+
} else {
220+
window.showWarningMessage(
221+
`Migration "${migration.name}" was not running or could not be stopped.`,
222+
);
223+
}
224+
} catch (error) {
225+
window.showErrorMessage(`Failed to stop migration: ${error.message}`);
226+
}
227+
}

libs/vscode/migrate/src/lib/commands/run-migration.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,15 @@ export async function runSingleMigration(
1515
title: `Running ${migration.name}`,
1616
},
1717
async () => {
18-
commands.executeCommand('nxMigrate.refreshWebview');
19-
2018
const migrateUiApi = await importMigrateUIApi(workspacePath);
21-
migrateUiApi.runSingleMigration(workspacePath, migration, configuration);
19+
await migrateUiApi.runSingleMigration(
20+
workspacePath,
21+
migration,
22+
configuration,
23+
);
24+
25+
// Refresh after migration completes and writes to migrations.json
26+
commands.executeCommand('nxMigrate.refreshWebview');
2227
},
2328
);
2429
}

libs/vscode/migrate/src/lib/migrate-webview.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import {
1616
import {
1717
cancelMigration,
1818
skipMigration,
19+
stopMigration,
1920
undoMigration,
2021
viewDocumentation,
2122
viewImplementation,
@@ -101,6 +102,9 @@ export class MigrateWebview {
101102
case 'view-documentation':
102103
viewDocumentation(message.payload.migration);
103104
break;
105+
case 'stop-migration':
106+
stopMigration(message.payload.migration);
107+
break;
104108
}
105109
});
106110

0 commit comments

Comments
 (0)