diff --git a/packages/cli/build.ts b/packages/cli/build.ts index 26b06d2810..d271068f83 100644 --- a/packages/cli/build.ts +++ b/packages/cli/build.ts @@ -40,8 +40,8 @@ const { task } = await cli.build({ const output = (await task).find((o) => o.kind === 'node'); await build({ - input: ['./src/bin.ts', './src/index.ts'], - external: [/^node:/, 'rolldown-vite'], + input: ['./src/bin.ts', './src/index.ts', './src/test.ts'], + external: [/^node:/, 'rolldown-vite', 'vitest'], output: { format: 'esm', }, @@ -64,6 +64,7 @@ const program = createProgram({ rootNames: [ join(srcDir, 'index.ts'), join(srcDir, 'client.ts'), + join(srcDir, 'test.ts'), ], options: { ...options, diff --git a/packages/cli/package.json b/packages/cli/package.json index d6845b4950..ee3f2fa697 100644 --- a/packages/cli/package.json +++ b/packages/cli/package.json @@ -16,6 +16,10 @@ }, "./client": { "types": "./dist/client.d.ts" + }, + "./test": { + "import": "./dist/test.js", + "types": "./dist/test.d.ts" } }, "engines": { diff --git a/packages/cli/src/bin.ts b/packages/cli/src/bin.ts index 0db16a4396..f09633e5a6 100644 --- a/packages/cli/src/bin.ts +++ b/packages/cli/src/bin.ts @@ -10,12 +10,12 @@ */ import { run } from '../binding/index.js'; -import { doc } from './doc.js'; -import { fmt } from './fmt.js'; -import { lib } from './lib.js'; -import { lint } from './lint.js'; -import { test } from './test.js'; -import { vite } from './vite.js'; +import { doc } from './resolve-doc.js'; +import { fmt } from './resolve-fmt.js'; +import { lib } from './resolve-lib.js'; +import { lint } from './resolve-lint.js'; +import { test } from './resolve-test.js'; +import { vite } from './resolve-vite.js'; async function resolveUniversalViteConfig(err: null | Error, viteConfigCwd: string) { if (err) { diff --git a/packages/cli/src/doc.ts b/packages/cli/src/resolve-doc.ts similarity index 100% rename from packages/cli/src/doc.ts rename to packages/cli/src/resolve-doc.ts diff --git a/packages/cli/src/fmt.ts b/packages/cli/src/resolve-fmt.ts similarity index 100% rename from packages/cli/src/fmt.ts rename to packages/cli/src/resolve-fmt.ts diff --git a/packages/cli/src/lib.ts b/packages/cli/src/resolve-lib.ts similarity index 100% rename from packages/cli/src/lib.ts rename to packages/cli/src/resolve-lib.ts diff --git a/packages/cli/src/lint.ts b/packages/cli/src/resolve-lint.ts similarity index 100% rename from packages/cli/src/lint.ts rename to packages/cli/src/resolve-lint.ts diff --git a/packages/cli/src/resolve-test.ts b/packages/cli/src/resolve-test.ts new file mode 100644 index 0000000000..4150679444 --- /dev/null +++ b/packages/cli/src/resolve-test.ts @@ -0,0 +1,42 @@ +/** + * Vitest tool resolver for the vite-plus CLI. + * + * This module exports a function that resolves the Vitest binary path + * using Node.js module resolution. The resolved path is passed back + * to the Rust core, which then executes Vitest for running tests. + * + * Used for: `vite-plus test` command + */ + +import { DEFAULT_ENVS, resolve } from './utils.js'; + +/** + * Resolves the Vitest binary path and environment variables. + * + * @returns Promise containing: + * - binPath: Absolute path to the Vitest CLI entry point (vitest.mjs) + * - envs: Environment variables to set when executing Vitest + * + * Vitest is Vite's testing framework that provides a Jest-compatible + * testing experience with Vite's fast HMR and transformation pipeline. + */ +export async function test(): Promise<{ + binPath: string; + envs: Record; +}> { + // Resolve the Vitest CLI module directly + const binPath = resolve('vitest/vitest.mjs'); + + return { + binPath, + // Pass through source map debugging environment variable if set + envs: process.env.DEBUG_DISABLE_SOURCE_MAP + ? { + ...DEFAULT_ENVS, + DEBUG_DISABLE_SOURCE_MAP: process.env.DEBUG_DISABLE_SOURCE_MAP, + } + : { + ...DEFAULT_ENVS, + }, + }; +} diff --git a/packages/cli/src/vite.ts b/packages/cli/src/resolve-vite.ts similarity index 100% rename from packages/cli/src/vite.ts rename to packages/cli/src/resolve-vite.ts diff --git a/packages/cli/src/test.ts b/packages/cli/src/test.ts index 4150679444..3f058bce8f 100644 --- a/packages/cli/src/test.ts +++ b/packages/cli/src/test.ts @@ -1,42 +1 @@ -/** - * Vitest tool resolver for the vite-plus CLI. - * - * This module exports a function that resolves the Vitest binary path - * using Node.js module resolution. The resolved path is passed back - * to the Rust core, which then executes Vitest for running tests. - * - * Used for: `vite-plus test` command - */ - -import { DEFAULT_ENVS, resolve } from './utils.js'; - -/** - * Resolves the Vitest binary path and environment variables. - * - * @returns Promise containing: - * - binPath: Absolute path to the Vitest CLI entry point (vitest.mjs) - * - envs: Environment variables to set when executing Vitest - * - * Vitest is Vite's testing framework that provides a Jest-compatible - * testing experience with Vite's fast HMR and transformation pipeline. - */ -export async function test(): Promise<{ - binPath: string; - envs: Record; -}> { - // Resolve the Vitest CLI module directly - const binPath = resolve('vitest/vitest.mjs'); - - return { - binPath, - // Pass through source map debugging environment variable if set - envs: process.env.DEBUG_DISABLE_SOURCE_MAP - ? { - ...DEFAULT_ENVS, - DEBUG_DISABLE_SOURCE_MAP: process.env.DEBUG_DISABLE_SOURCE_MAP, - } - : { - ...DEFAULT_ENVS, - }, - }; -} +export * from 'vitest'; diff --git a/packages/tools/src/__tests__/utils.spec.ts b/packages/tools/src/__tests__/utils.spec.ts index 5fddd2340c..25bb181d37 100644 --- a/packages/tools/src/__tests__/utils.spec.ts +++ b/packages/tools/src/__tests__/utils.spec.ts @@ -1,6 +1,6 @@ import { tmpdir } from 'node:os'; -import { describe, expect, test } from 'vitest'; +import { describe, expect, test } from '@voidzero-dev/vite-plus/test'; import { replaceUnstableOutput } from '../utils.ts';