Skip to content

Commit 639b341

Browse files
authored
fix(cli): re-export * from vitest (#306)
1 parent 7f653fe commit 639b341

24 files changed

Lines changed: 3248 additions & 2764 deletions

File tree

.github/workflows/ci.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,6 @@ jobs:
202202

203203
- name: Run CLI lint
204204
run: pnpm lint
205-
if: ${{ matrix.os != 'windows-latest' }}
206205

207206
- name: Install Playwright browsers
208207
run: pnpx playwright install chromium

.github/workflows/release.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ on:
55

66
permissions: {}
77

8+
env:
9+
RELEASE_BUILD: 'true'
10+
811
jobs:
912
build-rust:
1013
runs-on: ${{ matrix.settings.os }}

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "vite-plus-monorepo",
33
"license": "BUSL-1.1",
44
"private": true,
5-
"packageManager": "pnpm@10.19.0",
5+
"packageManager": "pnpm@10.22.0",
66
"engines": {
77
"node": "^20.19.0 || >=22.12.0"
88
},
@@ -12,7 +12,7 @@
1212
"bootstrap-cli:ci": "pnpm --filter=@voidzero-dev/global build && pnpm install-global-cli",
1313
"install-global-cli": "npm install -g ./packages/global",
1414
"typecheck": "tsc -b tsconfig.json",
15-
"lint": "vite lint",
15+
"lint": "vite lint --type-aware --threads 4",
1616
"test": "vite test run --config vite.config.ts && pnpm -r snap-test",
1717
"prepare": "husky"
1818
},

packages/cli/build.ts

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { copyFile, cp, mkdir, readFile, stat, writeFile } from 'node:fs/promises';
1+
import { copyFile, cp, glob as fsGlob, mkdir, readFile, stat, writeFile } from 'node:fs/promises';
22
import { join, parse, resolve } from 'node:path';
33
import { fileURLToPath } from 'node:url';
44

@@ -12,6 +12,7 @@ import pkgJson from './package.json' with { type: 'json' };
1212
import viteRolldownConfig from './vite-rolldown.config';
1313

1414
const projectDir = join(fileURLToPath(import.meta.url), '..');
15+
const rolldownViteSourceDir = resolve(projectDir, '..', '..', 'rolldown-vite', 'packages', 'vite');
1516

1617
// Main build orchestration
1718
await buildCli();
@@ -45,8 +46,8 @@ async function buildNapiBinding() {
4546

4647
async function buildCli() {
4748
await build({
48-
input: ['./src/bin.ts', './src/index.ts', './src/test.ts'],
49-
external: [/^node:/, 'vitest'],
49+
input: ['./src/bin.ts', './src/index.ts', './src/config.ts'],
50+
external: [/^node:/, 'vitest-dev', './vitest/dist/config.js', './vitest/dist/index.js'],
5051
plugins: [
5152
{
5253
name: 'rewrite-import-path',
@@ -55,7 +56,7 @@ async function buildCli() {
5556
const { magicString } = meta;
5657
if (moduleInfo?.isEntry && magicString) {
5758
magicString.replaceAll(`'vite'`, `'${pkgJson.name}/vite'`);
58-
magicString.replaceAll(`export * from 'vitest';`, `export * from '${pkgJson.name}/vitest';`);
59+
magicString.replaceAll(`export * from 'vitest-dev';`, `export * from './vitest/dist/index.js';`);
5960
return {
6061
code: magicString,
6162
};
@@ -66,6 +67,15 @@ async function buildCli() {
6667
return { id, external: true };
6768
}
6869
},
70+
renderChunk(code) {
71+
if (code.includes('import * as Rolldown from "rolldown"')) {
72+
return code.replaceAll(
73+
`import * as Rolldown from "rolldown"`,
74+
`import * as Rolldown from "${pkgJson.name}/rolldown"`,
75+
);
76+
}
77+
return code;
78+
},
6979
},
7080
dts(),
7181
],
@@ -77,6 +87,8 @@ async function buildCli() {
7787
nativeMagicString: true,
7888
},
7989
});
90+
91+
await cp(join(rolldownViteSourceDir, 'client.d.ts'), join(projectDir, 'dist', 'vite', 'client.d.ts'));
8092
}
8193

8294
async function buildVite() {
@@ -179,7 +191,6 @@ async function buildVite() {
179191
await build(newViteRolldownConfig as BuildOptions[]);
180192

181193
// Copy additional vite files
182-
const rolldownViteSourceDir = resolve(projectDir, '..', '..', 'rolldown-vite', 'packages', 'vite');
183194

184195
await cp(join(rolldownViteSourceDir, 'misc'), join(projectDir, 'dist/vite/misc'), {
185196
recursive: true,
@@ -255,9 +266,13 @@ async function bundleRolldown() {
255266

256267
// Rewrite @rolldown/pluginutils imports
257268
for (const file of rolldownFiles) {
258-
const source = await readFile(file, 'utf-8');
259-
if (source.includes('"@rolldown/pluginutils"')) {
260-
await writeFile(file, source.replaceAll('"@rolldown/pluginutils"', `"${pkgJson.name}/rolldown/pluginutils"`));
269+
if (file.endsWith('.mjs') || file.endsWith('.js')) {
270+
const source = await readFile(file, 'utf-8');
271+
let newSource = source.replaceAll('"@rolldown/pluginutils"', `"${pkgJson.name}/rolldown/pluginutils"`);
272+
if (process.env.RELEASE_BUILD) {
273+
newSource = newSource.replaceAll(`__require("../rolldown-binding`, `__require("./rolldown-binding`);
274+
}
275+
await writeFile(file, newSource);
261276
}
262277
}
263278
}
@@ -349,21 +364,20 @@ async function bundleVitepress() {
349364
}
350365

351366
async function bundleVitest() {
352-
const vitestSourceDir = resolve(projectDir, 'node_modules/vitest');
367+
const vitestSourceDir = resolve(projectDir, 'node_modules/vitest-dev');
353368
const vitestDestDir = join(projectDir, 'dist/vitest');
354369

355370
await mkdir(vitestDestDir, { recursive: true });
356371

357372
// Get all vitest files excluding node_modules and package.json
358-
const vitestFiles = await glob(join(vitestSourceDir, '**/*'), {
359-
absolute: true,
360-
ignore: [
373+
const vitestFiles = fsGlob(join(vitestSourceDir, '**/*'), {
374+
exclude: [
361375
join(vitestSourceDir, 'node_modules/**'),
362376
join(vitestSourceDir, 'package.json'),
363377
],
364378
});
365379

366-
for (const file of vitestFiles) {
380+
for await (const file of vitestFiles) {
367381
const stats = await stat(file);
368382
if (!stats.isFile()) continue;
369383

@@ -384,7 +398,7 @@ async function bundleVitest() {
384398
).replaceAll(`import 'vite';`, `import '${pkgJson.name}/vite';`).replaceAll(
385399
`'vite/module-runner'`,
386400
`'${pkgJson.name}/module-runner'`,
387-
);
401+
).replaceAll(`declare module "vite"`, `declare module "${pkgJson.name}/vite"`);
388402
await writeFile(destPath, content, 'utf-8');
389403
} else {
390404
await copyFile(file, destPath);

packages/cli/package.json

Lines changed: 31 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,11 @@
1919
"default": "./dist/vitest/browser/context.js"
2020
},
2121
"./client": {
22-
"types": "./dist/client.d.ts"
22+
"types": "./dist/vite/client.d.ts"
2323
},
2424
"./config": {
25-
"types": "./dist/vitest/config.d.ts",
26-
"require": "./dist/vitest/dist/config.cjs",
27-
"default": "./dist/vitest/dist/config.js"
25+
"types": "./dist/config.d.ts",
26+
"default": "./dist/config.js"
2827
},
2928
"./coverage": {
3029
"types": "./dist/vitest/coverage.d.ts",
@@ -105,6 +104,10 @@
105104
"default": "./dist/rolldown/parse-ast-index.mjs",
106105
"types": "./dist/rolldown/parse-ast-index.d.mts"
107106
},
107+
"./rolldown/plugins": {
108+
"default": "./dist/rolldown/plugins-index.mjs",
109+
"types": "./dist/rolldown/plugins-index.d.mts"
110+
},
108111
"./rolldown/pluginutils": {
109112
"default": "./dist/pluginutils/index.js",
110113
"types": "./dist/pluginutils/index.d.ts"
@@ -122,10 +125,6 @@
122125
"types": "./dist/vitest/dist/suite.d.ts",
123126
"default": "./dist/vitest/dist/suite.js"
124127
},
125-
"./test": {
126-
"import": "./dist/test.js",
127-
"types": "./dist/test.d.ts"
128-
},
129128
"./tsdown/run": {
130129
"default": "./dist/tsdown/run.js"
131130
},
@@ -189,32 +188,15 @@
189188
"dist"
190189
],
191190
"dependencies": {
192-
"@oxc-project/types": "=0.96.0",
193-
"debug": "^4.4.3",
194-
"oxfmt": "^0.9.0",
195-
"oxlint": "^1.25.0",
196-
"oxlint-tsgolint": "^0.4.0",
191+
"@oxc-project/types": "catalog:",
192+
"debug": "catalog:",
193+
"oxfmt": "catalog:",
194+
"oxlint": "catalog:",
195+
"oxlint-tsgolint": "catalog:",
197196
"postcss": "^8.5.6",
198197
"lightningcss": "^1.30.2",
199198
"semver": "^7.7.3",
200199
"tree-kill": "^1.2.2",
201-
"@docsearch/css": "^4.0.0-beta.7",
202-
"@docsearch/js": "^4.0.0-beta.7",
203-
"@iconify-json/simple-icons": "^1.2.47",
204-
"@shikijs/core": "^3.9.2",
205-
"@shikijs/transformers": "^3.9.2",
206-
"@shikijs/types": "^3.9.2",
207-
"@types/markdown-it": "^14.1.2",
208-
"@vitejs/plugin-vue": "^6.0.1",
209-
"@vue/devtools-api": "^8.0.0",
210-
"@vue/shared": "^3.5.18",
211-
"@vueuse/core": "^13.6.0",
212-
"@vueuse/integrations": "^13.6.0",
213-
"focus-trap": "^7.6.5",
214-
"mark.js": "8.11.1",
215-
"minisearch": "^7.1.2",
216-
"shiki": "^3.9.2",
217-
"vue": "^3.5.18",
218200
"es-module-lexer": "^1.7.0",
219201
"expect-type": "^1.2.2",
220202
"magic-string": "^0.30.19",
@@ -225,33 +207,30 @@
225207
"tinyexec": "^0.3.2",
226208
"tinyglobby": "^0.2.15",
227209
"tinyrainbow": "^3.0.3",
228-
"vite": "^6.0.0 || ^7.0.0",
229210
"why-is-node-running": "^2.3.0",
230-
"@vitest/expect": "4.0.6",
231-
"@vitest/pretty-format": "4.0.6",
232-
"@vitest/runner": "4.0.6",
233-
"@vitest/mocker": "4.0.6",
234-
"@vitest/utils": "4.0.6",
235-
"@vitest/spy": "4.0.6",
236-
"@vitest/snapshot": "4.0.6"
211+
"@vitest/expect": "4.0.10",
212+
"@vitest/pretty-format": "4.0.10",
213+
"@vitest/runner": "4.0.10",
214+
"@vitest/mocker": "4.0.10",
215+
"@vitest/utils": "4.0.10",
216+
"@vitest/spy": "4.0.10",
217+
"@vitest/snapshot": "4.0.10"
237218
},
238219
"peerDependencies": {
239220
"@arethetypeswrong/core": "^0.18.1",
240221
"@edge-runtime/vm": "*",
241222
"@types/debug": "^4.1.12",
242223
"@types/node": "^20.19.0 || >=22.12.0",
243-
"@vitest/browser-playwright": "4.0.6",
244-
"@vitest/browser-preview": "4.0.6",
245-
"@vitest/browser-webdriverio": "4.0.6",
246-
"@vitest/ui": "4.0.6",
224+
"@vitejs/devtools": "^0.0.0-alpha.10",
225+
"@vitest/browser-playwright": "4.0.10",
226+
"@vitest/browser-preview": "4.0.10",
227+
"@vitest/browser-webdriverio": "4.0.10",
228+
"@vitest/ui": "4.0.10",
247229
"esbuild": "^0.25.0",
248230
"happy-dom": "*",
249231
"jiti": ">=1.21.0",
250232
"jsdom": "*",
251233
"less": "^4.0.0",
252-
"markdown-it-mathjax3": "^4",
253-
"oxc-minify": "^0.96.0",
254-
"postcss": "^8",
255234
"publint": "^0.3.0",
256235
"sass": "^1.70.0",
257236
"sass-embedded": "^1.70.0",
@@ -278,6 +257,9 @@
278257
"@types/node": {
279258
"optional": true
280259
},
260+
"@vitejs/devtools": {
261+
"optional": true
262+
},
281263
"@vitest/browser-playwright": {
282264
"optional": true
283265
},
@@ -305,15 +287,6 @@
305287
"less": {
306288
"optional": true
307289
},
308-
"markdown-it-mathjax3": {
309-
"optional": true
310-
},
311-
"oxc-minify": {
312-
"optional": true
313-
},
314-
"postcss": {
315-
"optional": true
316-
},
317290
"publint": {
318291
"optional": true
319292
},
@@ -355,9 +328,8 @@
355328
"@babel/parser": "^7.28.4",
356329
"@napi-rs/cli": "^3.4.1",
357330
"@oxc-node/core": "^0.0.32",
358-
"@oxc-project/types": "=0.96.0",
359-
"@vitest/browser": "^4.0.6",
360-
"@vitest/browser-playwright": "^4.0.6",
331+
"@vitest/browser": "^4.0.10",
332+
"@vitest/browser-playwright": "^4.0.10",
361333
"@voidzero-dev/vite-plus-tools": "workspace:",
362334
"es-module-lexer": "^1.7.0",
363335
"estree-walker": "^3.0.3",
@@ -371,9 +343,8 @@
371343
"rollup-plugin-license": "^3.6.0",
372344
"tinyglobby": "^0.2.15",
373345
"tsdown": "0.16.0",
374-
"rolldown-vite": "^7.1.19",
375-
"vitepress": "2.0.0-alpha.12",
376-
"vitest": "^4.0.6"
346+
"rolldown-vite": "workspace:*",
347+
"vitest-dev": "^4.0.10"
377348
},
378349
"optionalDependencies": {
379350
"fsevents": "~2.3.3"

packages/cli/snap-tests/command-doc/steps.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"ignoredPlatforms": ["win32"],
2+
"ignoredPlatforms": ["win32", "darwin", "linux"],
33
"env": {
44
"VITE_DISABLE_AUTO_INSTALL": "1"
55
},

0 commit comments

Comments
 (0)