From e3972ea0d88c50118de12c84181625799a7a181d Mon Sep 17 00:00:00 2001 From: "gxc.510" Date: Mon, 30 Nov 2026 12:20:18 +0800 Subject: [PATCH 1/5] fix(migrate): supply the Vite peer for direct pnpm Vitest installs Change-Id: I2f26472eca3d61e8ce50e9b4e3bdc2c935faadf9 --- .../migration_import_rule_install.md | 1 + ...import_rule_preserved_dependency_owners.md | 3 + ...gration_import_rule_template_dependency.md | 2 + ...migration_monorepo_root_vitest_adjacent.md | 1 + .../check-identity.mjs | 12 ++-- .../snapshots.toml | 3 +- ...10_upgrade_peer_identity_and_test_cache.md | 2 - .../pnpm_peer_identity_and_test_cache.md | 6 +- .../migration_rewrite_declare_module.md | 1 + ...igration_upgrade_browser_peer_only_pnpm.md | 1 + ...ration_upgrade_browser_source_only_pnpm.md | 1 + .../migrate_vitest4_community_provider.md | 2 +- ...ration_upgrade_browser_webdriverio_pnpm.md | 1 + .../preserve_community_provider_version.md | 1 + .../upgrade_community_provider_catalog.md | 1 + ..._upgrade_monorepo_vitest_localized_pnpm.md | 1 + ...ration_upgrade_nuxt_test_utils_monorepo.md | 1 + docs/guide/migrate-rules.md | 2 + .../src/migration/__tests__/migrator.spec.ts | 69 +++++++++++++++---- packages/cli/src/migration/bin.ts | 4 ++ .../cli/src/migration/migrator/catalog.ts | 25 +++++++ .../src/migration/migrator/package-json.ts | 5 +- .../migration/migrator/vite-plus-bootstrap.ts | 12 +++- 23 files changed, 129 insertions(+), 28 deletions(-) diff --git a/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/migration_import_rule_install/snapshots/migration_import_rule_install.md b/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/migration_import_rule_install/snapshots/migration_import_rule_install.md index f806966d79..4fe9cd8321 100644 --- a/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/migration_import_rule_install/snapshots/migration_import_rule_install.md +++ b/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/migration_import_rule_install/snapshots/migration_import_rule_install.md @@ -65,6 +65,7 @@ test("template", () => {}); "private": true, "type": "module", "devDependencies": { + "vite": "catalog:", "vitest": "catalog:" } } diff --git a/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/migration_import_rule_template_dependency/snapshots/migration_import_rule_preserved_dependency_owners.md b/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/migration_import_rule_template_dependency/snapshots/migration_import_rule_preserved_dependency_owners.md index eb56b2a3e6..951315bd18 100644 --- a/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/migration_import_rule_template_dependency/snapshots/migration_import_rule_preserved_dependency_owners.md +++ b/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/migration_import_rule_template_dependency/snapshots/migration_import_rule_preserved_dependency_owners.md @@ -53,6 +53,7 @@ import { test } from 'vitest'; test('starter', () => {}); { "devDependencies": { + "vite": "catalog:", "vitest": "catalog:", "vite-plus": "catalog:" }, @@ -73,6 +74,7 @@ export { page }; "devDependencies": { "@vitest/browser": "catalog:", "@vitest/browser-preview": "catalog:", + "vite": "catalog:", "vitest": "catalog:", "vite-plus": "catalog:" }, @@ -93,6 +95,7 @@ import 'vite-plus/test/browser-preview'; export { page }; { "devDependencies": { + "vite": "catalog:", "vitest": "catalog:", "vite-plus": "catalog:" }, diff --git a/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/migration_import_rule_template_dependency/snapshots/migration_import_rule_template_dependency.md b/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/migration_import_rule_template_dependency/snapshots/migration_import_rule_template_dependency.md index 4e65297ef1..1b8578048d 100644 --- a/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/migration_import_rule_template_dependency/snapshots/migration_import_rule_template_dependency.md +++ b/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/migration_import_rule_template_dependency/snapshots/migration_import_rule_template_dependency.md @@ -28,6 +28,7 @@ test('starter', () => {}); "private": true, "type": "module", "devDependencies": { + "vite": "catalog:", "vitest": "catalog:", "vite-plus": "catalog:" } @@ -102,6 +103,7 @@ This project is already using Vite+! Happy coding! "private": true, "type": "module", "devDependencies": { + "vite": "catalog:", "vitest": "catalog:", "vite-plus": "catalog:" } diff --git a/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/migration_monorepo_root_vitest_adjacent/snapshots/migration_monorepo_root_vitest_adjacent.md b/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/migration_monorepo_root_vitest_adjacent/snapshots/migration_monorepo_root_vitest_adjacent.md index 78e65ae87e..5168dbe052 100644 --- a/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/migration_monorepo_root_vitest_adjacent/snapshots/migration_monorepo_root_vitest_adjacent.md +++ b/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/migration_monorepo_root_vitest_adjacent/snapshots/migration_monorepo_root_vitest_adjacent.md @@ -30,6 +30,7 @@ vitest pinned at the root even though vite-plus is injected first "prepare": "vp config" }, "devDependencies": { + "vite": "catalog:", "vitest-browser-svelte": "^2.1.0", "vite-plus": "catalog:", "vitest": "catalog:" diff --git a/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/migration_pnpm_vite_identity/check-identity.mjs b/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/migration_pnpm_vite_identity/check-identity.mjs index 5d1ef9cad9..26aba5a1b3 100644 --- a/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/migration_pnpm_vite_identity/check-identity.mjs +++ b/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/migration_pnpm_vite_identity/check-identity.mjs @@ -7,7 +7,7 @@ for (const directory of ['.', 'packages/utils', 'packages/app']) { const manifest = project('./package.json'); const cliPath = project.resolve('vite-plus/package.json'); const cli = createRequire(cliPath); - const vitestPath = cli.resolve('vitest/package.json'); + const vitestPath = cli.resolve('vitest'); const vitest = createRequire(vitestPath); const vitePath = cli.resolve('vite/package.json'); @@ -15,8 +15,13 @@ for (const directory of ['.', 'packages/utils', 'packages/app']) { // separate core instance, when its consumer has no direct Vite dependency. assert.equal(vitest.resolve('vite/package.json'), vitePath); assert.equal(cli('vite/package.json').name, '@voidzero-dev/vite-plus-core'); - if (directory === 'packages/app') { - assert.ok(manifest.devDependencies.vite, 'preserve the existing Vite dependency'); + const usesVitestUi = manifest.devDependencies['@vitest/ui'] !== undefined; + if (usesVitestUi) { + assert.ok(manifest.devDependencies.vitest); + assert.equal(project.resolve('vitest'), vitestPath); + } + if (directory === 'packages/app' || usesVitestUi) { + assert.ok(manifest.devDependencies.vite); assert.equal(project.resolve('vite/package.json'), vitePath); } else { assert.equal(manifest.devDependencies.vite, undefined, `${directory} needs no direct Vite`); @@ -28,5 +33,4 @@ for (const directory of ['.', 'packages/utils', 'packages/app']) { for (const [name, paths] of Object.entries(instances)) { assert.equal(paths.size, 1, `${name} must have one instance across the workspace`); } -console.log('Root and utils have no direct Vite; app keeps its declared Vite'); console.log('All packages share one Vite+, bundled Vite, and Vitest instance'); diff --git a/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/migration_pnpm_vite_identity/snapshots.toml b/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/migration_pnpm_vite_identity/snapshots.toml index 8b48964897..a97632e220 100644 --- a/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/migration_pnpm_vite_identity/snapshots.toml +++ b/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/migration_pnpm_vite_identity/snapshots.toml @@ -2,8 +2,9 @@ name = "pnpm_peer_identity_and_test_cache" vp = "global" local-registry = true -comment = "Regression for #1932: a root and utility package without direct Vite must share the app's core and Vitest instances, and test tasks must cache." +comment = "The root's direct Vitest and the utility package's bundled Vitest must share the app's core and runner, and test tasks must cache." steps = [ + { argv = ["vpt", "json-edit", "package.json", "devDependencies.@vitest/ui", "5.1.1"], snapshot = false }, { argv = ["vp", "migrate", "--full", "--no-interactive", "--no-hooks", "--no-agent", "--no-editor"], snapshot = false }, { argv = ["vp", "install", "--ignore-scripts"], snapshot = false }, ["node", "check-identity.mjs"], diff --git a/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/migration_pnpm_vite_identity/snapshots/pnpm10_upgrade_peer_identity_and_test_cache.md b/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/migration_pnpm_vite_identity/snapshots/pnpm10_upgrade_peer_identity_and_test_cache.md index 9892fb62e3..5be4c93731 100644 --- a/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/migration_pnpm_vite_identity/snapshots/pnpm10_upgrade_peer_identity_and_test_cache.md +++ b/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/migration_pnpm_vite_identity/snapshots/pnpm10_upgrade_peer_identity_and_test_cache.md @@ -14,7 +14,6 @@ The existing-Vite+ upgrade path must also preserve dependency identity and cachi ## `node check-identity.mjs` ``` -Root and utils have no direct Vite; app keeps its declared Vite All packages share one Vite+, bundled Vite, and Vitest instance ``` @@ -67,6 +66,5 @@ vp run: cache hit, saved. Repeated migration must not inject Vite either. ``` -Root and utils have no direct Vite; app keeps its declared Vite All packages share one Vite+, bundled Vite, and Vitest instance ``` diff --git a/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/migration_pnpm_vite_identity/snapshots/pnpm_peer_identity_and_test_cache.md b/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/migration_pnpm_vite_identity/snapshots/pnpm_peer_identity_and_test_cache.md index 3204d8b523..85511de936 100644 --- a/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/migration_pnpm_vite_identity/snapshots/pnpm_peer_identity_and_test_cache.md +++ b/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/migration_pnpm_vite_identity/snapshots/pnpm_peer_identity_and_test_cache.md @@ -1,6 +1,9 @@ # pnpm_peer_identity_and_test_cache -Regression for #1932: a root and utility package without direct Vite must share the app's core and Vitest instances, and test tasks must cache. +The root's direct Vitest and the utility package's bundled Vitest must share the app's core and runner, and test tasks must cache. + +## `vpt json-edit package.json devDependencies.@vitest/ui 5.1.1` + ## `vp migrate --full --no-interactive --no-hooks --no-agent --no-editor` @@ -11,7 +14,6 @@ Regression for #1932: a root and utility package without direct Vite must share ## `node check-identity.mjs` ``` -Root and utils have no direct Vite; app keeps its declared Vite All packages share one Vite+, bundled Vite, and Vitest instance ``` diff --git a/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/migration_rewrite_declare_module/snapshots/migration_rewrite_declare_module.md b/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/migration_rewrite_declare_module/snapshots/migration_rewrite_declare_module.md index de54e90796..d740ecbcf3 100644 --- a/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/migration_rewrite_declare_module/snapshots/migration_rewrite_declare_module.md +++ b/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/migration_rewrite_declare_module/snapshots/migration_rewrite_declare_module.md @@ -61,6 +61,7 @@ check package.json { "name": "migration-rewrite-declare-module", "devDependencies": { + "vite": "catalog:", "vitest": "catalog:", "vite-plus": "catalog:" }, diff --git a/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/migration_upgrade_browser_peer_only_pnpm/snapshots/migration_upgrade_browser_peer_only_pnpm.md b/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/migration_upgrade_browser_peer_only_pnpm/snapshots/migration_upgrade_browser_peer_only_pnpm.md index 1ee7aa7d57..869ebf7a38 100644 --- a/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/migration_upgrade_browser_peer_only_pnpm/snapshots/migration_upgrade_browser_peer_only_pnpm.md +++ b/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/migration_upgrade_browser_peer_only_pnpm/snapshots/migration_upgrade_browser_peer_only_pnpm.md @@ -24,6 +24,7 @@ provider, Playwright, and package-local Vitest are installed { "name": "migration-upgrade-browser-peer-only-pnpm", "devDependencies": { + "vite": "catalog:", "vite-plus": "catalog:", "@vitest/browser-playwright": "catalog:", "playwright": "*", diff --git a/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/migration_upgrade_browser_source_only_pnpm/snapshots/migration_upgrade_browser_source_only_pnpm.md b/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/migration_upgrade_browser_source_only_pnpm/snapshots/migration_upgrade_browser_source_only_pnpm.md index be418e27f8..8e065b83be 100644 --- a/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/migration_upgrade_browser_source_only_pnpm/snapshots/migration_upgrade_browser_source_only_pnpm.md +++ b/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/migration_upgrade_browser_source_only_pnpm/snapshots/migration_upgrade_browser_source_only_pnpm.md @@ -30,6 +30,7 @@ provider, framework peer, and local vitest should be present { "name": "migration-upgrade-browser-source-only-pnpm", "devDependencies": { + "vite": "catalog:", "vite-plus": "catalog:", "@vitest/browser-playwright": "catalog:", "playwright": "*", diff --git a/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/migration_upgrade_browser_webdriverio_pnpm/snapshots/migrate_vitest4_community_provider.md b/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/migration_upgrade_browser_webdriverio_pnpm/snapshots/migrate_vitest4_community_provider.md index e0afce59c0..63da8c0fac 100644 --- a/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/migration_upgrade_browser_webdriverio_pnpm/snapshots/migrate_vitest4_community_provider.md +++ b/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/migration_upgrade_browser_webdriverio_pnpm/snapshots/migrate_vitest4_community_provider.md @@ -23,7 +23,7 @@ VITE+ - The Unified Toolchain for the Web ## `vpt print-file package.json` ``` -{"name":"vitest4-browser","private":true,"type":"module","packageManager":"pnpm@10.33.0","devDependencies":{"vitest":"catalog:","@vitest/browser-webdriverio":"^5.0.0","webdriverio":"^9.20.0","vite-plus":"catalog:"}} +{"name":"vitest4-browser","private":true,"type":"module","packageManager":"pnpm@10.33.0","devDependencies":{"vite":"catalog:","vitest":"catalog:","@vitest/browser-webdriverio":"^5.0.0","webdriverio":"^9.20.0","vite-plus":"catalog:"}} ``` ## `vpt print-file vite.config.ts` diff --git a/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/migration_upgrade_browser_webdriverio_pnpm/snapshots/migration_upgrade_browser_webdriverio_pnpm.md b/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/migration_upgrade_browser_webdriverio_pnpm/snapshots/migration_upgrade_browser_webdriverio_pnpm.md index 2264e3d0cf..a3dcfd4a4b 100644 --- a/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/migration_upgrade_browser_webdriverio_pnpm/snapshots/migration_upgrade_browser_webdriverio_pnpm.md +++ b/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/migration_upgrade_browser_webdriverio_pnpm/snapshots/migration_upgrade_browser_webdriverio_pnpm.md @@ -30,6 +30,7 @@ ensure the provider and its framework peer are declared { "name": "migration-upgrade-browser-webdriverio-pnpm", "devDependencies": { + "vite": "catalog:", "vite-plus": "catalog:", "vitest": "catalog:", "@vitest/browser-webdriverio": "^5.0.0", diff --git a/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/migration_upgrade_browser_webdriverio_pnpm/snapshots/preserve_community_provider_version.md b/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/migration_upgrade_browser_webdriverio_pnpm/snapshots/preserve_community_provider_version.md index 0eff0f5412..3c18707a63 100644 --- a/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/migration_upgrade_browser_webdriverio_pnpm/snapshots/preserve_community_provider_version.md +++ b/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/migration_upgrade_browser_webdriverio_pnpm/snapshots/preserve_community_provider_version.md @@ -27,6 +27,7 @@ VITE+ - The Unified Toolchain for the Web { "devDependencies": { "@vitest/browser-webdriverio": "^5.0.0", + "vite": "catalog:", "vite-plus": "catalog:", "vitest": "catalog:", "webdriverio": "*" diff --git a/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/migration_upgrade_browser_webdriverio_pnpm/snapshots/upgrade_community_provider_catalog.md b/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/migration_upgrade_browser_webdriverio_pnpm/snapshots/upgrade_community_provider_catalog.md index f93ad80924..c1fe589da6 100644 --- a/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/migration_upgrade_browser_webdriverio_pnpm/snapshots/upgrade_community_provider_catalog.md +++ b/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/migration_upgrade_browser_webdriverio_pnpm/snapshots/upgrade_community_provider_catalog.md @@ -41,6 +41,7 @@ VITE+ - The Unified Toolchain for the Web { "devDependencies": { "@vitest/browser-webdriverio": "catalog:browser", + "vite": "catalog:", "vite-plus": "catalog:", "webdriverio": "^9.20.0", "vitest": "catalog:" diff --git a/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/migration_upgrade_monorepo_vitest_localized_pnpm/snapshots/migration_upgrade_monorepo_vitest_localized_pnpm.md b/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/migration_upgrade_monorepo_vitest_localized_pnpm/snapshots/migration_upgrade_monorepo_vitest_localized_pnpm.md index 28c87514c2..4bae7f5e71 100644 --- a/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/migration_upgrade_monorepo_vitest_localized_pnpm/snapshots/migration_upgrade_monorepo_vitest_localized_pnpm.md +++ b/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/migration_upgrade_monorepo_vitest_localized_pnpm/snapshots/migration_upgrade_monorepo_vitest_localized_pnpm.md @@ -46,6 +46,7 @@ only the peer consumer should gain local vitest "name": "app", "devDependencies": { "@vitest/ui": "catalog:", + "vite": "catalog:", "vite-plus": "catalog:", "vitest": "catalog:" } diff --git a/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/migration_upgrade_nuxt_test_utils_monorepo/snapshots/migration_upgrade_nuxt_test_utils_monorepo.md b/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/migration_upgrade_nuxt_test_utils_monorepo/snapshots/migration_upgrade_nuxt_test_utils_monorepo.md index fe95d68337..f0e5b86686 100644 --- a/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/migration_upgrade_nuxt_test_utils_monorepo/snapshots/migration_upgrade_nuxt_test_utils_monorepo.md +++ b/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/migration_upgrade_nuxt_test_utils_monorepo/snapshots/migration_upgrade_nuxt_test_utils_monorepo.md @@ -27,6 +27,7 @@ affected workspace keeps direct Vitest "private": true, "devDependencies": { "@nuxt/test-utils": "file:../../.fixture/nuxt-test-utils", + "vite": "catalog:", "vitest": "catalog:" } } diff --git a/docs/guide/migrate-rules.md b/docs/guide/migrate-rules.md index 94a87b558c..ef8ad2d615 100644 --- a/docs/guide/migrate-rules.md +++ b/docs/guide/migrate-rules.md @@ -147,6 +147,8 @@ What happens to each toolchain dependency, at a glance: You can use `vite-plus` in a pnpm package without declaring `vite`. The `vite-plus` package includes a `vite` dependency aliased to its core, which provides Vitest's required peer. Migration keeps the workspace override for other Vite consumers but does not add `vite` to a package solely because it uses `vite-plus`. +When a pnpm package installs `vitest` directly and has no `vite` declaration, migration adds the core alias to its `devDependencies`. This gives Vitest the same Vite peer in both the project and Vite+, so plugins such as `@cloudflare/vitest-plugin` register tests with the runner used by `vp test`. + Related rules: - A direct `vite` declaration is never removed merely because a root override exists. diff --git a/packages/cli/src/migration/__tests__/migrator.spec.ts b/packages/cli/src/migration/__tests__/migrator.spec.ts index b306677972..7868c71de7 100644 --- a/packages/cli/src/migration/__tests__/migrator.spec.ts +++ b/packages/cli/src/migration/__tests__/migrator.spec.ts @@ -360,6 +360,21 @@ describe('rewritePackageJson', () => { // Vite+ now supplies its own Vite alias. The #1932 install-layout and cache // regression is covered by the migration_pnpm_vite_identity CLI fixture. describe('pnpm Vite dependencies', () => { + it.each([ + [true, 'catalog:'], + [false, VITE_PLUS_OVERRIDE_PACKAGES.vite], + ] as const)( + 'supplies the Vite peer for a direct Vitest install (catalogs: %s)', + (catalogs, vite) => { + const pkg = { devDependencies: { '@cloudflare/vitest-plugin': '1.8.4' } }; + rewritePackageJson(pkg, PackageManager.pnpm, catalogs); + expect(pkg.devDependencies).toMatchObject({ + vite, + vitest: catalogs ? 'catalog:' : VITEST_VERSION, + }); + }, + ); + it('does not add `vite` just because a package depends on vite-plus', () => { const sub = { devDependencies: { 'vite-plus': 'catalog:' }, @@ -405,7 +420,7 @@ describe('rewritePackageJson', () => { // A vite plugin that pins `vite` as a peer must keep its own contract; // injecting vite-plus-core as a concrete devDep would conflict with it. const pkg = { - devDependencies: { 'vite-plus': 'catalog:' }, + devDependencies: { 'vite-plus': 'catalog:', vitest: 'catalog:' }, peerDependencies: { vite: '^6.0.0' }, }; rewritePackageJson(pkg, PackageManager.pnpm, true); @@ -416,7 +431,7 @@ describe('rewritePackageJson', () => { it('does not add a second vite when an empty-string vite spec is already declared under pnpm', () => { const pkg = { dependencies: { vite: '' }, - devDependencies: { 'vite-plus': 'catalog:' }, + devDependencies: { 'vite-plus': 'catalog:', vitest: 'catalog:' }, }; rewritePackageJson(pkg, PackageManager.pnpm, true); expect(fixtureObject(pkg, 'devDependencies').vite).toBeUndefined(); @@ -658,18 +673,20 @@ describe('rewritePackageJson', () => { expect(pkg.devDependencies).not.toHaveProperty('vite'); }); - it('does not inject a direct vite for pnpm/yarn/bun browser projects', async () => { - for (const pm of [PackageManager.pnpm, PackageManager.yarn, PackageManager.bun]) { - const pkg = { - devDependencies: { - '@vitest/browser-playwright': '^4.0.0', - playwright: '^1.60.0', - vitest: '^4.0.0', - }, - }; - rewritePackageJson(pkg, pm); - expect(pkg.devDependencies).not.toHaveProperty('vite'); - } + it.each([ + [PackageManager.pnpm, VITE_PLUS_OVERRIDE_PACKAGES.vite], + [PackageManager.yarn, undefined], + [PackageManager.bun, undefined], + ] as const)('rewrites the Vite peer for a %s browser project', (pm, vite) => { + const pkg = { + devDependencies: { + '@vitest/browser-playwright': '^4.0.0', + playwright: '^1.60.0', + vitest: '^4.0.0', + }, + }; + rewritePackageJson(pkg, pm); + expect(fixtureObject(pkg, 'devDependencies').vite).toBe(vite); }); it('normalizes a pre-existing direct vite dep to the override target for an npm provider project', async () => { @@ -2513,6 +2530,30 @@ describe('ensureVitePlusBootstrap', () => { expect(pkg.devDependencies).toEqual({ 'vite-plus': 'catalog:' }); }); + it('repairs a missing Vite peer on a previously migrated pnpm Vitest project', () => { + const manifest = path.join(tmpDir, 'package.json'); + const workspace = makeWorkspaceInfo(tmpDir, PackageManager.pnpm, '10.26.2'); + fs.writeFileSync( + manifest, + JSON.stringify({ + name: 'worker', + devDependencies: { + '@cloudflare/vitest-plugin': '1.8.4', + 'vite-plus': 'catalog:', + vitest: 'catalog:', + }, + }), + ); + ensureVitePlusBootstrap(workspace); + const pkg = readJson(manifest); + delete fixtureObject(pkg, 'devDependencies').vite; + fs.writeFileSync(manifest, JSON.stringify(pkg)); + + checkBootstrapPass(workspace, true); + expect(readJson(manifest)).toHaveProperty(['devDependencies', 'vite'], 'catalog:'); + checkBootstrapPass(workspace, false); + }); + it('removes the stale vitest wrapper override for a non-vitest npm project', () => { fs.writeFileSync( path.join(tmpDir, 'package.json'), diff --git a/packages/cli/src/migration/bin.ts b/packages/cli/src/migration/bin.ts index ff7c6b4cbf..2e9d247449 100644 --- a/packages/cli/src/migration/bin.ts +++ b/packages/cli/src/migration/bin.ts @@ -1365,6 +1365,9 @@ async function main() { // Runtime metadata can participate in the package manager's lockfile. let needsInstall = coreMigrationResult.dependencies || nodeUpgrades > 0; + // A config that only loads after install may let us drop a provisional + // Vitest dependency. Remove its Vite peer only if this migration added it. + const addedVitePeers = importRuleConfig === null ? new Set() : undefined; async function reconcileBootstrap(dependencies: RetainedImportDependencies): Promise { const resolved = await ensureExistingPackageManager(); updateMigrationProgress('Configuring package manager'); @@ -1372,6 +1375,7 @@ async function main() { { ...workspaceInfoOptional, ...resolved }, report, dependencies, + addedVitePeers, ).changed; } if (vitePlusBootstrapPending && (await reconcileBootstrap(retainedImportDependencies))) { diff --git a/packages/cli/src/migration/migrator/catalog.ts b/packages/cli/src/migration/migrator/catalog.ts index a50edc4c3f..422067991c 100644 --- a/packages/cli/src/migration/migrator/catalog.ts +++ b/packages/cli/src/migration/migrator/catalog.ts @@ -55,6 +55,7 @@ import { } from '../migrator.ts'; import type { MigrationReport } from '../report.ts'; import type { + DependencyBag, PreparedOxlintConfigs, RetainedImportDependencies, PackageJsonDependencyField, @@ -66,6 +67,7 @@ import { PROVIDER_OVERRIDE_DROP_NAMES, OPT_IN_BROWSER_PROVIDERS, bundledPackagesToRemove, + findDeclaredSpec, VITEST_IS_MANAGED_OVERRIDE, isPlainRecord, pinnedPackageManagerVersion, @@ -744,6 +746,29 @@ export function setDirectViteEdge( Object.assign(target, Object.fromEntries(entries)); } +// pnpm can auto-install upstream Vite for a package-local Vitest despite the +// workspace override. Supply the same Vite peer as vite-plus so both resolve +// to one Vitest instance (#3619). +export function ensurePnpmVitestVitePeer( + pkg: DependencyBag, + packageManager: PackageManager, + supportCatalog: boolean, + catalogDependencyResolver?: CatalogDependencyResolver, +): boolean { + if ( + packageManager === PackageManager.pnpm && + VITE_PLUS_OVERRIDE_PACKAGES.vite && + findDeclaredSpec(pkg, 'vite') === undefined && + [pkg.dependencies, pkg.devDependencies, pkg.optionalDependencies].some( + (deps) => deps?.vitest !== undefined, + ) + ) { + setDirectViteEdge(pkg, supportCatalog, catalogDependencyResolver); + return true; + } + return false; +} + // A peer declaration does not install Vitest and therefore must not keep a // workspace-wide managed Vitest catalog alive. Resolve its catalog reference to // the public peer range before that catalog is pruned, so the surviving peer diff --git a/packages/cli/src/migration/migrator/package-json.ts b/packages/cli/src/migration/migrator/package-json.ts index 8842463c28..99485d1498 100644 --- a/packages/cli/src/migration/migrator/package-json.ts +++ b/packages/cli/src/migration/migrator/package-json.ts @@ -11,6 +11,7 @@ import { import { VITEST_DIRECT_USAGE_EXCLUDED, alignVitestEcosystemPackages, + ensurePnpmVitestVitePeer, getAlignedVitestEcosystemDependencySpec, getCatalogDependencySpec, getScriptRulesYaml, @@ -394,9 +395,6 @@ export function rewritePackageJson( [VITE_PLUS_NAME]: canonicalVitePlusSpec, }; } - // Vite+ supplies its own `vite` alias for Vitest's peer dependency. Unlike - // the pre-#2617 package layout, pnpm consumers do not need an extra direct - // Vite dependency just to use Vite+. Keep existing declarations above. // Add `vitest` as a direct devDependency when: // - a remaining dependency likely peer-depends on vitest (e.g. // vitest-browser-svelte), OR @@ -435,6 +433,7 @@ export function rewritePackageJson( ); } } + ensurePnpmVitestVitePeer(pkg, packageManager, supportCatalog, catalogDependencyResolver); return extractedStagedConfig; } diff --git a/packages/cli/src/migration/migrator/vite-plus-bootstrap.ts b/packages/cli/src/migration/migrator/vite-plus-bootstrap.ts index bcb0737a07..9e4d5aad2f 100644 --- a/packages/cli/src/migration/migrator/vite-plus-bootstrap.ts +++ b/packages/cli/src/migration/migrator/vite-plus-bootstrap.ts @@ -19,6 +19,7 @@ import { editYamlFile, readYamlFile } from '../../utils/yaml.ts'; import type { PnpmPeerDependencyRuleKeys } from '../migrator.ts'; import { alignVitestEcosystemPackages, + ensurePnpmVitestVitePeer, applyBuildAllowanceToPackageJsonPnpm, applyYarnWorkspaceHoistingFix, collectProviderSourceModes, @@ -304,6 +305,7 @@ function reconcileVitePlusBootstrapPackage( // An installed provider references the shared catalog entry added for a sibling. browserCatalogAdditions: ReadonlySet = new Set(), retainedImportDependencies?: RetainedImportDependencies, + addedVitePeers?: Set, ): boolean { const before = JSON.stringify(pkg); const usesVitest = @@ -491,10 +493,15 @@ function reconcileVitePlusBootstrapPackage( // into every project. Remove that stale install pin when no remaining peer, // source import, or browser-mode signal needs it. for (const dependencies of installGroups) { - removeManagedVitestEntry(dependencies); + if (removeManagedVitestEntry(dependencies) && addedVitePeers?.delete(projectPath)) { + delete pkg.devDependencies?.vite; + } } } + if (ensurePnpmVitestVitePeer(pkg, packageManager, supportCatalog, catalogDependencyResolver)) { + addedVitePeers?.add(projectPath); + } return before !== JSON.stringify(pkg); } @@ -969,6 +976,7 @@ export function ensureVitePlusBootstrap( workspaceInfo: WorkspaceInfo, report?: MigrationReport, retainedImportDependencies?: RetainedImportDependencies, + addedVitePeers?: Set, ): VitePlusBootstrapResult { const projectPath = workspaceInfo.rootDir; const packageJsonPath = path.join(projectPath, 'package.json'); @@ -1084,6 +1092,7 @@ export function ensureVitePlusBootstrap( catalogDependencyResolver, browserCatalogAdditions, retainedImportDependencies, + addedVitePeers, ); if (workspaceInfo.packageManager === PackageManager.yarn) { @@ -1184,6 +1193,7 @@ export function ensureVitePlusBootstrap( catalogDependencyResolver, browserCatalogAdditions, retainedImportDependencies, + addedVitePeers, ); if ( yarnHoisting && From 8503a804b209fc5a90e79e6f42787e410c7f2fd3 Mon Sep 17 00:00:00 2001 From: "gxc.510" Date: Mon, 30 Nov 2026 12:42:35 +0800 Subject: [PATCH 2/5] fix(migrate): defer the Vite peer until Vitest ownership is known Change-Id: I93a5811901d7b3bf1f6d6b27ebed8fc279246789 --- .../snapshots.toml | 4 +-- ...10_upgrade_peer_identity_and_test_cache.md | 4 +-- .../package.json | 1 - .../snapshots.toml | 5 ++-- .../migration_vitest_unmanaged_override.md | 22 +++++++++++++-- docs/guide/migrate-rules.md | 2 +- .../src/migration/__tests__/migrator.spec.ts | 28 +++++++++++++++++++ packages/cli/src/migration/bin.ts | 28 +++++++++++-------- .../cli/src/migration/migrator/catalog.ts | 5 ++-- .../src/migration/migrator/package-json.ts | 4 +-- .../migration/migrator/vite-plus-bootstrap.ts | 18 ++++++------ 11 files changed, 83 insertions(+), 38 deletions(-) diff --git a/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/migration_pnpm_vite_identity/snapshots.toml b/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/migration_pnpm_vite_identity/snapshots.toml index a97632e220..5e4e0cafe5 100644 --- a/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/migration_pnpm_vite_identity/snapshots.toml +++ b/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/migration_pnpm_vite_identity/snapshots.toml @@ -18,7 +18,7 @@ vp = "global" # Dependency installation is slow on Linux CI. skip-platforms = ["linux"] local-registry = true -comment = "The existing-Vite+ upgrade path must also preserve dependency identity and caching without injecting Vite, including on pnpm 10." +comment = "The pnpm 10 upgrade preserves dependency identity and caching when the root and utility use the bundled Vitest." steps = [ { argv = ["vpt", "json-edit", "package.json", "packageManager", "pnpm@10.33.0"], snapshot = false }, { argv = ["vp", "migrate", "--no-interactive"], snapshot = false }, @@ -27,5 +27,5 @@ steps = [ { argv = ["vp", "run", "test"], cwd = "packages/utils", comment = "First run populates the test cache." }, { argv = ["vp", "run", "test"], cwd = "packages/utils", comment = "Second run must hit the cache." }, { argv = ["vp", "migrate", "--no-interactive"], snapshot = false }, - { argv = ["node", "check-identity.mjs"], comment = "Repeated migration must not inject Vite either." }, + { argv = ["node", "check-identity.mjs"], comment = "Repeated migration keeps Vite out of packages that only use the bundled Vitest." }, ] diff --git a/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/migration_pnpm_vite_identity/snapshots/pnpm10_upgrade_peer_identity_and_test_cache.md b/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/migration_pnpm_vite_identity/snapshots/pnpm10_upgrade_peer_identity_and_test_cache.md index 5be4c93731..dc3a0d521e 100644 --- a/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/migration_pnpm_vite_identity/snapshots/pnpm10_upgrade_peer_identity_and_test_cache.md +++ b/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/migration_pnpm_vite_identity/snapshots/pnpm10_upgrade_peer_identity_and_test_cache.md @@ -1,6 +1,6 @@ # pnpm10_upgrade_peer_identity_and_test_cache -The existing-Vite+ upgrade path must also preserve dependency identity and caching without injecting Vite, including on pnpm 10. +The pnpm 10 upgrade preserves dependency identity and caching when the root and utility use the bundled Vitest. ## `vpt json-edit package.json packageManager pnpm@10.33.0` @@ -63,7 +63,7 @@ vp run: cache hit, saved. ## `node check-identity.mjs` -Repeated migration must not inject Vite either. +Repeated migration keeps Vite out of packages that only use the bundled Vitest. ``` All packages share one Vite+, bundled Vite, and Vitest instance diff --git a/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/migration_vitest_unmanaged_override/package.json b/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/migration_vitest_unmanaged_override/package.json index 184290e34f..1a1d684120 100644 --- a/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/migration_vitest_unmanaged_override/package.json +++ b/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/migration_vitest_unmanaged_override/package.json @@ -5,7 +5,6 @@ }, "devDependencies": { "@vitest/ui": "4.0.13", - "vite": "^7.0.0", "vitest": "4.0.13" } } diff --git a/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/migration_vitest_unmanaged_override/snapshots.toml b/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/migration_vitest_unmanaged_override/snapshots.toml index 3ebb1a7ddb..f2be57801e 100644 --- a/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/migration_vitest_unmanaged_override/snapshots.toml +++ b/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/migration_vitest_unmanaged_override/snapshots.toml @@ -4,7 +4,8 @@ vp = "global" env = { VP_OVERRIDE_PACKAGES = "{\"vite\":\"npm:@voidzero-dev/vite-plus-core@latest\"}" } steps = [ { argv = ["vp", "migrate", "--no-interactive"], comment = "vitest omitted from managed overrides must remain user-owned", continue-on-failure = true }, - { argv = ["vpt", "print-file", "package.json"], comment = "user's Vitest and @vitest/ui stay direct devDependencies (not converted to catalog:), so they remain user-owned", continue-on-failure = true }, + { argv = ["vpt", "print-file", "package.json"], comment = "The project keeps its Vitest and @vitest/ui versions without gaining a direct Vite dependency.", continue-on-failure = true }, { argv = ["vpt", "print-file", "pnpm-workspace.yaml"], comment = "no vitest catalog or override should be introduced", continue-on-failure = true }, - { argv = ["vp", "migrate", "--no-interactive"], comment = "unmanaged Vitest ecosystem versions remain stable on rerun", continue-on-failure = true }, + { argv = ["vp", "migrate", "--no-interactive"], comment = "Run the existing-project upgrade with the same unmanaged Vitest.", continue-on-failure = true }, + ["vpt", "print-file", "package.json"], ] diff --git a/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/migration_vitest_unmanaged_override/snapshots/migration_vitest_unmanaged_override.md b/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/migration_vitest_unmanaged_override/snapshots/migration_vitest_unmanaged_override.md index 093f671893..76d8e4cb62 100644 --- a/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/migration_vitest_unmanaged_override/snapshots/migration_vitest_unmanaged_override.md +++ b/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/migration_vitest_unmanaged_override/snapshots/migration_vitest_unmanaged_override.md @@ -14,7 +14,7 @@ VITE+ - The Unified Toolchain for the Web ## `vpt print-file package.json` -user's Vitest and @vitest/ui stay direct devDependencies (not converted to catalog:), so they remain user-owned +The project keeps its Vitest and @vitest/ui versions without gaining a direct Vite dependency. ``` { @@ -25,7 +25,6 @@ user's Vitest and @vitest/ui stay direct devDependencies (not converted to catal }, "devDependencies": { "@vitest/ui": "", - "vite": "catalog:", "vitest": "", "vite-plus": "catalog:" } @@ -51,7 +50,7 @@ peerDependencyRules: ## `vp migrate --no-interactive` -unmanaged Vitest ecosystem versions remain stable on rerun +Run the existing-project upgrade with the same unmanaged Vitest. ``` VITE+ - The Unified Toolchain for the Web @@ -64,3 +63,20 @@ VITE+ - The Unified Toolchain for the Web vitest 4.0.13 → @vitest/ui 4.0.13 → ``` + +## `vpt print-file package.json` + +``` +{ + "name": "migration-vitest-unmanaged-override", + "scripts": { + "test": "vp test", + "prepare": "vp config" + }, + "devDependencies": { + "@vitest/ui": "", + "vitest": "", + "vite-plus": "catalog:" + } +} +``` diff --git a/docs/guide/migrate-rules.md b/docs/guide/migrate-rules.md index ef8ad2d615..82f7bdad6b 100644 --- a/docs/guide/migrate-rules.md +++ b/docs/guide/migrate-rules.md @@ -147,7 +147,7 @@ What happens to each toolchain dependency, at a glance: You can use `vite-plus` in a pnpm package without declaring `vite`. The `vite-plus` package includes a `vite` dependency aliased to its core, which provides Vitest's required peer. Migration keeps the workspace override for other Vite consumers but does not add `vite` to a package solely because it uses `vite-plus`. -When a pnpm package installs `vitest` directly and has no `vite` declaration, migration adds the core alias to its `devDependencies`. This gives Vitest the same Vite peer in both the project and Vite+, so plugins such as `@cloudflare/vitest-plugin` register tests with the runner used by `vp test`. +When a pnpm package directly installs the Vite+-managed `vitest` and has no `vite` declaration, migration adds the core alias to its `devDependencies` for local testing. This gives Vitest the same Vite peer in both the project and Vite+, so plugins such as `@cloudflare/vitest-plugin` register tests with the runner used by `vp test`. Packages that already declare `peerDependencies.vite` keep their public peer range. Related rules: diff --git a/packages/cli/src/migration/__tests__/migrator.spec.ts b/packages/cli/src/migration/__tests__/migrator.spec.ts index 7868c71de7..e3ac3d998c 100644 --- a/packages/cli/src/migration/__tests__/migrator.spec.ts +++ b/packages/cli/src/migration/__tests__/migrator.spec.ts @@ -2530,6 +2530,34 @@ describe('ensureVitePlusBootstrap', () => { expect(pkg.devDependencies).toEqual({ 'vite-plus': 'catalog:' }); }); + it.each([true, false])( + 'reconciles a provisional pnpm Vitest on retry (import retained: %s)', + (retained) => { + const manifest = path.join(tmpDir, 'package.json'); + const workspace = makeWorkspaceInfo(tmpDir, PackageManager.pnpm, '10.26.2'); + fs.writeFileSync( + manifest, + JSON.stringify({ name: 'app', devDependencies: { 'vite-plus': 'latest', vitest: '^5' } }), + ); + const imports = { vitest: new Set([tmpDir]), browser: new Map>() }; + ensureVitePlusBootstrap(workspace, undefined, imports, true); + expect(readJson(manifest).devDependencies).toEqual({ + 'vite-plus': 'catalog:', + vitest: 'catalog:', + }); + + // A retry has only the manifest left by the interrupted install. + const resolved = { ...imports, vitest: retained ? new Set([tmpDir]) : new Set() }; + ensureVitePlusBootstrap(workspace, undefined, resolved); + expect(readJson(manifest).devDependencies).toEqual( + retained + ? { vite: 'catalog:', 'vite-plus': 'catalog:', vitest: 'catalog:' } + : { 'vite-plus': 'catalog:' }, + ); + expect(ensureVitePlusBootstrap(workspace, undefined, resolved).changed).toBe(false); + }, + ); + it('repairs a missing Vite peer on a previously migrated pnpm Vitest project', () => { const manifest = path.join(tmpDir, 'package.json'); const workspace = makeWorkspaceInfo(tmpDir, PackageManager.pnpm, '10.26.2'); diff --git a/packages/cli/src/migration/bin.ts b/packages/cli/src/migration/bin.ts index 2e9d247449..6258e14e1c 100644 --- a/packages/cli/src/migration/bin.ts +++ b/packages/cli/src/migration/bin.ts @@ -1,6 +1,6 @@ import fs from 'node:fs'; import path from 'node:path'; -import { isDeepStrictEqual, styleText } from 'node:util'; +import { styleText } from 'node:util'; import { confirm as promptConfirm, @@ -1365,22 +1365,27 @@ async function main() { // Runtime metadata can participate in the package manager's lockfile. let needsInstall = coreMigrationResult.dependencies || nodeUpgrades > 0; - // A config that only loads after install may let us drop a provisional - // Vitest dependency. Remove its Vite peer only if this migration added it. - const addedVitePeers = importRuleConfig === null ? new Set() : undefined; - async function reconcileBootstrap(dependencies: RetainedImportDependencies): Promise { + async function reconcileBootstrap( + dependencies: RetainedImportDependencies, + deferRetainedImportVitePeers = false, + ): Promise { const resolved = await ensureExistingPackageManager(); updateMigrationProgress('Configuring package manager'); return ensureVitePlusBootstrap( { ...workspaceInfoOptional, ...resolved }, report, dependencies, - addedVitePeers, + deferRetainedImportVitePeers, ).changed; } - if (vitePlusBootstrapPending && (await reconcileBootstrap(retainedImportDependencies))) { - didMigrate = true; - needsInstall = true; + if (vitePlusBootstrapPending) { + const changed = await reconcileBootstrap( + retainedImportDependencies, + importRuleConfig === null, + ); + didMigrate ||= changed; + // Even if the only pending change was deferred, install to load the config. + needsInstall ||= changed || importRuleConfig === null; } let fixBaseUrl = false; @@ -1725,10 +1730,9 @@ async function main() { oxlintOwnerDirs: deferredOxlintOwnerDirs, importRuleConfig: resolvedImportRuleConfig ?? DISABLED_IMPORT_RULE_CONFIG, }) || didMigrate; - // The first install used the owners we could identify without loading - // the config. Sync again only if the resolved rule changes dependencies. + // The resolved rule can drop a provisional Vitest or confirm it needs a Vite peer. if ( - !isDeepStrictEqual(resolvedDependencies, retainedImportDependencies) && + resolvedImportRuleConfig !== null && bootstrapPending(resolvedDependencies) && (await reconcileBootstrap(resolvedDependencies)) ) { diff --git a/packages/cli/src/migration/migrator/catalog.ts b/packages/cli/src/migration/migrator/catalog.ts index 422067991c..f75257e1cc 100644 --- a/packages/cli/src/migration/migrator/catalog.ts +++ b/packages/cli/src/migration/migrator/catalog.ts @@ -754,9 +754,10 @@ export function ensurePnpmVitestVitePeer( packageManager: PackageManager, supportCatalog: boolean, catalogDependencyResolver?: CatalogDependencyResolver, -): boolean { +): void { if ( packageManager === PackageManager.pnpm && + VITEST_IS_MANAGED_OVERRIDE && VITE_PLUS_OVERRIDE_PACKAGES.vite && findDeclaredSpec(pkg, 'vite') === undefined && [pkg.dependencies, pkg.devDependencies, pkg.optionalDependencies].some( @@ -764,9 +765,7 @@ export function ensurePnpmVitestVitePeer( ) ) { setDirectViteEdge(pkg, supportCatalog, catalogDependencyResolver); - return true; } - return false; } // A peer declaration does not install Vitest and therefore must not keep a diff --git a/packages/cli/src/migration/migrator/package-json.ts b/packages/cli/src/migration/migrator/package-json.ts index 99485d1498..1c00d52e52 100644 --- a/packages/cli/src/migration/migrator/package-json.ts +++ b/packages/cli/src/migration/migrator/package-json.ts @@ -403,9 +403,7 @@ export function rewritePackageJson( // Vite-plus already bundles upstream vitest as a direct dep, but a strict // pnpm / yarn Plug'n'Play layout will not expose that transitive `vitest` // to the package. Pinning it here points the dep at the same upstream - // version vite-plus ships with. Gated by needDirectVitest (browser-mode / - // vitest-adjacent, or some other change) — a pure normalize pass must not - // mutate the project beyond the vite-plus spec. + // version vite-plus ships with. if (needDirectVitest) { const installableDeps = { ...pkg.dependencies, diff --git a/packages/cli/src/migration/migrator/vite-plus-bootstrap.ts b/packages/cli/src/migration/migrator/vite-plus-bootstrap.ts index 9e4d5aad2f..8095e3022f 100644 --- a/packages/cli/src/migration/migrator/vite-plus-bootstrap.ts +++ b/packages/cli/src/migration/migrator/vite-plus-bootstrap.ts @@ -305,7 +305,7 @@ function reconcileVitePlusBootstrapPackage( // An installed provider references the shared catalog entry added for a sibling. browserCatalogAdditions: ReadonlySet = new Set(), retainedImportDependencies?: RetainedImportDependencies, - addedVitePeers?: Set, + deferRetainedImportVitePeers = false, ): boolean { const before = JSON.stringify(pkg); const usesVitest = @@ -493,14 +493,14 @@ function reconcileVitePlusBootstrapPackage( // into every project. Remove that stale install pin when no remaining peer, // source import, or browser-mode signal needs it. for (const dependencies of installGroups) { - if (removeManagedVitestEntry(dependencies) && addedVitePeers?.delete(projectPath)) { - delete pkg.devDependencies?.vite; - } + removeManagedVitestEntry(dependencies); } } - if (ensurePnpmVitestVitePeer(pkg, packageManager, supportCatalog, catalogDependencyResolver)) { - addedVitePeers?.add(projectPath); + // The lint config may be unavailable until install. Wait before adding Vite for + // a provisional import so a failed or interrupted install leaves no stale peer. + if (!(deferRetainedImportVitePeers && retainedImportDependencies?.vitest.has(projectPath))) { + ensurePnpmVitestVitePeer(pkg, packageManager, supportCatalog, catalogDependencyResolver); } return before !== JSON.stringify(pkg); } @@ -976,7 +976,7 @@ export function ensureVitePlusBootstrap( workspaceInfo: WorkspaceInfo, report?: MigrationReport, retainedImportDependencies?: RetainedImportDependencies, - addedVitePeers?: Set, + deferRetainedImportVitePeers = false, ): VitePlusBootstrapResult { const projectPath = workspaceInfo.rootDir; const packageJsonPath = path.join(projectPath, 'package.json'); @@ -1092,7 +1092,7 @@ export function ensureVitePlusBootstrap( catalogDependencyResolver, browserCatalogAdditions, retainedImportDependencies, - addedVitePeers, + deferRetainedImportVitePeers, ); if (workspaceInfo.packageManager === PackageManager.yarn) { @@ -1193,7 +1193,7 @@ export function ensureVitePlusBootstrap( catalogDependencyResolver, browserCatalogAdditions, retainedImportDependencies, - addedVitePeers, + deferRetainedImportVitePeers, ); if ( yarnHoisting && From e5f315298c34379168e7ffd2852baff22b3dcce2 Mon Sep 17 00:00:00 2001 From: "gxc.510" Date: Mon, 30 Nov 2026 12:57:42 +0800 Subject: [PATCH 3/5] fix(migrate): settle pnpm Vitest peers when lint config cannot load Change-Id: I28beac8e1561486e6cab5c9761fc8f242309cfcc --- .../snapshots.toml | 20 ++++++ ...esolved_lint_config_retains_vitest_peer.md | 69 +++++++++++++++++++ .../check-identity.mjs | 6 +- .../snapshots.toml | 6 +- ...10_upgrade_peer_identity_and_test_cache.md | 10 ++- .../package.json | 1 + .../snapshots.toml | 15 +++- .../migration_vitest_unmanaged_override.md | 22 +----- .../unmanaged_vitest_without_vite.md | 46 +++++++++++++ docs/guide/migrate-rules.md | 2 +- .../src/migration/__tests__/migrator.spec.ts | 34 ++++++++- packages/cli/src/migration/bin.ts | 18 +++-- .../src/migration/migrator/package-json.ts | 2 + .../migration/migrator/vite-plus-bootstrap.ts | 21 ++++-- .../migration/migrator/vitest-ecosystem.ts | 3 +- 15 files changed, 232 insertions(+), 43 deletions(-) create mode 100644 crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/migration_import_rule_install/snapshots/unresolved_lint_config_retains_vitest_peer.md create mode 100644 crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/migration_vitest_unmanaged_override/snapshots/unmanaged_vitest_without_vite.md diff --git a/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/migration_import_rule_install/snapshots.toml b/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/migration_import_rule_install/snapshots.toml index caf772f3e6..e94f2e628a 100644 --- a/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/migration_import_rule_install/snapshots.toml +++ b/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/migration_import_rule_install/snapshots.toml @@ -40,3 +40,23 @@ steps = [ ["vp", "migrate", "--no-interactive", "--no-hooks", "--no-agent", "--no-editor"], ["vpt", "stat-file", "install-requested", "--assert", "missing"], ] + +[[case]] +name = "unresolved_lint_config_retains_vitest_peer" +vp = "local" +local-registry = true +unset-env = ["VP_SKIP_INSTALL"] +comment = "A config that still throws after install keeps the upstream Vitest import and its Vite peer. Rerunning migration does not reinstall." +steps = [ + { argv = ["vpt", "json-edit", "package.json", "devDependencies.vitest", "5.1.1"], snapshot = false }, + { argv = ["vpt", "write-file", "vite.config.ts", "export default () => { throw new Error('missing project setting'); };\n"], snapshot = false }, + { argv = ["vpt", "write-file", ".pnpmfile.cjs", "require('node:fs').writeFileSync(require('node:path').join(__dirname, 'install-requested'), 'install');\nmodule.exports = {};\n"], snapshot = false }, + { argv = ["vp", "migrate", "--no-interactive", "--no-hooks", "--no-agent", "--no-editor"], snapshot = false }, + ["vpt", "print-file", "package.json"], + ["vpt", "print-file", "unit.test.ts"], + ["vpt", "stat-file", "node_modules/vite/package.json", "--assert", "file"], + ["vpt", "stat-file", "install-requested", "--assert", "file"], + { argv = ["vpt", "rm", "install-requested"], snapshot = false }, + { argv = ["vp", "migrate", "--no-interactive", "--no-hooks", "--no-agent", "--no-editor"], snapshot = false }, + ["vpt", "stat-file", "install-requested", "--assert", "missing"], +] diff --git a/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/migration_import_rule_install/snapshots/unresolved_lint_config_retains_vitest_peer.md b/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/migration_import_rule_install/snapshots/unresolved_lint_config_retains_vitest_peer.md new file mode 100644 index 0000000000..f80feeb94c --- /dev/null +++ b/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/migration_import_rule_install/snapshots/unresolved_lint_config_retains_vitest_peer.md @@ -0,0 +1,69 @@ +# unresolved_lint_config_retains_vitest_peer + +A config that still throws after install keeps the upstream Vitest import and its Vite peer. Rerunning migration does not reinstall. + +## `vpt json-edit package.json devDependencies.vitest 5.1.1` + + +## `vpt write-file vite.config.ts 'export default () => { throw new Error('\''missing project setting'\''); }; +'` + + +## `vpt write-file .pnpmfile.cjs 'require('\''node:fs'\'').writeFileSync(require('\''node:path'\'').join(__dirname, '\''install-requested'\''), '\''install'\''); +module.exports = {}; +'` + + +## `vp migrate --no-interactive --no-hooks --no-agent --no-editor` + + +## `vpt print-file package.json` + +``` +{ + "devDependencies": { + "lint-policy": "file:./lint-policy", + "vite": "catalog:", + "vite-plus": "catalog:", + "vitest": "catalog:" + }, + "name": "migration-import-rule-install", + "packageManager": "pnpm@12.11.2", + "private": true, + "scripts": { + "build": "vp build" + }, + "type": "module" +} +``` + +## `vpt print-file unit.test.ts` + +``` +import { test } from 'vitest'; +test('application', () => {}); +``` + +## `vpt stat-file node_modules/vite/package.json --assert file` + +``` +node_modules/vite/package.json: file +``` + +## `vpt stat-file install-requested --assert file` + +``` +install-requested: file +``` + +## `vpt rm install-requested` + + +## `vp migrate --no-interactive --no-hooks --no-agent --no-editor` + + +## `vpt stat-file install-requested --assert missing` + +``` +install-requested: missing +``` diff --git a/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/migration_pnpm_vite_identity/check-identity.mjs b/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/migration_pnpm_vite_identity/check-identity.mjs index 26aba5a1b3..58b3f1376e 100644 --- a/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/migration_pnpm_vite_identity/check-identity.mjs +++ b/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/migration_pnpm_vite_identity/check-identity.mjs @@ -20,7 +20,11 @@ for (const directory of ['.', 'packages/utils', 'packages/app']) { assert.ok(manifest.devDependencies.vitest); assert.equal(project.resolve('vitest'), vitestPath); } - if (directory === 'packages/app' || usesVitestUi) { + if (directory === 'packages/utils' && usesVitestUi) { + assert.equal(manifest.peerDependencies.vite, '^7'); + assert.equal(manifest.devDependencies.vite, undefined); + assert.equal(project.resolve('vite/package.json'), vitePath); + } else if (directory === 'packages/app' || usesVitestUi) { assert.ok(manifest.devDependencies.vite); assert.equal(project.resolve('vite/package.json'), vitePath); } else { diff --git a/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/migration_pnpm_vite_identity/snapshots.toml b/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/migration_pnpm_vite_identity/snapshots.toml index 5e4e0cafe5..5c57f73c0a 100644 --- a/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/migration_pnpm_vite_identity/snapshots.toml +++ b/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/migration_pnpm_vite_identity/snapshots.toml @@ -18,14 +18,16 @@ vp = "global" # Dependency installation is slow on Linux CI. skip-platforms = ["linux"] local-registry = true -comment = "The pnpm 10 upgrade preserves dependency identity and caching when the root and utility use the bundled Vitest." +comment = "The pnpm 10 upgrade preserves the utility package's public Vite peer range and runs its direct Vitest with the same core and runner as Vite+." steps = [ { argv = ["vpt", "json-edit", "package.json", "packageManager", "pnpm@10.33.0"], snapshot = false }, + { argv = ["vpt", "json-edit", "packages/utils/package.json", "peerDependencies.vite", "^7"], snapshot = false }, + { argv = ["vpt", "json-edit", "packages/utils/package.json", "devDependencies.@vitest/ui", "5.1.1"], snapshot = false }, { argv = ["vp", "migrate", "--no-interactive"], snapshot = false }, { argv = ["vp", "install", "--ignore-scripts"], snapshot = false }, ["node", "check-identity.mjs"], { argv = ["vp", "run", "test"], cwd = "packages/utils", comment = "First run populates the test cache." }, { argv = ["vp", "run", "test"], cwd = "packages/utils", comment = "Second run must hit the cache." }, { argv = ["vp", "migrate", "--no-interactive"], snapshot = false }, - { argv = ["node", "check-identity.mjs"], comment = "Repeated migration keeps Vite out of packages that only use the bundled Vitest." }, + { argv = ["node", "check-identity.mjs"], comment = "Repeated migration preserves the public peer range and the installed runner identity." }, ] diff --git a/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/migration_pnpm_vite_identity/snapshots/pnpm10_upgrade_peer_identity_and_test_cache.md b/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/migration_pnpm_vite_identity/snapshots/pnpm10_upgrade_peer_identity_and_test_cache.md index dc3a0d521e..6e8f68f611 100644 --- a/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/migration_pnpm_vite_identity/snapshots/pnpm10_upgrade_peer_identity_and_test_cache.md +++ b/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/migration_pnpm_vite_identity/snapshots/pnpm10_upgrade_peer_identity_and_test_cache.md @@ -1,10 +1,16 @@ # pnpm10_upgrade_peer_identity_and_test_cache -The pnpm 10 upgrade preserves dependency identity and caching when the root and utility use the bundled Vitest. +The pnpm 10 upgrade preserves the utility package's public Vite peer range and runs its direct Vitest with the same core and runner as Vite+. ## `vpt json-edit package.json packageManager pnpm@10.33.0` +## `vpt json-edit packages/utils/package.json peerDependencies.vite ^7` + + +## `vpt json-edit packages/utils/package.json devDependencies.@vitest/ui 5.1.1` + + ## `vp migrate --no-interactive` @@ -63,7 +69,7 @@ vp run: cache hit, saved. ## `node check-identity.mjs` -Repeated migration keeps Vite out of packages that only use the bundled Vitest. +Repeated migration preserves the public peer range and the installed runner identity. ``` All packages share one Vite+, bundled Vite, and Vitest instance diff --git a/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/migration_vitest_unmanaged_override/package.json b/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/migration_vitest_unmanaged_override/package.json index 1a1d684120..184290e34f 100644 --- a/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/migration_vitest_unmanaged_override/package.json +++ b/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/migration_vitest_unmanaged_override/package.json @@ -5,6 +5,7 @@ }, "devDependencies": { "@vitest/ui": "4.0.13", + "vite": "^7.0.0", "vitest": "4.0.13" } } diff --git a/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/migration_vitest_unmanaged_override/snapshots.toml b/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/migration_vitest_unmanaged_override/snapshots.toml index f2be57801e..a279fd682b 100644 --- a/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/migration_vitest_unmanaged_override/snapshots.toml +++ b/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/migration_vitest_unmanaged_override/snapshots.toml @@ -4,8 +4,19 @@ vp = "global" env = { VP_OVERRIDE_PACKAGES = "{\"vite\":\"npm:@voidzero-dev/vite-plus-core@latest\"}" } steps = [ { argv = ["vp", "migrate", "--no-interactive"], comment = "vitest omitted from managed overrides must remain user-owned", continue-on-failure = true }, - { argv = ["vpt", "print-file", "package.json"], comment = "The project keeps its Vitest and @vitest/ui versions without gaining a direct Vite dependency.", continue-on-failure = true }, + { argv = ["vpt", "print-file", "package.json"], comment = "user's Vitest and @vitest/ui stay direct devDependencies (not converted to catalog:), so they remain user-owned", continue-on-failure = true }, { argv = ["vpt", "print-file", "pnpm-workspace.yaml"], comment = "no vitest catalog or override should be introduced", continue-on-failure = true }, - { argv = ["vp", "migrate", "--no-interactive"], comment = "Run the existing-project upgrade with the same unmanaged Vitest.", continue-on-failure = true }, + { argv = ["vp", "migrate", "--no-interactive"], comment = "unmanaged Vitest ecosystem versions remain stable on rerun", continue-on-failure = true }, +] + +[[case]] +name = "unmanaged_vitest_without_vite" +vp = "global" +env = { VP_OVERRIDE_PACKAGES = "{\"vite\":\"npm:@voidzero-dev/vite-plus-core@latest\"}" } +steps = [ + { argv = ["vpt", "json-edit", "package.json", "devDependencies", "{\"@vitest/ui\":\"4.0.13\",\"vitest\":\"4.0.13\"}"], snapshot = false }, + { argv = ["vp", "migrate", "--no-interactive"], snapshot = false }, + { argv = ["vpt", "print-file", "package.json"], comment = "The project keeps its Vitest and @vitest/ui versions without gaining a direct Vite dependency." }, + { argv = ["vp", "migrate", "--no-interactive"], snapshot = false }, ["vpt", "print-file", "package.json"], ] diff --git a/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/migration_vitest_unmanaged_override/snapshots/migration_vitest_unmanaged_override.md b/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/migration_vitest_unmanaged_override/snapshots/migration_vitest_unmanaged_override.md index 76d8e4cb62..093f671893 100644 --- a/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/migration_vitest_unmanaged_override/snapshots/migration_vitest_unmanaged_override.md +++ b/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/migration_vitest_unmanaged_override/snapshots/migration_vitest_unmanaged_override.md @@ -14,7 +14,7 @@ VITE+ - The Unified Toolchain for the Web ## `vpt print-file package.json` -The project keeps its Vitest and @vitest/ui versions without gaining a direct Vite dependency. +user's Vitest and @vitest/ui stay direct devDependencies (not converted to catalog:), so they remain user-owned ``` { @@ -25,6 +25,7 @@ The project keeps its Vitest and @vitest/ui versions without gaining a direct Vi }, "devDependencies": { "@vitest/ui": "", + "vite": "catalog:", "vitest": "", "vite-plus": "catalog:" } @@ -50,7 +51,7 @@ peerDependencyRules: ## `vp migrate --no-interactive` -Run the existing-project upgrade with the same unmanaged Vitest. +unmanaged Vitest ecosystem versions remain stable on rerun ``` VITE+ - The Unified Toolchain for the Web @@ -63,20 +64,3 @@ VITE+ - The Unified Toolchain for the Web vitest 4.0.13 → @vitest/ui 4.0.13 → ``` - -## `vpt print-file package.json` - -``` -{ - "name": "migration-vitest-unmanaged-override", - "scripts": { - "test": "vp test", - "prepare": "vp config" - }, - "devDependencies": { - "@vitest/ui": "", - "vitest": "", - "vite-plus": "catalog:" - } -} -``` diff --git a/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/migration_vitest_unmanaged_override/snapshots/unmanaged_vitest_without_vite.md b/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/migration_vitest_unmanaged_override/snapshots/unmanaged_vitest_without_vite.md new file mode 100644 index 0000000000..89e52878b6 --- /dev/null +++ b/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/migration_vitest_unmanaged_override/snapshots/unmanaged_vitest_without_vite.md @@ -0,0 +1,46 @@ +# unmanaged_vitest_without_vite + +## `vpt json-edit package.json devDependencies '{"@vitest/ui":"4.0.13","vitest":"4.0.13"}'` + + +## `vp migrate --no-interactive` + + +## `vpt print-file package.json` + +The project keeps its Vitest and @vitest/ui versions without gaining a direct Vite dependency. + +``` +{ + "devDependencies": { + "@vitest/ui": "", + "vitest": "", + "vite-plus": "catalog:" + }, + "name": "migration-vitest-unmanaged-override", + "scripts": { + "test": "vp test", + "prepare": "vp config" + } +} +``` + +## `vp migrate --no-interactive` + + +## `vpt print-file package.json` + +``` +{ + "devDependencies": { + "@vitest/ui": "", + "vitest": "", + "vite-plus": "catalog:" + }, + "name": "migration-vitest-unmanaged-override", + "scripts": { + "test": "vp test", + "prepare": "vp config" + } +} +``` diff --git a/docs/guide/migrate-rules.md b/docs/guide/migrate-rules.md index 82f7bdad6b..abf654161f 100644 --- a/docs/guide/migrate-rules.md +++ b/docs/guide/migrate-rules.md @@ -147,7 +147,7 @@ What happens to each toolchain dependency, at a glance: You can use `vite-plus` in a pnpm package without declaring `vite`. The `vite-plus` package includes a `vite` dependency aliased to its core, which provides Vitest's required peer. Migration keeps the workspace override for other Vite consumers but does not add `vite` to a package solely because it uses `vite-plus`. -When a pnpm package directly installs the Vite+-managed `vitest` and has no `vite` declaration, migration adds the core alias to its `devDependencies` for local testing. This gives Vitest the same Vite peer in both the project and Vite+, so plugins such as `@cloudflare/vitest-plugin` register tests with the runner used by `vp test`. Packages that already declare `peerDependencies.vite` keep their public peer range. +When a pnpm package directly installs the Vite+-managed `vitest` and has no `vite` declaration, migration adds the core alias to its `devDependencies` for local testing. This gives Vitest the same Vite peer in both the project and Vite+, so plugins such as `@cloudflare/vitest-plugin` register tests with the runner used by `vp test`. Packages that already declare `peerDependencies.vite` keep their public peer range. If a later migration removes Vitest, it keeps the existing Vite dependency because the package may also use Vite directly. Related rules: diff --git a/packages/cli/src/migration/__tests__/migrator.spec.ts b/packages/cli/src/migration/__tests__/migrator.spec.ts index e3ac3d998c..6706a583a4 100644 --- a/packages/cli/src/migration/__tests__/migrator.spec.ts +++ b/packages/cli/src/migration/__tests__/migrator.spec.ts @@ -2537,27 +2537,55 @@ describe('ensureVitePlusBootstrap', () => { const workspace = makeWorkspaceInfo(tmpDir, PackageManager.pnpm, '10.26.2'); fs.writeFileSync( manifest, - JSON.stringify({ name: 'app', devDependencies: { 'vite-plus': 'latest', vitest: '^5' } }), + JSON.stringify({ + name: 'app', + devDependencies: { 'vite-plus': 'latest', vitest: '^5', library: '1.0.0' }, + }), ); const imports = { vitest: new Set([tmpDir]), browser: new Map>() }; ensureVitePlusBootstrap(workspace, undefined, imports, true); expect(readJson(manifest).devDependencies).toEqual({ + library: '1.0.0', 'vite-plus': 'catalog:', vitest: 'catalog:', }); // A retry has only the manifest left by the interrupted install. + const libraryDir = path.join(tmpDir, 'node_modules', 'library'); + fs.mkdirSync(libraryDir, { recursive: true }); + fs.writeFileSync( + path.join(libraryDir, 'package.json'), + JSON.stringify({ name: 'library', version: '1.0.0' }), + ); const resolved = { ...imports, vitest: retained ? new Set([tmpDir]) : new Set() }; ensureVitePlusBootstrap(workspace, undefined, resolved); expect(readJson(manifest).devDependencies).toEqual( retained - ? { vite: 'catalog:', 'vite-plus': 'catalog:', vitest: 'catalog:' } - : { 'vite-plus': 'catalog:' }, + ? { library: '1.0.0', vite: 'catalog:', 'vite-plus': 'catalog:', vitest: 'catalog:' } + : { library: '1.0.0', 'vite-plus': 'catalog:' }, ); expect(ensureVitePlusBootstrap(workspace, undefined, resolved).changed).toBe(false); }, ); + it('supplies the pnpm Vite peer before install for a known Vitest consumer', () => { + const workspace = makeWorkspaceInfo(tmpDir, PackageManager.pnpm, '10.26.2'); + const manifest = path.join(tmpDir, 'package.json'); + fs.writeFileSync( + manifest, + JSON.stringify({ + name: 'worker', + devDependencies: { '@cloudflare/vitest-plugin': '1.8.4', 'vite-plus': 'latest' }, + }), + ); + const imports = { vitest: new Set([tmpDir]), browser: new Map>() }; + ensureVitePlusBootstrap(workspace, undefined, imports, true); + expect(readJson(manifest).devDependencies).toMatchObject({ + vite: 'catalog:', + vitest: 'catalog:', + }); + }); + it('repairs a missing Vite peer on a previously migrated pnpm Vitest project', () => { const manifest = path.join(tmpDir, 'package.json'); const workspace = makeWorkspaceInfo(tmpDir, PackageManager.pnpm, '10.26.2'); diff --git a/packages/cli/src/migration/bin.ts b/packages/cli/src/migration/bin.ts index 6258e14e1c..03642fc140 100644 --- a/packages/cli/src/migration/bin.ts +++ b/packages/cli/src/migration/bin.ts @@ -1666,9 +1666,11 @@ async function main() { } } - async function installExistingDependencies(): Promise { + async function installExistingDependencies( + message = 'Installing dependencies', + ): Promise { await ensureExistingPackageManager(); - updateMigrationProgress('Installing dependencies'); + updateMigrationProgress(message); const npmReinstallPreparation = packageManager === PackageManager.npm ? prepareNpmViteAliasReinstall( @@ -1704,11 +1706,13 @@ async function main() { workspaceInfoOptional.rootDir, report, ); + return installSummary.status === 'installed'; } + let installedDependencies = false; if (needsInstall) { clearMigrationProgress(); completeVitestV5Migration(vitestV5Plan, report); - await installExistingDependencies(); + installedDependencies = await installExistingDependencies(); } if (importRuleConfig === null) { @@ -1730,14 +1734,16 @@ async function main() { oxlintOwnerDirs: deferredOxlintOwnerDirs, importRuleConfig: resolvedImportRuleConfig ?? DISABLED_IMPORT_RULE_CONFIG, }) || didMigrate; - // The resolved rule can drop a provisional Vitest or confirm it needs a Vite peer. + // After a successful install, supply peers for the imports that remain even + // when the config still cannot load. A failed install can be retried first. if ( - resolvedImportRuleConfig !== null && + (resolvedImportRuleConfig !== null || + (installedDependencies && packageManager === PackageManager.pnpm)) && bootstrapPending(resolvedDependencies) && (await reconcileBootstrap(resolvedDependencies)) ) { didMigrate = true; - await installExistingDependencies(); + await installExistingDependencies('Installing dependencies for retained imports'); } } diff --git a/packages/cli/src/migration/migrator/package-json.ts b/packages/cli/src/migration/migrator/package-json.ts index 1c00d52e52..2eb975fe61 100644 --- a/packages/cli/src/migration/migrator/package-json.ts +++ b/packages/cli/src/migration/migrator/package-json.ts @@ -431,6 +431,8 @@ export function rewritePackageJson( ); } } + // An existing direct Vitest needs its peer even when no new Vitest was added. + // First-time migration and project creation both install after rewriting manifests. ensurePnpmVitestVitePeer(pkg, packageManager, supportCatalog, catalogDependencyResolver); return extractedStagedConfig; } diff --git a/packages/cli/src/migration/migrator/vite-plus-bootstrap.ts b/packages/cli/src/migration/migrator/vite-plus-bootstrap.ts index 8095e3022f..6bf0c2da80 100644 --- a/packages/cli/src/migration/migrator/vite-plus-bootstrap.ts +++ b/packages/cli/src/migration/migrator/vite-plus-bootstrap.ts @@ -45,6 +45,7 @@ import { bunSupportsCatalog, pnpmWorkspaceMinimumReleaseAgeExemptionsPending, pnpmWorkspaceTsrsTrustPolicyExceptionPending, + projectListsRequiredVitestPeer, projectUsesVitestDirectly, pruneLegacyWrapperAliases, readPnpmWorkspaceCatalogDependencyResolver, @@ -308,9 +309,19 @@ function reconcileVitePlusBootstrapPackage( deferRetainedImportVitePeers = false, ): boolean { const before = JSON.stringify(pkg); - const usesVitest = - retainedImportDependencies?.vitest.has(projectPath) || - projectUsesVitestDirectly(projectPath, pkg); + const retainedVitestImport = retainedImportDependencies?.vitest.has(projectPath); + const usesVitest = retainedVitestImport || projectUsesVitestDirectly(projectPath, pkg); + // An unresolved import rule can only affect ordinary imports. Browser mode, + // required peers and always-preserved references already require local Vitest. + const deferVitePeer = + packageManager === PackageManager.pnpm && + deferRetainedImportVitePeers && + retainedVitestImport && + !projectUsesVitestDirectly( + projectPath, + pkg, + projectListsRequiredVitestPeer(projectPath, pkg, { preserveIfMetadataUnavailable: false }), + ); ensureVitePlusDependencySpecs(pkg, vitePlusVersion, ensureVitePlus); const installGroups = [pkg.devDependencies, pkg.dependencies, pkg.optionalDependencies]; @@ -497,9 +508,7 @@ function reconcileVitePlusBootstrapPackage( } } - // The lint config may be unavailable until install. Wait before adding Vite for - // a provisional import so a failed or interrupted install leaves no stale peer. - if (!(deferRetainedImportVitePeers && retainedImportDependencies?.vitest.has(projectPath))) { + if (!deferVitePeer) { ensurePnpmVitestVitePeer(pkg, packageManager, supportCatalog, catalogDependencyResolver); } return before !== JSON.stringify(pkg); diff --git a/packages/cli/src/migration/migrator/vitest-ecosystem.ts b/packages/cli/src/migration/migrator/vitest-ecosystem.ts index a5b05b3d67..252316c6dd 100644 --- a/packages/cli/src/migration/migrator/vitest-ecosystem.ts +++ b/packages/cli/src/migration/migrator/vitest-ecosystem.ts @@ -443,6 +443,7 @@ export function projectListsRequiredVitestPeer( devDependencies?: Record; optionalDependencies?: Record; }, + { preserveIfMetadataUnavailable = true } = {}, ): boolean { const installGroups = [pkg.dependencies, pkg.devDependencies, pkg.optionalDependencies]; const hasExistingVitest = installGroups.some( @@ -487,7 +488,7 @@ export function projectListsRequiredVitestPeer( // unknown, preserve it rather than risk removing the provider for an // arbitrary integration such as vite-plugin-gherkin. A later migration with // complete metadata can safely remove a genuinely redundant pin. - return metadataUnavailable && hasExistingVitest; + return preserveIfMetadataUnavailable && metadataUnavailable && hasExistingVitest; } // True iff the project uses vitest DIRECTLY — via a dependency that is expected From 13b40a0616aebb9fcb451a960fe58dc833223d25 Mon Sep 17 00:00:00 2001 From: "gxc.510" Date: Mon, 30 Nov 2026 13:12:08 +0800 Subject: [PATCH 4/5] fix(migrate): finalize pnpm Vitest peers when installation is skipped Change-Id: I80fef2bab1eeab5c5e2458eda3a5bfa216723303 --- .../check-vite-peer.mjs | 13 ++++ .../snapshots.toml | 20 ++++++- ...esolved_lint_config_retains_vitest_peer.md | 12 +++- .../unresolved_lint_config_skip_install.md | 48 +++++++++++++++ .../snapshots.toml | 18 ++++++ ...optional_vite_peer_without_auto_install.md | 60 +++++++++++++++++++ packages/cli/src/migration/bin.ts | 17 +++--- 7 files changed, 175 insertions(+), 13 deletions(-) create mode 100644 crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/migration_import_rule_install/check-vite-peer.mjs create mode 100644 crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/migration_import_rule_install/snapshots/unresolved_lint_config_skip_install.md create mode 100644 crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/migration_pnpm_vite_identity/snapshots/pnpm_optional_vite_peer_without_auto_install.md diff --git a/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/migration_import_rule_install/check-vite-peer.mjs b/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/migration_import_rule_install/check-vite-peer.mjs new file mode 100644 index 0000000000..20f378a735 --- /dev/null +++ b/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/migration_import_rule_install/check-vite-peer.mjs @@ -0,0 +1,13 @@ +import assert from 'node:assert/strict'; +import { createRequire } from 'node:module'; + +const project = createRequire(import.meta.url); +const cli = createRequire(project.resolve('vite-plus/package.json')); +const runner = createRequire(project.resolve('vitest')); +const core = cli.resolve('vite/package.json'); + +assert.equal(project('vite/package.json').name, '@voidzero-dev/vite-plus-core'); +assert.equal(project.resolve('vite/package.json'), core); +assert.equal(runner.resolve('vite/package.json'), core); +assert.equal(project.resolve('vitest'), cli.resolve('vitest')); +console.log('The project and Vite+ share Vitest and Vite+ core'); diff --git a/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/migration_import_rule_install/snapshots.toml b/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/migration_import_rule_install/snapshots.toml index e94f2e628a..6a10e294e9 100644 --- a/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/migration_import_rule_install/snapshots.toml +++ b/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/migration_import_rule_install/snapshots.toml @@ -54,9 +54,27 @@ steps = [ { argv = ["vp", "migrate", "--no-interactive", "--no-hooks", "--no-agent", "--no-editor"], snapshot = false }, ["vpt", "print-file", "package.json"], ["vpt", "print-file", "unit.test.ts"], - ["vpt", "stat-file", "node_modules/vite/package.json", "--assert", "file"], + ["node", "check-vite-peer.mjs"], + { argv = ["vpt", "cp", "pnpm-lock.yaml", "lockfile.before"], snapshot = false }, ["vpt", "stat-file", "install-requested", "--assert", "file"], { argv = ["vpt", "rm", "install-requested"], snapshot = false }, { argv = ["vp", "migrate", "--no-interactive", "--no-hooks", "--no-agent", "--no-editor"], snapshot = false }, ["vpt", "stat-file", "install-requested", "--assert", "missing"], + ["node", "-e", "const fs = require('node:fs'); require('node:assert/strict').deepEqual(fs.readFileSync('pnpm-lock.yaml'), fs.readFileSync('lockfile.before'));"], +] + +[[case]] +name = "unresolved_lint_config_skip_install" +vp = "local" +local-registry = true +env = { VP_SKIP_INSTALL = "1" } +comment = "Skipping dependency installation still supplies the retained Vitest peer for a later pnpm install." +steps = [ + { argv = ["vpt", "json-edit", "package.json", "devDependencies.vitest", "5.1.1"], snapshot = false }, + { argv = ["vpt", "write-file", "vite.config.ts", "export default () => { throw new Error('missing project setting'); };\n"], snapshot = false }, + { argv = ["vp", "migrate", "--no-interactive", "--no-hooks", "--no-agent", "--no-editor"], snapshot = false }, + ["vpt", "stat-file", "node_modules", "--assert", "missing"], + ["vpt", "print-file", "package.json"], + { argv = ["pnpm", "install", "--no-frozen-lockfile", "--ignore-scripts"], snapshot = false }, + ["node", "check-vite-peer.mjs"], ] diff --git a/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/migration_import_rule_install/snapshots/unresolved_lint_config_retains_vitest_peer.md b/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/migration_import_rule_install/snapshots/unresolved_lint_config_retains_vitest_peer.md index f80feeb94c..59855d41a2 100644 --- a/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/migration_import_rule_install/snapshots/unresolved_lint_config_retains_vitest_peer.md +++ b/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/migration_import_rule_install/snapshots/unresolved_lint_config_retains_vitest_peer.md @@ -44,12 +44,15 @@ import { test } from 'vitest'; test('application', () => {}); ``` -## `vpt stat-file node_modules/vite/package.json --assert file` +## `node check-vite-peer.mjs` ``` -node_modules/vite/package.json: file +The project and Vite+ share Vitest and Vite+ core ``` +## `vpt cp pnpm-lock.yaml lockfile.before` + + ## `vpt stat-file install-requested --assert file` ``` @@ -67,3 +70,8 @@ install-requested: file ``` install-requested: missing ``` + +## `node -e 'const fs = require('\''node:fs'\''); require('\''node:assert/strict'\'').deepEqual(fs.readFileSync('\''pnpm-lock.yaml'\''), fs.readFileSync('\''lockfile.before'\''));'` + +``` +``` diff --git a/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/migration_import_rule_install/snapshots/unresolved_lint_config_skip_install.md b/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/migration_import_rule_install/snapshots/unresolved_lint_config_skip_install.md new file mode 100644 index 0000000000..8f51ef4be8 --- /dev/null +++ b/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/migration_import_rule_install/snapshots/unresolved_lint_config_skip_install.md @@ -0,0 +1,48 @@ +# unresolved_lint_config_skip_install + +Skipping dependency installation still supplies the retained Vitest peer for a later pnpm install. + +## `vpt json-edit package.json devDependencies.vitest 5.1.1` + + +## `vpt write-file vite.config.ts 'export default () => { throw new Error('\''missing project setting'\''); }; +'` + + +## `vp migrate --no-interactive --no-hooks --no-agent --no-editor` + + +## `vpt stat-file node_modules --assert missing` + +``` +node_modules: missing +``` + +## `vpt print-file package.json` + +``` +{ + "devDependencies": { + "lint-policy": "file:./lint-policy", + "vite": "catalog:", + "vite-plus": "catalog:", + "vitest": "catalog:" + }, + "name": "migration-import-rule-install", + "packageManager": "pnpm@12.11.2", + "private": true, + "scripts": { + "build": "vp build" + }, + "type": "module" +} +``` + +## `pnpm install --no-frozen-lockfile --ignore-scripts` + + +## `node check-vite-peer.mjs` + +``` +The project and Vite+ share Vitest and Vite+ core +``` diff --git a/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/migration_pnpm_vite_identity/snapshots.toml b/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/migration_pnpm_vite_identity/snapshots.toml index 5c57f73c0a..712de1cc23 100644 --- a/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/migration_pnpm_vite_identity/snapshots.toml +++ b/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/migration_pnpm_vite_identity/snapshots.toml @@ -31,3 +31,21 @@ steps = [ { argv = ["vp", "migrate", "--no-interactive"], snapshot = false }, { argv = ["node", "check-identity.mjs"], comment = "Repeated migration preserves the public peer range and the installed runner identity." }, ] + +[[case]] +name = "pnpm_optional_vite_peer_without_auto_install" +vp = "global" +local-registry = true +comment = "A workspace member with an optional public Vite peer resolves the same Vite and Vitest as Vite+ with automatic peer installation disabled." +steps = [ + { argv = ["vpt", "json-edit", "package.json", "packageManager", "pnpm@10.33.0"], snapshot = false }, + { argv = ["vpt", "replace-file-content", "pnpm-workspace.yaml", "autoInstallPeers: true", "autoInstallPeers: false\nresolvePeersFromWorkspaceRoot: false"], snapshot = false }, + { argv = ["vpt", "json-edit", "packages/utils/package.json", "peerDependencies.vite", "^7"], snapshot = false }, + { argv = ["vpt", "json-edit", "packages/utils/package.json", "peerDependenciesMeta.vite.optional", "true"], snapshot = false }, + { argv = ["vpt", "json-edit", "packages/utils/package.json", "devDependencies.@vitest/ui", "5.1.1"], snapshot = false }, + { argv = ["vp", "migrate", "--no-interactive"], snapshot = false }, + { argv = ["vp", "install", "--ignore-scripts"], snapshot = false }, + ["vpt", "grep-file", "pnpm-lock.yaml", "autoInstallPeers: false"], + ["vpt", "print-file", "packages/utils/package.json"], + ["node", "check-identity.mjs"], +] diff --git a/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/migration_pnpm_vite_identity/snapshots/pnpm_optional_vite_peer_without_auto_install.md b/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/migration_pnpm_vite_identity/snapshots/pnpm_optional_vite_peer_without_auto_install.md new file mode 100644 index 0000000000..453b934f70 --- /dev/null +++ b/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/migration_pnpm_vite_identity/snapshots/pnpm_optional_vite_peer_without_auto_install.md @@ -0,0 +1,60 @@ +# pnpm_optional_vite_peer_without_auto_install + +A workspace member with an optional public Vite peer resolves the same Vite and Vitest as Vite+ with automatic peer installation disabled. + +## `vpt json-edit package.json packageManager pnpm@10.33.0` + + +## `vpt replace-file-content pnpm-workspace.yaml 'autoInstallPeers: true' 'autoInstallPeers: false +resolvePeersFromWorkspaceRoot: false'` + + +## `vpt json-edit packages/utils/package.json peerDependencies.vite ^7` + + +## `vpt json-edit packages/utils/package.json peerDependenciesMeta.vite.optional true` + + +## `vpt json-edit packages/utils/package.json devDependencies.@vitest/ui 5.1.1` + + +## `vp migrate --no-interactive` + + +## `vp install --ignore-scripts` + + +## `vpt grep-file pnpm-lock.yaml 'autoInstallPeers: false'` + +``` +pnpm-lock.yaml: found "autoInstallPeers: false" +``` + +## `vpt print-file packages/utils/package.json` + +``` +{ + "devDependencies": { + "@vitest/ui": "catalog:", + "vite-plus": "catalog:", + "vitest": "catalog:" + }, + "name": "utils", + "peerDependencies": { + "vite": "^7" + }, + "peerDependenciesMeta": { + "vite": { + "optional": true + } + }, + "private": true, + "type": "module" +} +``` + +## `node check-identity.mjs` + +``` +All packages share one Vite+, bundled Vite, and Vitest instance +``` diff --git a/packages/cli/src/migration/bin.ts b/packages/cli/src/migration/bin.ts index 03642fc140..5c3d16a651 100644 --- a/packages/cli/src/migration/bin.ts +++ b/packages/cli/src/migration/bin.ts @@ -1666,9 +1666,7 @@ async function main() { } } - async function installExistingDependencies( - message = 'Installing dependencies', - ): Promise { + async function installExistingDependencies(message = 'Installing dependencies'): Promise { await ensureExistingPackageManager(); updateMigrationProgress(message); const npmReinstallPreparation = @@ -1706,13 +1704,11 @@ async function main() { workspaceInfoOptional.rootDir, report, ); - return installSummary.status === 'installed'; } - let installedDependencies = false; if (needsInstall) { clearMigrationProgress(); completeVitestV5Migration(vitestV5Plan, report); - installedDependencies = await installExistingDependencies(); + await installExistingDependencies(); } if (importRuleConfig === null) { @@ -1734,11 +1730,12 @@ async function main() { oxlintOwnerDirs: deferredOxlintOwnerDirs, importRuleConfig: resolvedImportRuleConfig ?? DISABLED_IMPORT_RULE_CONFIG, }) || didMigrate; - // After a successful install, supply peers for the imports that remain even - // when the config still cannot load. A failed install can be retried first. + // A skipped install still needs a complete manifest for the caller's next + // pnpm install. Only an install failure should leave these peers deferred. if ( - (resolvedImportRuleConfig !== null || - (installedDependencies && packageManager === PackageManager.pnpm)) && + needsInstall && + finalInstallOk && + (resolvedImportRuleConfig !== null || packageManager === PackageManager.pnpm) && bootstrapPending(resolvedDependencies) && (await reconcileBootstrap(resolvedDependencies)) ) { From 62883df15d0118f25f725e7e87020321965d1620 Mon Sep 17 00:00:00 2001 From: "gxc.510" Date: Mon, 30 Nov 2026 13:18:24 +0800 Subject: [PATCH 5/5] docs(migrate): explain Vite peer overrides on older pnpm Change-Id: I48b3b0fa29edab813b09c529ab9698e1cb8645fa --- docs/guide/migrate-rules.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/docs/guide/migrate-rules.md b/docs/guide/migrate-rules.md index abf654161f..1f4a883ec9 100644 --- a/docs/guide/migrate-rules.md +++ b/docs/guide/migrate-rules.md @@ -149,6 +149,8 @@ You can use `vite-plus` in a pnpm package without declaring `vite`. The `vite-pl When a pnpm package directly installs the Vite+-managed `vitest` and has no `vite` declaration, migration adds the core alias to its `devDependencies` for local testing. This gives Vitest the same Vite peer in both the project and Vite+, so plugins such as `@cloudflare/vitest-plugin` register tests with the runner used by `vp test`. Packages that already declare `peerDependencies.vite` keep their public peer range. If a later migration removes Vitest, it keeps the existing Vite dependency because the package may also use Vite directly. +On pnpm 8 and 9 with `auto-install-peers=false`, a package that declares `vite` only in `peerDependencies` can be missing the core alias that its local Vitest needs. With automatic peer installation enabled, pnpm 8 can also install upstream Vite. In either case, keep the public peer range and add the workspace's Vite+ core alias to that package's `devDependencies.vite`. + Related rules: - A direct `vite` declaration is never removed merely because a root override exists. @@ -391,7 +393,7 @@ Migration converts the Volta `volta.node` pin to `.node-version`, because Vite+ - Migration does not add `vite` to `peerDependencyRules.allowAny` or `peerDependencyRules.allowedVersions`. - Migration removes `vite` from `allowAny` and removes `allowedVersions.vite` when its value is `'*'`, also when you wrote the entry. Those entries accepted the `1.x` core alias. Another `allowedVersions.vite` range, such as `'7 || 8'`, stays. Migration removes a field, or `peerDependencyRules`, when no entry remains. Other entries stay. The migrate summary names the removed rule. - For a preview build (`0.0.0-commit.`) or a Vite+ prerelease core (such as `8.4.0-vp.0`), migration keeps writing the `vite` rule. Package managers do not accept these versions for ranges such as `^8.0.0`. -- On pnpm before 10.2.0, migration also keeps writing the `vite` rule. These versions apply the `vite@*` alias override to peer ranges, so every `vite` peer fails against the core without the rule. +- On pnpm before 10.2.0, migration also keeps writing the `vite` rule because these versions apply the `vite@*` alias override to peer ranges. pnpm 10.0 and 10.1 can reject the resulting `npm:` peer spec with `ERR_PNPM_INVALID_PEER_DEPENDENCY_SPECIFICATION` before peer rules take effect. Upgrade to [pnpm 10.2.0](https://github.com/pnpm/pnpm/releases/tag/v10.2.0) or later to use the alias. - After migration, a plugin whose `vite` peer range excludes the bundled Vite (for example `^7.0.0`) produces a peer warning. With `strictPeerDependencies`, the install fails. Update the plugin, or widen the peer range of that plugin only: - pnpm 12.17.0 and later: add the override `'vite-plugin-foo>vite:peer': '*'`. pnpm deprecated `peerDependencyRules` in this version. - Earlier pnpm versions: add the rule `allowedVersions: { 'vite-plugin-foo>vite': '*' }`.