Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions packages/cli/snap-tests/command-helper/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{
}
291 changes: 291 additions & 0 deletions packages/cli/snap-tests/command-helper/snap.txt

Large diffs are not rendered by default.

12 changes: 12 additions & 0 deletions packages/cli/snap-tests/command-helper/steps.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"env": {
"VITE_DISABLE_AUTO_INSTALL": "1"
},
"commands": [
"vite lib -h # lib help message",
"vite fmt -h # fmt help message",
"vite lint -h # lint help message",
"vite build -h # build help message",
"vite test -h # test help message"
]
}
2 changes: 1 addition & 1 deletion packages/cli/snap-tests/command-lib/snap.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
> vite lib -h # should print the help message
tsdown/0.15.1
tsdown/<semver>

Usage:
$ tsdown [...files]
Expand Down
17 changes: 3 additions & 14 deletions packages/cli/src/doc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,8 @@
* Used for: `vite doc` command
*/

import { createRequire } from 'node:module';
import { dirname, join } from 'node:path';
import { fileURLToPath } from 'node:url';

const require = createRequire(import.meta.url);
import { DEFAULT_ENVS, resolve } from './utils.js';

/**
* Resolves the VitePress binary path and environment variables.
Expand All @@ -29,23 +26,15 @@ export async function doc(): Promise<{
binPath: string;
envs: Record<string, string>;
}> {
const paths = [process.cwd(), dirname(fileURLToPath(import.meta.url))];

// VitePress's CLI binary is located at bin/vitepress.js relative to the package root
const pkgJsonPath = require.resolve('vitepress/package.json', {
paths,
});
const pkgJsonPath = resolve('vitepress/package.json');
const binPath = join(dirname(pkgJsonPath), 'bin', 'vitepress.js');

return {
binPath,
// TODO: provide envs inference API
envs: {
// Provide Node.js runtime information for telemetry/compatibility
JS_RUNTIME_VERSION: process.versions.node,
JS_RUNTIME_NAME: process.release.name,
// Indicate that vite-plus is the package manager
NODE_PACKAGE_MANAGER: 'vite-plus',
...DEFAULT_ENVS,
},
};
}
18 changes: 4 additions & 14 deletions packages/cli/src/fmt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,7 @@
* provides high-performance code formatting capabilities.
*/

import { createRequire } from 'node:module';
import { dirname } from 'node:path';
import { fileURLToPath } from 'node:url';

const require = createRequire(import.meta.url);
import { DEFAULT_ENVS, resolve } from './utils.js';

/**
* Resolves the oxfmt binary path and environment variables.
Expand All @@ -32,19 +28,13 @@ export async function fmt(): Promise<{
envs: Record<string, string>;
}> {
// Resolve the oxfmt binary directly (it's a native executable)
const binPath = require.resolve('oxfmt/bin/oxfmt', {
paths: [process.cwd(), dirname(fileURLToPath(import.meta.url))],
});
const binPath = resolve('oxfmt/bin/oxfmt');

return {
binPath,
// TODO: provide envs inference API
envs: {
// Provide Node.js runtime information for oxfmt's telemetry/compatibility
JS_RUNTIME_VERSION: process.versions.node,
JS_RUNTIME_NAME: process.release.name,
// Indicate that vite-plus is the package manager invoking oxfmt
NODE_PACKAGE_MANAGER: 'vite-plus',
...DEFAULT_ENVS,
},
};
}
}
16 changes: 3 additions & 13 deletions packages/cli/src/lib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,7 @@
* Used for: `vite-plus lib` command
*/

import { createRequire } from 'node:module';
import { dirname } from 'node:path';
import { fileURLToPath } from 'node:url';

const require = createRequire(import.meta.url);
import { DEFAULT_ENVS, resolve } from './utils.js';

/**
* Resolves the Tsdown binary path and environment variables.
Expand All @@ -28,19 +24,13 @@ export async function lib(): Promise<{
envs: Record<string, string>;
}> {
// Resolve the Tsdown CLI module directly
const binPath = require.resolve('tsdown/run', {
paths: [process.cwd(), dirname(fileURLToPath(import.meta.url))],
});
const binPath = resolve('tsdown/run');

return {
binPath,
// TODO: provide envs inference API
envs: {
// Provide Node.js runtime information for oxfmt's telemetry/compatibility
JS_RUNTIME_VERSION: process.versions.node,
JS_RUNTIME_NAME: process.release.name,
// Indicate that vite-plus is the package manager invoking tsdown
NODE_PACKAGE_MANAGER: 'vite-plus',
...DEFAULT_ENVS,
},
};
}
21 changes: 4 additions & 17 deletions packages/cli/src/lint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,7 @@
* provides ESLint-compatible linting with significantly better performance.
*/

import { createRequire } from 'node:module';
import { dirname } from 'node:path';
import { fileURLToPath } from 'node:url';

const require = createRequire(import.meta.url);
import { DEFAULT_ENVS, resolve } from './utils.js';

/**
* Resolves the oxlint binary path and environment variables.
Expand All @@ -31,24 +27,15 @@ export async function lint(): Promise<{
binPath: string;
envs: Record<string, string>;
}> {
const paths = [process.cwd(), dirname(fileURLToPath(import.meta.url))];
// Resolve the oxlint binary directly (it's a native executable)
const binPath = require.resolve('oxlint/bin/oxlint', {
paths,
});
const binPath = resolve('oxlint/bin/oxlint');

return {
binPath,
// TODO: provide envs inference API
envs: {
// Provide Node.js runtime information for oxlint's telemetry/compatibility
JS_RUNTIME_VERSION: process.versions.node,
JS_RUNTIME_NAME: process.release.name,
// Indicate that vite-plus is the package manager invoking oxlint
NODE_PACKAGE_MANAGER: 'vite-plus',
OXLINT_TSGOLINT_PATH: require.resolve('oxlint-tsgolint/bin/tsgolint.js', {
paths,
}),
...DEFAULT_ENVS,
OXLINT_TSGOLINT_PATH: resolve('oxlint-tsgolint/bin/tsgolint.js'),
},
};
}
15 changes: 6 additions & 9 deletions packages/cli/src/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,7 @@
* Used for: `vite-plus test` command
*/

import { createRequire } from 'node:module';
import { dirname } from 'node:path';
import { fileURLToPath } from 'node:url';

const require = createRequire(import.meta.url);
import { DEFAULT_ENVS, resolve } from './utils.js';

/**
* Resolves the Vitest binary path and environment variables.
Expand All @@ -29,17 +25,18 @@ export async function test(): Promise<{
envs: Record<string, string>;
}> {
// Resolve the Vitest CLI module directly
const binPath = require.resolve('vitest/vitest.mjs', {
paths: [process.cwd(), dirname(fileURLToPath(import.meta.url))],
});
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,
},
};
}
17 changes: 17 additions & 0 deletions packages/cli/src/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { createRequire } from 'node:module';

const require = createRequire(import.meta.url);

export function resolve(path: string) {
return require.resolve(path, {
paths: [process.cwd(), import.meta.dirname],
Comment thread
fengmk2 marked this conversation as resolved.
Comment thread
fengmk2 marked this conversation as resolved.
});
}

export const DEFAULT_ENVS = {
// Provide Node.js runtime information for oxfmt's telemetry/compatibility
JS_RUNTIME_VERSION: process.versions.node,
JS_RUNTIME_NAME: process.release.name,
// Indicate that vite-plus is the package manager
NODE_PACKAGE_MANAGER: 'vite-plus',
} as const;
22 changes: 8 additions & 14 deletions packages/cli/src/vite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,8 @@
* Used for: `vite-plus build` and potentially `vite-plus dev` commands
*/

import { createRequire } from 'node:module';
import { dirname, join } from 'node:path';
import { fileURLToPath } from 'node:url';

const require = createRequire(import.meta.url);
import { DEFAULT_ENVS, resolve } from './utils.js';

/**
* Resolves the Vite binary path and environment variables.
Expand All @@ -30,21 +27,15 @@ export async function vite(): Promise<{
binPath: string;
envs: Record<string, string>;
}> {
const resolvePaths = [process.cwd(), dirname(fileURLToPath(import.meta.url))];

let pkgJsonPath: string;
try {
// First try to resolve vite package.json
pkgJsonPath = require.resolve('vite/package.json', {
paths: resolvePaths,
});
pkgJsonPath = resolve('vite/package.json');
} catch {
// Fallback to rolldown-vite package.json (for direct rolldown-vite installations)
pkgJsonPath = require.resolve('rolldown-vite/package.json', {
paths: resolvePaths,
});
pkgJsonPath = resolve('rolldown-vite/package.json');
}

// Vite's CLI binary is located at bin/vite.js relative to the package root
const binPath = join(dirname(pkgJsonPath), 'bin', 'vite.js');

Expand All @@ -53,8 +44,11 @@ export async function vite(): Promise<{
// 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,
},
};
}
15 changes: 9 additions & 6 deletions packages/tools/src/__tests__/__snapshots__/utils.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,13 @@ Done in <variable>ms using pnpm v<semver>"
`;

exports[`replaceUnstableOutput > replace unstable semver version 1`] = `
"v1.0.0
v1.0.0-beta.1
v1.0.0-beta.1+build.1
1.0.0
1.0.0-beta.1
1.0.0-beta.1+build.1"
"foo v<semver>
v<semver>
v<semver>
<semver>
<semver>
<semver>
tsdown/<semver>
vitest/<semver>
foo/v<semver>"
`;
15 changes: 9 additions & 6 deletions packages/tools/src/__tests__/utils.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,15 @@ import { replaceUnstableOutput } from '../utils.ts';
describe('replaceUnstableOutput', () => {
test('replace unstable semver version', () => {
const output = `
v1.0.0
v1.0.0-beta.1
v1.0.0-beta.1+build.1
1.0.0
1.0.0-beta.1
1.0.0-beta.1+build.1
foo v1.0.0
v1.0.0-beta.1
v1.0.0-beta.1+build.1
1.0.0
1.0.0-beta.1
1.0.0-beta.1+build.1
tsdown/0.15.1
vitest/3.2.4
foo/v100.1.1000
`;
expect(replaceUnstableOutput(output.trim())).toMatchSnapshot();
});
Expand Down
4 changes: 3 additions & 1 deletion packages/tools/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ export function replaceUnstableOutput(output: string, cwd?: string) {
}
return output
// semver version
.replaceAll(/ (v)?\d+\.\d+\.\d+(?:-.*)?/g, ' $1<semver>')
// e.g.: ` v1.0.0` -> ` <semver>`
// e.g.: `/1.0.0` -> `/<semver>`
.replaceAll(/([/\s]v?)\d+\.\d+\.\d+(?:-.*)?/g, '$1<semver>')
// date
.replaceAll(/\d{2}:\d{2}:\d{2}/g, '<date>')
// oxlint
Expand Down
Loading