From b9db571f9290374a4dff4ed6bea23caed9babbac Mon Sep 17 00:00:00 2001 From: Leslie Lau <1178273431@qq.com> Date: Thu, 23 Jul 2026 16:51:33 +0800 Subject: [PATCH 1/3] fix(migrate): reject workspace member targets --- .../package.json | 7 ++ .../snapshots.toml | 64 +++++++++++++++++++ .../migration_workspace_member_cwd.md | 49 ++++++++++++++ ...igration_workspace_member_explicit_path.md | 49 ++++++++++++++ .../vendor/sub/package.json | 7 ++ docs/guide/migrate.md | 3 + packages/cli/src/migration/bin.ts | 9 +++ 7 files changed, 188 insertions(+) create mode 100644 crates/vite_cli_snapshots/tests/cli_snapshots/fixtures/migration_workspace_member_target/package.json create mode 100644 crates/vite_cli_snapshots/tests/cli_snapshots/fixtures/migration_workspace_member_target/snapshots.toml create mode 100644 crates/vite_cli_snapshots/tests/cli_snapshots/fixtures/migration_workspace_member_target/snapshots/migration_workspace_member_cwd.md create mode 100644 crates/vite_cli_snapshots/tests/cli_snapshots/fixtures/migration_workspace_member_target/snapshots/migration_workspace_member_explicit_path.md create mode 100644 crates/vite_cli_snapshots/tests/cli_snapshots/fixtures/migration_workspace_member_target/vendor/sub/package.json diff --git a/crates/vite_cli_snapshots/tests/cli_snapshots/fixtures/migration_workspace_member_target/package.json b/crates/vite_cli_snapshots/tests/cli_snapshots/fixtures/migration_workspace_member_target/package.json new file mode 100644 index 0000000000..6a2f1757bc --- /dev/null +++ b/crates/vite_cli_snapshots/tests/cli_snapshots/fixtures/migration_workspace_member_target/package.json @@ -0,0 +1,7 @@ +{ + "name": "workspace-root", + "private": true, + "workspaces": [ + "vendor/*" + ] +} diff --git a/crates/vite_cli_snapshots/tests/cli_snapshots/fixtures/migration_workspace_member_target/snapshots.toml b/crates/vite_cli_snapshots/tests/cli_snapshots/fixtures/migration_workspace_member_target/snapshots.toml new file mode 100644 index 0000000000..5108714d14 --- /dev/null +++ b/crates/vite_cli_snapshots/tests/cli_snapshots/fixtures/migration_workspace_member_target/snapshots.toml @@ -0,0 +1,64 @@ +[[case]] +name = "migration_workspace_member_cwd" +vp = "global" +cwd = "vendor/sub" +steps = [ + { argv = [ + "vp", + "migrate", + "--no-interactive", + "--no-agent", + "--no-editor", + "--no-hooks", + ], comment = "reject migration from a workspace member before changing files", continue-on-failure = true }, + { argv = [ + "vpt", + "print-file", + "../../package.json", + ], comment = "workspace root remains unchanged", continue-on-failure = true }, + { argv = [ + "vpt", + "print-file", + "package.json", + ], comment = "workspace member remains unchanged", continue-on-failure = true }, + { argv = [ + "vpt", + "stat-file", + "../../pnpm-workspace.yaml", + "--assert", + "missing", + ], comment = "no package-manager files are created at the workspace root" }, +] + +[[case]] +name = "migration_workspace_member_explicit_path" +vp = "global" +cwd = "vendor/sub" +steps = [ + { argv = [ + "vp", + "migrate", + ".", + "--no-interactive", + "--no-agent", + "--no-editor", + "--no-hooks", + ], comment = "reject an explicit workspace-member target before changing files", continue-on-failure = true }, + { argv = [ + "vpt", + "print-file", + "../../package.json", + ], comment = "workspace root remains unchanged", continue-on-failure = true }, + { argv = [ + "vpt", + "print-file", + "package.json", + ], comment = "workspace member remains unchanged", continue-on-failure = true }, + { argv = [ + "vpt", + "stat-file", + "../../pnpm-workspace.yaml", + "--assert", + "missing", + ], comment = "no package-manager files are created at the workspace root" }, +] diff --git a/crates/vite_cli_snapshots/tests/cli_snapshots/fixtures/migration_workspace_member_target/snapshots/migration_workspace_member_cwd.md b/crates/vite_cli_snapshots/tests/cli_snapshots/fixtures/migration_workspace_member_target/snapshots/migration_workspace_member_cwd.md new file mode 100644 index 0000000000..977c1f6c08 --- /dev/null +++ b/crates/vite_cli_snapshots/tests/cli_snapshots/fixtures/migration_workspace_member_target/snapshots/migration_workspace_member_cwd.md @@ -0,0 +1,49 @@ +# migration_workspace_member_cwd + +## `vp migrate --no-interactive --no-agent --no-editor --no-hooks` + +reject migration from a workspace member before changing files + +**Exit code:** 1 + +``` +VITE+ - The Unified Toolchain for the Web + +Cannot migrate a workspace member independently. Run `vp migrate` from the workspace root at . +``` + +## `vpt print-file ../../package.json` + +workspace root remains unchanged + +``` +{ + "name": "workspace-root", + "private": true, + "workspaces": [ + "vendor/*" + ] +} +``` + +## `vpt print-file package.json` + +workspace member remains unchanged + +``` +{ + "name": "workspace-member", + "private": true, + "devDependencies": { + "vitest": "" + } +} +``` + +## `vpt stat-file ../../pnpm-workspace.yaml --assert missing` + +no package-manager files are created at the workspace root + +``` +../../pnpm-workspace.yaml: missing +``` diff --git a/crates/vite_cli_snapshots/tests/cli_snapshots/fixtures/migration_workspace_member_target/snapshots/migration_workspace_member_explicit_path.md b/crates/vite_cli_snapshots/tests/cli_snapshots/fixtures/migration_workspace_member_target/snapshots/migration_workspace_member_explicit_path.md new file mode 100644 index 0000000000..e04e07e3a3 --- /dev/null +++ b/crates/vite_cli_snapshots/tests/cli_snapshots/fixtures/migration_workspace_member_target/snapshots/migration_workspace_member_explicit_path.md @@ -0,0 +1,49 @@ +# migration_workspace_member_explicit_path + +## `vp migrate . --no-interactive --no-agent --no-editor --no-hooks` + +reject an explicit workspace-member target before changing files + +**Exit code:** 1 + +``` +VITE+ - The Unified Toolchain for the Web + +Cannot migrate a workspace member independently. Run `vp migrate` from the workspace root at . +``` + +## `vpt print-file ../../package.json` + +workspace root remains unchanged + +``` +{ + "name": "workspace-root", + "private": true, + "workspaces": [ + "vendor/*" + ] +} +``` + +## `vpt print-file package.json` + +workspace member remains unchanged + +``` +{ + "name": "workspace-member", + "private": true, + "devDependencies": { + "vitest": "" + } +} +``` + +## `vpt stat-file ../../pnpm-workspace.yaml --assert missing` + +no package-manager files are created at the workspace root + +``` +../../pnpm-workspace.yaml: missing +``` diff --git a/crates/vite_cli_snapshots/tests/cli_snapshots/fixtures/migration_workspace_member_target/vendor/sub/package.json b/crates/vite_cli_snapshots/tests/cli_snapshots/fixtures/migration_workspace_member_target/vendor/sub/package.json new file mode 100644 index 0000000000..96df63ca31 --- /dev/null +++ b/crates/vite_cli_snapshots/tests/cli_snapshots/fixtures/migration_workspace_member_target/vendor/sub/package.json @@ -0,0 +1,7 @@ +{ + "name": "workspace-member", + "private": true, + "devDependencies": { + "vitest": "4.1.10" + } +} diff --git a/docs/guide/migrate.md b/docs/guide/migrate.md index 9de7c63958..c438ec8fcd 100644 --- a/docs/guide/migrate.md +++ b/docs/guide/migrate.md @@ -22,6 +22,9 @@ The positional `PATH` argument is optional. - If omitted, `vp migrate` migrates the current directory - If provided, it migrates that target directory instead +- For a monorepo, the target must be the workspace root. Workspace members + cannot be migrated independently because migration updates shared package + manager configuration, catalogs, and lockfiles. ```bash vp migrate diff --git a/packages/cli/src/migration/bin.ts b/packages/cli/src/migration/bin.ts index d856ef8d9d..92866af9f5 100644 --- a/packages/cli/src/migration/bin.ts +++ b/packages/cli/src/migration/bin.ts @@ -1044,6 +1044,15 @@ async function main() { printHeader(); const workspaceInfoOptional = await detectWorkspace(projectPath); + if ( + workspaceInfoOptional.isMonorepo && + path.resolve(projectPath) !== path.resolve(workspaceInfoOptional.rootDir) + ) { + cancelAndExit( + `Cannot migrate a workspace member independently. Run \`vp migrate\` from the workspace root at ${workspaceInfoOptional.rootDir}.`, + 1, + ); + } const initialChangedPaths = await collectChangedFormatPaths(workspaceInfoOptional.rootDir); const preExistingChangedPaths = initialChangedPaths ? new Set(initialChangedPaths) : undefined; const resolvedPackageManager = workspaceInfoOptional.packageManager ?? 'unknown'; From 818319ceca9caceb9c8aade5199e198cfae4f656 Mon Sep 17 00:00:00 2001 From: MK Date: Tue, 11 Aug 2026 11:45:45 +0800 Subject: [PATCH 2/3] fix(snapshots): move fixture to renamed vp_cli_snapshots crate The crates were renamed from vite_* to vp_* on main. The old crates/vite_cli_snapshots directory has no Cargo.toml, so the crates/* workspace glob broke every cargo command in CI. --- .../fixtures/migration_workspace_member_target/package.json | 0 .../fixtures/migration_workspace_member_target/snapshots.toml | 0 .../snapshots/migration_workspace_member_cwd.md | 0 .../snapshots/migration_workspace_member_explicit_path.md | 0 .../migration_workspace_member_target/vendor/sub/package.json | 0 5 files changed, 0 insertions(+), 0 deletions(-) rename crates/{vite_cli_snapshots => vp_cli_snapshots}/tests/cli_snapshots/fixtures/migration_workspace_member_target/package.json (100%) rename crates/{vite_cli_snapshots => vp_cli_snapshots}/tests/cli_snapshots/fixtures/migration_workspace_member_target/snapshots.toml (100%) rename crates/{vite_cli_snapshots => vp_cli_snapshots}/tests/cli_snapshots/fixtures/migration_workspace_member_target/snapshots/migration_workspace_member_cwd.md (100%) rename crates/{vite_cli_snapshots => vp_cli_snapshots}/tests/cli_snapshots/fixtures/migration_workspace_member_target/snapshots/migration_workspace_member_explicit_path.md (100%) rename crates/{vite_cli_snapshots => vp_cli_snapshots}/tests/cli_snapshots/fixtures/migration_workspace_member_target/vendor/sub/package.json (100%) diff --git a/crates/vite_cli_snapshots/tests/cli_snapshots/fixtures/migration_workspace_member_target/package.json b/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/migration_workspace_member_target/package.json similarity index 100% rename from crates/vite_cli_snapshots/tests/cli_snapshots/fixtures/migration_workspace_member_target/package.json rename to crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/migration_workspace_member_target/package.json diff --git a/crates/vite_cli_snapshots/tests/cli_snapshots/fixtures/migration_workspace_member_target/snapshots.toml b/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/migration_workspace_member_target/snapshots.toml similarity index 100% rename from crates/vite_cli_snapshots/tests/cli_snapshots/fixtures/migration_workspace_member_target/snapshots.toml rename to crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/migration_workspace_member_target/snapshots.toml diff --git a/crates/vite_cli_snapshots/tests/cli_snapshots/fixtures/migration_workspace_member_target/snapshots/migration_workspace_member_cwd.md b/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/migration_workspace_member_target/snapshots/migration_workspace_member_cwd.md similarity index 100% rename from crates/vite_cli_snapshots/tests/cli_snapshots/fixtures/migration_workspace_member_target/snapshots/migration_workspace_member_cwd.md rename to crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/migration_workspace_member_target/snapshots/migration_workspace_member_cwd.md diff --git a/crates/vite_cli_snapshots/tests/cli_snapshots/fixtures/migration_workspace_member_target/snapshots/migration_workspace_member_explicit_path.md b/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/migration_workspace_member_target/snapshots/migration_workspace_member_explicit_path.md similarity index 100% rename from crates/vite_cli_snapshots/tests/cli_snapshots/fixtures/migration_workspace_member_target/snapshots/migration_workspace_member_explicit_path.md rename to crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/migration_workspace_member_target/snapshots/migration_workspace_member_explicit_path.md diff --git a/crates/vite_cli_snapshots/tests/cli_snapshots/fixtures/migration_workspace_member_target/vendor/sub/package.json b/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/migration_workspace_member_target/vendor/sub/package.json similarity index 100% rename from crates/vite_cli_snapshots/tests/cli_snapshots/fixtures/migration_workspace_member_target/vendor/sub/package.json rename to crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/migration_workspace_member_target/vendor/sub/package.json From 35d6db49adc5f2ffbfdb319fdbbb546bc6d03b20 Mon Sep 17 00:00:00 2001 From: MK Date: Tue, 11 Aug 2026 12:32:49 +0800 Subject: [PATCH 3/3] refactor(migrate): simplify workspace-member rejection wording Apply Simplified Technical English to the error message, the docs bullet, and the snapshot step comments: active voice, a named subject, no -ing verb forms. Snapshots re-recorded. --- .../snapshots.toml | 16 ++++++++-------- .../snapshots/migration_workspace_member_cwd.md | 10 +++++----- .../migration_workspace_member_explicit_path.md | 10 +++++----- docs/guide/migrate.md | 6 +++--- packages/cli/src/migration/bin.ts | 2 +- 5 files changed, 22 insertions(+), 22 deletions(-) diff --git a/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/migration_workspace_member_target/snapshots.toml b/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/migration_workspace_member_target/snapshots.toml index 5108714d14..81639391ac 100644 --- a/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/migration_workspace_member_target/snapshots.toml +++ b/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/migration_workspace_member_target/snapshots.toml @@ -10,24 +10,24 @@ steps = [ "--no-agent", "--no-editor", "--no-hooks", - ], comment = "reject migration from a workspace member before changing files", continue-on-failure = true }, + ], comment = "vp migrate rejects a workspace member before it changes files", continue-on-failure = true }, { argv = [ "vpt", "print-file", "../../package.json", - ], comment = "workspace root remains unchanged", continue-on-failure = true }, + ], comment = "the workspace root package.json is unchanged", continue-on-failure = true }, { argv = [ "vpt", "print-file", "package.json", - ], comment = "workspace member remains unchanged", continue-on-failure = true }, + ], comment = "the workspace member package.json is unchanged", continue-on-failure = true }, { argv = [ "vpt", "stat-file", "../../pnpm-workspace.yaml", "--assert", "missing", - ], comment = "no package-manager files are created at the workspace root" }, + ], comment = "the migration created no package-manager files at the workspace root" }, ] [[case]] @@ -43,22 +43,22 @@ steps = [ "--no-agent", "--no-editor", "--no-hooks", - ], comment = "reject an explicit workspace-member target before changing files", continue-on-failure = true }, + ], comment = "vp migrate rejects an explicit workspace-member target before it changes files", continue-on-failure = true }, { argv = [ "vpt", "print-file", "../../package.json", - ], comment = "workspace root remains unchanged", continue-on-failure = true }, + ], comment = "the workspace root package.json is unchanged", continue-on-failure = true }, { argv = [ "vpt", "print-file", "package.json", - ], comment = "workspace member remains unchanged", continue-on-failure = true }, + ], comment = "the workspace member package.json is unchanged", continue-on-failure = true }, { argv = [ "vpt", "stat-file", "../../pnpm-workspace.yaml", "--assert", "missing", - ], comment = "no package-manager files are created at the workspace root" }, + ], comment = "the migration created no package-manager files at the workspace root" }, ] diff --git a/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/migration_workspace_member_target/snapshots/migration_workspace_member_cwd.md b/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/migration_workspace_member_target/snapshots/migration_workspace_member_cwd.md index 977c1f6c08..bb5d853f6c 100644 --- a/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/migration_workspace_member_target/snapshots/migration_workspace_member_cwd.md +++ b/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/migration_workspace_member_target/snapshots/migration_workspace_member_cwd.md @@ -2,19 +2,19 @@ ## `vp migrate --no-interactive --no-agent --no-editor --no-hooks` -reject migration from a workspace member before changing files +vp migrate rejects a workspace member before it changes files **Exit code:** 1 ``` VITE+ - The Unified Toolchain for the Web -Cannot migrate a workspace member independently. Run `vp migrate` from the workspace root at . +Vite+ cannot migrate a workspace member. Run `vp migrate` from the workspace root at . ``` ## `vpt print-file ../../package.json` -workspace root remains unchanged +the workspace root package.json is unchanged ``` { @@ -28,7 +28,7 @@ workspace root remains unchanged ## `vpt print-file package.json` -workspace member remains unchanged +the workspace member package.json is unchanged ``` { @@ -42,7 +42,7 @@ workspace member remains unchanged ## `vpt stat-file ../../pnpm-workspace.yaml --assert missing` -no package-manager files are created at the workspace root +the migration created no package-manager files at the workspace root ``` ../../pnpm-workspace.yaml: missing diff --git a/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/migration_workspace_member_target/snapshots/migration_workspace_member_explicit_path.md b/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/migration_workspace_member_target/snapshots/migration_workspace_member_explicit_path.md index e04e07e3a3..5857314458 100644 --- a/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/migration_workspace_member_target/snapshots/migration_workspace_member_explicit_path.md +++ b/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/migration_workspace_member_target/snapshots/migration_workspace_member_explicit_path.md @@ -2,19 +2,19 @@ ## `vp migrate . --no-interactive --no-agent --no-editor --no-hooks` -reject an explicit workspace-member target before changing files +vp migrate rejects an explicit workspace-member target before it changes files **Exit code:** 1 ``` VITE+ - The Unified Toolchain for the Web -Cannot migrate a workspace member independently. Run `vp migrate` from the workspace root at . +Vite+ cannot migrate a workspace member. Run `vp migrate` from the workspace root at . ``` ## `vpt print-file ../../package.json` -workspace root remains unchanged +the workspace root package.json is unchanged ``` { @@ -28,7 +28,7 @@ workspace root remains unchanged ## `vpt print-file package.json` -workspace member remains unchanged +the workspace member package.json is unchanged ``` { @@ -42,7 +42,7 @@ workspace member remains unchanged ## `vpt stat-file ../../pnpm-workspace.yaml --assert missing` -no package-manager files are created at the workspace root +the migration created no package-manager files at the workspace root ``` ../../pnpm-workspace.yaml: missing diff --git a/docs/guide/migrate.md b/docs/guide/migrate.md index c438ec8fcd..a9243c27d7 100644 --- a/docs/guide/migrate.md +++ b/docs/guide/migrate.md @@ -22,9 +22,9 @@ The positional `PATH` argument is optional. - If omitted, `vp migrate` migrates the current directory - If provided, it migrates that target directory instead -- For a monorepo, the target must be the workspace root. Workspace members - cannot be migrated independently because migration updates shared package - manager configuration, catalogs, and lockfiles. +- For a monorepo, the target must be the workspace root. Vite+ cannot + migrate one workspace member, because migration updates the package-manager + configuration, the catalogs, and the lockfiles that all members share. ```bash vp migrate diff --git a/packages/cli/src/migration/bin.ts b/packages/cli/src/migration/bin.ts index 92866af9f5..75a1b5148c 100644 --- a/packages/cli/src/migration/bin.ts +++ b/packages/cli/src/migration/bin.ts @@ -1049,7 +1049,7 @@ async function main() { path.resolve(projectPath) !== path.resolve(workspaceInfoOptional.rootDir) ) { cancelAndExit( - `Cannot migrate a workspace member independently. Run \`vp migrate\` from the workspace root at ${workspaceInfoOptional.rootDir}.`, + `Vite+ cannot migrate a workspace member. Run \`vp migrate\` from the workspace root at ${workspaceInfoOptional.rootDir}.`, 1, ); }