Skip to content

Commit 7b8f9ae

Browse files
committed
feat(migration): add framework shim confirmation and handling for TypeScript component files
1 parent 23fb9be commit 7b8f9ae

1 file changed

Lines changed: 50 additions & 1 deletion

File tree

  • packages/cli/src/migration

packages/cli/src/migration/bin.ts

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,14 @@ import { accent, log, muted } from '../utils/terminal.ts';
4141
import type { PackageDependencies } from '../utils/types.ts';
4242
import { detectWorkspace } from '../utils/workspace.ts';
4343
import {
44+
addFrameworkShim,
4445
checkVitestVersion,
4546
checkViteVersion,
4647
detectEslintProject,
48+
detectFramework,
4749
detectNodeVersionManagerFile,
4850
detectPrettierProject,
51+
hasFrameworkShim,
4952
installGitHooks,
5053
mergeViteConfigFiles,
5154
migrateEslintToOxlint,
@@ -54,6 +57,7 @@ import {
5457
preflightGitHooksSetup,
5558
rewriteMonorepo,
5659
rewriteStandaloneProject,
60+
type Framework,
5761
type NodeVersionManagerDetection,
5862
} from './migrator.ts';
5963
import { createMigrationReport, type MigrationReport } from './report.ts';
@@ -204,6 +208,30 @@ async function confirmNodeVersionFileMigration(
204208
return true;
205209
}
206210

211+
async function confirmFrameworkShim(
212+
framework: Framework,
213+
interactive: boolean,
214+
): Promise<boolean> {
215+
const frameworkNames: Record<Framework, string> = { vue: 'Vue', astro: 'Astro' };
216+
const name = frameworkNames[framework];
217+
if (interactive) {
218+
const confirmed = await prompts.confirm({
219+
message:
220+
`Add TypeScript shim for ${name} component files (*.${framework})?\n ` +
221+
styleText(
222+
'gray',
223+
`Lets TypeScript recognize .${framework} files until vp check fully supports them.`,
224+
),
225+
initialValue: true,
226+
});
227+
if (prompts.isCancel(confirmed)) {
228+
cancelAndExit();
229+
}
230+
return confirmed;
231+
}
232+
return true;
233+
}
234+
207235
const helpMessage = renderCliDoc({
208236
usage: 'vp migrate [PATH] [OPTIONS]',
209237
summary:
@@ -356,6 +384,7 @@ interface MigrationPlan {
356384
prettierConfigFile?: string;
357385
migrateNodeVersionFile: boolean;
358386
nodeVersionDetection?: NodeVersionManagerDetection;
387+
frameworkShimFramework?: Framework;
359388
}
360389

361390
async function collectMigrationPlan(
@@ -493,6 +522,16 @@ async function collectMigrationPlan(
493522
);
494523
}
495524

525+
// 11. Framework shim detection + prompt
526+
const detectedFramework = detectFramework(rootDir);
527+
let frameworkShimFramework: Framework | undefined;
528+
if (detectedFramework && !hasFrameworkShim(rootDir, detectedFramework)) {
529+
const addShim = await confirmFrameworkShim(detectedFramework, options.interactive);
530+
if (addShim) {
531+
frameworkShimFramework = detectedFramework;
532+
}
533+
}
534+
496535
const plan: MigrationPlan = {
497536
packageManager,
498537
shouldSetupHooks,
@@ -506,6 +545,7 @@ async function collectMigrationPlan(
506545
prettierConfigFile: prettierProject.configFile,
507546
migrateNodeVersionFile,
508547
nodeVersionDetection,
548+
frameworkShimFramework,
509549
};
510550

511551
return plan;
@@ -588,6 +628,9 @@ function showMigrationSummary(options: {
588628
if (report.gitHooksConfigured) {
589629
log(`${styleText('gray', '•')} Git hooks configured`);
590630
}
631+
if (report.frameworkShimAdded) {
632+
log(`${styleText('gray', '•')} TypeScript shim added for framework component files`);
633+
}
591634
if (report.warnings.length > 0) {
592635
log(`${styleText('yellow', '!')} Warnings:`);
593636
for (const warning of report.warnings) {
@@ -807,7 +850,13 @@ async function executeMigrationPlan(
807850
silent: true,
808851
});
809852

810-
// 11. Reinstall after migration
853+
// 11. Add framework shim if requested
854+
if (plan.frameworkShimFramework) {
855+
updateMigrationProgress('Adding TypeScript shim');
856+
addFrameworkShim(workspaceInfo.rootDir, plan.frameworkShimFramework, report);
857+
}
858+
859+
// 12. Reinstall after migration
811860
// npm needs --force to re-resolve packages with newly added overrides,
812861
// otherwise the stale lockfile prevents override resolution.
813862
const installArgs =

0 commit comments

Comments
 (0)