Skip to content

Commit d1cbf39

Browse files
committed
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
1 parent 7c7d404 commit d1cbf39

File tree

5 files changed

+38
-6
lines changed

5 files changed

+38
-6
lines changed

apps/vscode/project.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
"@angular-devkit/*",
2626
"@nx/key",
2727
"@nx/nx*",
28+
"nx",
29+
"nx/*",
2830
"*/nx.wasi.cjs"
2931
],
3032
"thirdParty": true,

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: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,3 +200,27 @@ 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+
const migrateUIApi = await importMigrateUIApi(workspacePath);
208+
209+
const isStopped = migrateUIApi.killMigrationProcess(
210+
migration.id,
211+
workspacePath,
212+
);
213+
214+
if (isStopped) {
215+
window.showInformationMessage(
216+
`Migration "${migration.name}" has been stopped.`,
217+
);
218+
} else {
219+
window.showWarningMessage(
220+
`Migration "${migration.name}" was not running or could not be stopped.`,
221+
);
222+
}
223+
} catch (error) {
224+
window.showErrorMessage(`Failed to stop migration: ${error.message}`);
225+
}
226+
}

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)