Skip to content

Commit 69cf07f

Browse files
Brooooooklynclaude
andcommitted
feat(test): support CLI package path aliases in vendor-aliases plugin
Added support for `@voidzero-dev/vite-plus/test/*` subpath imports in addition to existing `vitest/*` and `@voidzero-dev/vite-plus-test/*` patterns. All three import patterns now work: - `vitest/browser-playwright` (Recommended, requires vitest override) - `@voidzero-dev/vite-plus-test/browser-playwright` (direct test package) - `@voidzero-dev/vite-plus/test/browser-playwright` (direct CLI package) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 45b7e4a commit 69cf07f

2 files changed

Lines changed: 27 additions & 12 deletions

File tree

packages/test/BUNDLING.md

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -108,10 +108,11 @@ For maintainers developing the vitest/vite migration feature, here are the trans
108108
| `from "vite"` | `from "@voidzero-dev/vite-plus-core"` |
109109
| `from "vite/module-runner"` | `from "@voidzero-dev/vite-plus-core/module-runner"` |
110110

111-
**Note:** When using pnpm overrides, you have two options for the playwright import:
111+
**Note:** When using pnpm overrides, you have three options for the playwright import:
112112

113-
- `vitest/browser-playwright` - works when `vitest` is overridden to our package
114-
- `@voidzero-dev/vite-plus-test/browser-playwright` - always works (direct import)
113+
- `vitest/browser-playwright` - works when `vitest` is overridden to our package (Recommended)
114+
- `@voidzero-dev/vite-plus-test/browser-playwright` - direct import from test package
115+
- `@voidzero-dev/vite-plus/test/browser-playwright` - direct import from CLI package
115116

116117
Importing from `@vitest/browser-playwright` requires an additional override for that specific package.
117118

@@ -156,11 +157,14 @@ overrides:
156157
// Before
157158
import { playwright } from '@vitest/browser-playwright';
158159

159-
// After - Option 1: Direct import (always works)
160+
// After - Option 1 (Recommended): Via vitest subpath (works when vitest is overridden)
161+
import { playwright } from 'vitest/browser-playwright';
162+
163+
// After - Option 2: Direct import from test package
160164
import { playwright } from '@voidzero-dev/vite-plus-test/browser-playwright';
161165

162-
// After - Option 2: Via vitest subpath (works when vitest is overridden)
163-
import { playwright } from 'vitest/browser-playwright';
166+
// After - Option 3: Direct import from CLI package
167+
import { playwright } from '@voidzero-dev/vite-plus/test/browser-playwright';
164168
```
165169

166170
### Plugin Exports for pnpm Overrides
@@ -327,7 +331,8 @@ This is achieved through:
327331
- Handles `@vitest/*` imports → resolves to copied `dist/@vitest/` files
328332
- Handles `vitest/*` subpaths → resolves to dist files (enables `vitest/browser-playwright` usage)
329333
- Handles `@voidzero-dev/vite-plus-test/*` subpaths → maps to equivalent vitest paths
330-
- Intercepts `vitest/browser` → returns virtual module ID for BrowserContext plugin
334+
- Handles `@voidzero-dev/vite-plus/test/*` subpaths → maps to equivalent vitest paths (CLI package)
335+
- Intercepts `vitest/browser`, `@voidzero-dev/vite-plus-test/browser`, `@voidzero-dev/vite-plus/test/browser` → returns virtual module ID for BrowserContext plugin
331336

332337
### Key Constants
333338

packages/test/build.ts

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1148,9 +1148,10 @@ async function patchVitestBrowserPackage() {
11481148
if (id === '${CORE_PACKAGE_NAME}' || id === 'vite') {
11491149
return { id, external: true };
11501150
}
1151-
// Handle vitest/browser and @voidzero-dev/vite-plus-test/browser
1151+
// Handle vitest/browser and package aliases
11521152
// Return virtual module ID so BrowserContext plugin can load it
1153-
if (id === 'vitest/browser' || id === '@voidzero-dev/vite-plus-test/browser') {
1153+
// Supports: vitest/browser, @voidzero-dev/vite-plus-test/browser, @voidzero-dev/vite-plus/test/browser
1154+
if (id === 'vitest/browser' || id === '@voidzero-dev/vite-plus-test/browser' || id === '@voidzero-dev/vite-plus/test/browser') {
11541155
return '\\0vitest/browser';
11551156
}
11561157
// Handle vitest/* subpaths (resolve to our dist files)
@@ -1178,6 +1179,14 @@ async function patchVitestBrowserPackage() {
11781179
return vitestSubpathMap[vitestEquiv];
11791180
}
11801181
}
1182+
// Handle @voidzero-dev/vite-plus/test/* subpaths (CLI package paths, same as vitest/*)
1183+
if (id.startsWith('@voidzero-dev/vite-plus/test/')) {
1184+
const subpath = id.slice('@voidzero-dev/vite-plus/test/'.length);
1185+
const vitestEquiv = 'vitest/' + subpath;
1186+
if (vitestSubpathMap[vitestEquiv]) {
1187+
return vitestSubpathMap[vitestEquiv];
1188+
}
1189+
}
11811190
// Handle @vitest/* packages (resolve to our copied files)
11821191
const vendorMap = {
11831192
${mappingEntries}
@@ -1235,15 +1244,16 @@ async function patchVitestBrowserPackage() {
12351244
}
12361245
console.log(' Removed bundled deps from include list');
12371246

1238-
// 4. Patch BrowserContext to also handle @voidzero-dev/vite-plus-test/browser
1247+
// 4. Patch BrowserContext to also handle our package aliases as fallback
12391248
// This allows direct imports from our package without requiring vitest override
1249+
// Supports: @voidzero-dev/vite-plus-test/browser, @voidzero-dev/vite-plus/test/browser
12401250
const browserContextPattern = /if \(id === ID_CONTEXT\) \{/;
12411251
if (browserContextPattern.test(content)) {
12421252
content = content.replace(
12431253
browserContextPattern,
1244-
`if (id === ID_CONTEXT || id === "@voidzero-dev/vite-plus-test/browser") {`,
1254+
`if (id === ID_CONTEXT || id === "@voidzero-dev/vite-plus-test/browser" || id === "@voidzero-dev/vite-plus/test/browser") {`,
12451255
);
1246-
console.log(' Patched BrowserContext to handle @voidzero-dev/vite-plus-test/browser');
1256+
console.log(' Patched BrowserContext to handle package aliases');
12471257
} else {
12481258
console.log(' Warning: Could not find BrowserContext pattern to patch');
12491259
}

0 commit comments

Comments
 (0)