Skip to content

Commit 60480a3

Browse files
committed
fix(migration): add vitest to devDependencies for peer dep resolution
When migrating projects that have packages with vitest as a peer dependency (e.g., vitest-browser-svelte), the migration now ensures vitest is added to devDependencies. Without this, pnpm resolves the real vitest@4.x for peer deps instead of the aliased @voidzero-dev/vite-plus-test, causing third-party type augmentations (like page.render() from vitest-browser-svelte) to target the wrong module and fail type checking. Also add vite-plus-vitest-type-aug reproduction project to ecosystem-ci for ongoing regression testing. Closes #1256
1 parent 0d4e245 commit 60480a3

5 files changed

Lines changed: 27 additions & 1 deletion

File tree

.github/workflows/e2e-test.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,10 @@ jobs:
304304
command: |
305305
npx playwright install chromium
306306
vp test
307+
- name: vite-plus-vitest-type-aug
308+
node-version: 24
309+
command: |
310+
vp check --fix
307311
exclude:
308312
# frm-stack uses Docker (testcontainers) which doesn't work the same way on Windows
309313
- os: windows-latest

ecosystem-ci/repo.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,5 +113,11 @@
113113
"repository": "https://github.com/why-reproductions-are-required/vitest-playwright-repro.git",
114114
"branch": "main",
115115
"hash": "f7252170025c01ec482fa9ad43e09b965f46928f"
116+
},
117+
"vite-plus-vitest-type-aug": {
118+
"repository": "https://github.com/why-reproductions-are-required/vite-plus-vitest-type-aug.git",
119+
"branch": "main",
120+
"hash": "6192f60653c124ae068efaf5d7d0a4134c95edbd",
121+
"forceFreshMigration": true
116122
}
117123
}

packages/cli/src/migration/migrator.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1399,6 +1399,16 @@ export function rewritePackageJson(
13991399
...pkg.devDependencies,
14001400
[VITE_PLUS_NAME]: version,
14011401
};
1402+
// Ensure vitest is in devDependencies so pnpm uses the override for peer dep
1403+
// resolution. Without this, packages like vitest-browser-svelte (peer dep:
1404+
// vitest ^4.0.0) resolve the real vitest instead of @voidzero-dev/vite-plus-test,
1405+
// causing third-party type augmentations to target the wrong module.
1406+
for (const [key, ver] of Object.entries(VITE_PLUS_OVERRIDE_PACKAGES)) {
1407+
if (!pkg.devDependencies[key] && !pkg.dependencies?.[key]) {
1408+
const overrideValue = supportCatalog && !ver.startsWith('file:') ? 'catalog:' : ver;
1409+
pkg.devDependencies[key] = overrideValue;
1410+
}
1411+
}
14021412
}
14031413
return extractedStagedConfig;
14041414
}

packages/test/BUNDLING.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,8 @@ When upgrading the vitest version:
309309
- createNodeEntry() index-node.js with browser-provider
310310
- copyBrowserClientFiles()
311311
- createBrowserEntryFiles() browser/ entry files at package root
312+
- patchModuleAugmentations() Rewrite @vitest/expect, @vitest/runner augmentations
313+
- patchChaiTypeReference() Add @types/chai triple-slash reference
312314
- createPluginExports() dist/plugins/* for pnpm overrides
313315
- mergePackageJson()
314316
- validateExternalDeps()

packages/test/build.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/// <reference types="node" />
12
// Build Script for @voidzero-dev/vite-plus-test
23
//
34
// Bundles vitest and @vitest/* dependencies with browser/Node.js separation.
@@ -175,7 +176,10 @@ const EXTERNAL_BLOCKLIST = new Set([
175176
const CJS_REEXPORT_PACKAGES = new Set(['expect-type']);
176177

177178
// Node built-in modules (including node: prefix variants)
178-
const NODE_BUILTINS = new Set([...builtinModules, ...builtinModules.map((m) => `node:${m}`)]);
179+
const NODE_BUILTINS = new Set([
180+
...builtinModules,
181+
...builtinModules.map((m: string) => `node:${m}`),
182+
]);
179183

180184
// Step 1: Copy vitest-dev dist files (rewriting vite -> core package)
181185
await bundleVitest();

0 commit comments

Comments
 (0)