Skip to content

Commit 365a61d

Browse files
Brooooooklynclaude
andcommitted
refactor: replace @voidzero-dev/vite-plus-test with upstream vitest@4.1.5
Delete the bundled `@voidzero-dev/vite-plus-test` wrapper and consume upstream `vitest@4.1.5` (plus `@vitest/browser*`) directly. The vite redirection that the wrapper used to provide is now handled cleanly by package-manager overrides (`vite` -> `@voidzero-dev/vite-plus-core`), so the bundle was dead weight that lagged upstream vitest releases. Public API contract preserved: - `vite-plus/test*` IS the public test API. Existing vite-plus user code (e.g. `import { vi } from 'vite-plus/test'`) is NEVER rewritten — the imports stay exactly as authored. - New vite-plus users do NOT install `vitest` or `@vitest/*` directly. They install `vite-plus`; vitest and the browser providers come in transitively as direct deps of the CLI package. - `vp migrate` on an upstream-vitest project still rewrites bare `vitest`, `vitest/*`, `@vitest/browser*`, declare-module specifiers and `/// <reference types>` directives to the `vite-plus/test*` surface (one-time forward migration). Implementation: - packages/cli/build.ts `syncTestPackageExports` auto-generates `./test/*` shims from `vitest`'s own exports map, plus `./test/<provider>` and `./test/browser/providers/<short>` shims projected from each `@vitest/browser-*` package's exports. - packages/cli/package.json adds `@vitest/browser`, `@vitest/browser-playwright`, `@vitest/browser-preview`, `@vitest/browser-webdriverio` as direct catalog deps pinned to 4.1.5 alongside `vitest`. - crates/vite_global_cli/src/commands/version.rs version ToolSpec points at the `vitest` package directly. - packages/cli/src/resolve-test.ts resolves `vitest/package.json` and reads `bin.vitest` so `vp test` invokes upstream vitest. - packages/cli/src/utils/constants.ts drops `vitest` from `VITE_PLUS_OVERRIDE_PACKAGES`; only `vite` remains a managed key. - packages/cli/src/migration/migrator.ts adds an `isVitestAdjacent` flag that flips `needVitePlus = true` for projects with packages like `vitest-browser-svelte` even when no vite/oxlint/tsdown dep is being migrated; adds a `pruneLegacyWrapperAliases` / `pruneYamlMapLegacyWrapperAliases` sweep that rewrites stale `vitest: npm:@voidzero-dev/vite-plus-test@*` aliases to `^4.1.5` in package.json overrides/resolutions/pnpm.overrides, in pnpm-workspace.yaml catalog/catalogs/overrides, and in bun workspaces.catalog / workspaces.catalogs. - packages/cli/src/migration/bin.ts adds a `handleInstallResult` helper so failed reinstalls warn the user, append to `report.warnings`, and flip `process.exitCode` instead of being silently reported as success. Verification: - cargo test -p vite_migration --lib: 167 tests pass - pnpm exec vitest run (packages/cli): 355 tests pass - pnpm bootstrap-cli + snap-test-global + snap-test-local: all fixtures regenerated; expected diffs only (forward import rewrites, `@vitest/browser*` removed from user devDeps, `playwright`/`webdriverio` preserved as peers, stale `vite-plus-test` catalog aliases normalized to `^4.1.5`). Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
1 parent 45703ff commit 365a61d

115 files changed

Lines changed: 900 additions & 5469 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/scripts/upgrade-deps.ts

Lines changed: 7 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -155,8 +155,13 @@ async function updatePnpmWorkspace(versions: PnpmWorkspaceVersions): Promise<voi
155155
const entries: PnpmWorkspaceEntry[] = [
156156
{
157157
name: 'vitest',
158-
pattern: /vitest-dev: npm:vitest@\^([\d.]+(?:-[\w.]+)?)/,
159-
replacement: `vitest-dev: npm:vitest@^${versions.vitest}`,
158+
// The `@voidzero-dev/vite-plus-test` wrapper (which used to be aliased
159+
// here via `vitest-dev: npm:vitest@^…`) has been removed. Vitest is now
160+
// a plain catalog entry pinned to an exact version (`vitest: x.y.z`),
161+
// so match that shape directly. The leading newline anchor disambiguates
162+
// from neighbouring keys like `vitepress-*` and `@vitest/browser`.
163+
pattern: /\n {2}vitest: ([\d.]+(?:-[\w.]+)?)\n/,
164+
replacement: `\n vitest: ${versions.vitest}\n`,
160165
newVersion: versions.vitest,
161166
},
162167
{
@@ -246,36 +251,6 @@ async function updatePnpmWorkspace(versions: PnpmWorkspaceVersions): Promise<voi
246251
console.log('Updated pnpm-workspace.yaml');
247252
}
248253

249-
// ============ Update packages/test/package.json ============
250-
async function updateTestPackage(vitestVersion: string): Promise<void> {
251-
const filePath = path.join(ROOT, 'packages/test/package.json');
252-
const pkg: PackageJson = readJsonFile(filePath);
253-
const devDependencies = pkg.devDependencies;
254-
if (!devDependencies) {
255-
throw new Error('packages/test/package.json is missing devDependencies');
256-
}
257-
258-
// Update all @vitest/* devDependencies
259-
for (const dep of Object.keys(devDependencies)) {
260-
if (dep.startsWith('@vitest/')) {
261-
devDependencies[dep] = vitestVersion;
262-
}
263-
}
264-
265-
// Update vitest-dev devDependency
266-
if (devDependencies['vitest-dev']) {
267-
devDependencies['vitest-dev'] = `^${vitestVersion}`;
268-
}
269-
270-
// Update @vitest/ui peerDependency if present
271-
if (pkg.peerDependencies?.['@vitest/ui']) {
272-
pkg.peerDependencies['@vitest/ui'] = vitestVersion;
273-
}
274-
275-
fs.writeFileSync(filePath, JSON.stringify(pkg, null, 2) + '\n');
276-
console.log('Updated packages/test/package.json');
277-
}
278-
279254
// ============ Update packages/core/package.json ============
280255
async function updateCorePackage(devtoolsVersion: string): Promise<void> {
281256
const filePath = path.join(ROOT, 'packages/core/package.json');
@@ -430,7 +405,6 @@ await updatePnpmWorkspace({
430405
oxcParser: oxcParserVersion,
431406
oxcTransform: oxcTransformVersion,
432407
});
433-
await updateTestPackage(vitestVersion);
434408
await updateCorePackage(devtoolsVersion);
435409

436410
writeMetaFiles();

.github/workflows/e2e-test.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,6 @@ jobs:
109109
run: |
110110
mkdir -p tmp/tgz
111111
cd packages/core && pnpm pack --pack-destination ../../tmp/tgz && cd ../..
112-
cd packages/test && pnpm pack --pack-destination ../../tmp/tgz && cd ../..
113112
cd packages/cli && pnpm pack --pack-destination ../../tmp/tgz && cd ../..
114113
# Copy vp binary for e2e-test job (findVpBinary expects it in target/)
115114
cp target/${{ matrix.target }}/release/vp tmp/tgz/vp 2>/dev/null || cp target/${{ matrix.target }}/release/vp.exe tmp/tgz/vp.exe 2>/dev/null || true

.github/workflows/prepare_release.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ jobs:
5454
}
5555
update_json packages/cli/package.json
5656
update_json packages/core/package.json
57-
update_json packages/test/package.json
5857
update_toml packages/cli/binding/Cargo.toml
5958
update_toml crates/vite_global_cli/Cargo.toml
6059

.github/workflows/publish-to-pkg.pr.new.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,5 +136,4 @@ jobs:
136136
'./packages/cli/cli-npm/*' \
137137
'./packages/cli' \
138138
'./packages/core' \
139-
'./packages/prompts' \
140-
'./packages/test'
139+
'./packages/prompts'

.github/workflows/release.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,6 @@ jobs:
157157
- name: Publish
158158
run: |
159159
pnpm publish --filter=./packages/core --tag latest --access public --no-git-checks
160-
pnpm publish --filter=./packages/test --tag latest --access public --no-git-checks
161160
pnpm publish --filter=./packages/cli --tag latest --access public --no-git-checks
162161
163162
- name: Create release body
@@ -173,7 +172,6 @@ jobs:
173172
### Published Packages
174173
175174
- \`@voidzero-dev/vite-plus-core@${VERSION}\`
176-
- \`@voidzero-dev/vite-plus-test@${VERSION}\`
177175
- \`vite-plus@${VERSION}\`
178176
179177
### Installation
@@ -222,7 +220,6 @@ jobs:
222220
223221
**Published Packages:**
224222
• @voidzero-dev/vite-plus-core@${{ env.VERSION }}
225-
• @voidzero-dev/vite-plus-test@${{ env.VERSION }}
226223
• vite-plus@${{ env.VERSION }}
227224
228225
**Install:**

.github/workflows/test-vp-create.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,6 @@ jobs:
9494
run: |
9595
mkdir -p tmp/tgz
9696
cd packages/core && pnpm pack --pack-destination ../../tmp/tgz && cd ../..
97-
cd packages/test && pnpm pack --pack-destination ../../tmp/tgz && cd ../..
9897
cd packages/cli && pnpm pack --pack-destination ../../tmp/tgz && cd ../..
9998
# Copy vp binary for test jobs
10099
cp target/x86_64-unknown-linux-gnu/release/vp tmp/tgz/vp
@@ -152,7 +151,7 @@ jobs:
152151
- yarn
153152
- bun
154153
env:
155-
VP_OVERRIDE_PACKAGES: '{"vite":"file:${{ github.workspace }}/tmp/tgz/voidzero-dev-vite-plus-core-0.0.0.tgz","vitest":"file:${{ github.workspace }}/tmp/tgz/voidzero-dev-vite-plus-test-0.0.0.tgz","@voidzero-dev/vite-plus-core":"file:${{ github.workspace }}/tmp/tgz/voidzero-dev-vite-plus-core-0.0.0.tgz","@voidzero-dev/vite-plus-test":"file:${{ github.workspace }}/tmp/tgz/voidzero-dev-vite-plus-test-0.0.0.tgz"}'
154+
VP_OVERRIDE_PACKAGES: '{"vite":"file:${{ github.workspace }}/tmp/tgz/voidzero-dev-vite-plus-core-0.0.0.tgz","@voidzero-dev/vite-plus-core":"file:${{ github.workspace }}/tmp/tgz/voidzero-dev-vite-plus-core-0.0.0.tgz"}'
156155
VP_VERSION: 'file:${{ github.workspace }}/tmp/tgz/vite-plus-0.0.0.tgz'
157156
# Force full dependency rewriting so the library template's existing
158157
# vite-plus dep gets overridden with the local tgz

README.md

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -189,12 +189,11 @@ If you are manually migrating a project to Vite+, install these dev dependencies
189189
npm install -D vite-plus @voidzero-dev/vite-plus-core@latest
190190
```
191191

192-
You need to add overrides to your package manager for `vite` and `vitest` so that other packages depending on Vite and Vitest will use the Vite+ versions:
192+
You need to add overrides to your package manager for `vite` so that other packages depending on Vite (including Vitest) will use the Vite+ version:
193193

194194
```json
195195
"overrides": {
196-
"vite": "npm:@voidzero-dev/vite-plus-core@latest",
197-
"vitest": "npm:@voidzero-dev/vite-plus-test@latest"
196+
"vite": "npm:@voidzero-dev/vite-plus-core@latest"
198197
}
199198
```
200199

@@ -203,15 +202,13 @@ If you are using `pnpm`, add this to your `pnpm-workspace.yaml`:
203202
```yaml
204203
overrides:
205204
vite: npm:@voidzero-dev/vite-plus-core@latest
206-
vitest: npm:@voidzero-dev/vite-plus-test@latest
207205
```
208206
209207
Or, if you are using Yarn:
210208
211209
```json
212210
"resolutions": {
213-
"vite": "npm:@voidzero-dev/vite-plus-core@latest",
214-
"vitest": "npm:@voidzero-dev/vite-plus-test@latest"
211+
"vite": "npm:@voidzero-dev/vite-plus-core@latest"
215212
}
216213
```
217214

crates/vite_global_cli/src/commands/version.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,7 @@ const TOOL_SPECS: [ToolSpec; 7] = [
4747
package_name: "@voidzero-dev/vite-plus-core",
4848
bundled_version_key: Some("rolldown"),
4949
},
50-
ToolSpec {
51-
display_name: "vitest",
52-
package_name: "@voidzero-dev/vite-plus-test",
53-
bundled_version_key: Some("vitest"),
54-
},
50+
ToolSpec { display_name: "vitest", package_name: "vitest", bundled_version_key: None },
5551
ToolSpec { display_name: "oxfmt", package_name: "oxfmt", bundled_version_key: None },
5652
ToolSpec { display_name: "oxlint", package_name: "oxlint", bundled_version_key: None },
5753
ToolSpec {

crates/vite_migration/src/file_walker.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,12 @@ use std::path::{Path, PathBuf};
33
use ignore::WalkBuilder;
44
use vite_error::Error;
55

6-
// TODO: only support esm files for now
7-
/// File extensions to process for import rewriting
8-
const TS_JS_EXTENSIONS: &[&str] = &["ts", "tsx", "mts", "js", "jsx", "mjs"];
6+
/// File extensions to process for import rewriting.
7+
///
8+
/// Includes CommonJS (`.cjs`/`.cts`) variants in addition to ESM, because
9+
/// the legacy reverse-migration rules also cover `require('vite-plus/test/browser-*')`
10+
/// calls that are most commonly found in `.cjs` / `vitest.config.cjs` files.
11+
const TS_JS_EXTENSIONS: &[&str] = &["ts", "tsx", "mts", "cts", "js", "jsx", "mjs", "cjs"];
912

1013
/// Result of walking TypeScript/JavaScript files
1114
#[derive(Debug)]
@@ -164,7 +167,7 @@ mod tests {
164167

165168
let result = find_ts_files(temp.path()).unwrap();
166169

167-
assert_eq!(result.files.len(), 6);
170+
assert_eq!(result.files.len(), 8);
168171
}
169172

170173
#[test]

docs/guide/migrate.md

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,8 @@ Migrate this project to Vite+. Vite+ replaces the current split tooling around r
7575
After the migration:
7676

7777
- Confirm `vite` imports were rewritten to `vite-plus` where needed
78-
- Confirm `vitest` imports were rewritten to `vite-plus/test` where needed
79-
- Remove old `vite` and `vitest` dependencies only after those rewrites are confirmed
78+
- Confirm `vitest/config` imports were rewritten to `vite-plus` (other `vitest` and `@vitest/browser*` imports are intentionally left as-is)
79+
- Remove the old `vite` dependency only after those rewrites are confirmed; keep `vitest` and any `@vitest/browser*` providers
8080
- Move remaining tool-specific config into the appropriate blocks in `vite.config.ts`
8181

8282
Command mapping to keep in mind:
@@ -96,20 +96,28 @@ Summarize the migration at the end and report any manual follow-up still require
9696

9797
### Vitest
9898

99-
Vitest is automatically migrated through `vp migrate`. If you are migrating manually, you have to update all the imports to `vite-plus/test` instead:
99+
`vp migrate` is the recommended path. It only rewrites `vitest/config` imports to `vite-plus`; all other Vitest imports are left untouched and resolve through the upstream `vitest` package as usual (`vite` is aliased to `@voidzero-dev/vite-plus-core` via overrides, so Vitest picks up the Vite+ core transparently).
100+
101+
If you are migrating manually, update only the config entry point:
100102

101103
```ts
102104
// before
103-
import { describe, expect, it, vi } from 'vitest';
104-
105-
const { page } = await import('@vitest/browser/context');
105+
import { defineConfig } from 'vitest/config';
106106

107107
// after
108-
import { describe, expect, it, vi } from 'vite-plus/test';
108+
import { defineConfig } from 'vite-plus';
109+
```
109110

110-
const { page } = await import('vite-plus/test/browser/context');
111+
Runtime imports stay as-is:
112+
113+
```ts
114+
import { describe, expect, it, vi } from 'vitest';
115+
116+
const { page } = await import('@vitest/browser/context');
111117
```
112118

119+
Do not rewrite bare `vitest`, `vitest/*` subpaths, or `@vitest/browser*` — Vitest's mock hoister requires the literal string `'vitest'`, and the browser/provider subpaths are not re-exported by `vite-plus`.
120+
113121
### tsdown
114122

115123
If your project uses a `tsdown.config.ts`, move its options into the `pack` block in `vite.config.ts`:

0 commit comments

Comments
 (0)