diff --git a/packages/cli/snap-tests/command-helper/package.json b/packages/cli/snap-tests/command-helper/package.json new file mode 100644 index 0000000000..2c63c08510 --- /dev/null +++ b/packages/cli/snap-tests/command-helper/package.json @@ -0,0 +1,2 @@ +{ +} diff --git a/packages/cli/snap-tests/command-helper/snap.txt b/packages/cli/snap-tests/command-helper/snap.txt new file mode 100644 index 0000000000..70d1bdf9dc --- /dev/null +++ b/packages/cli/snap-tests/command-helper/snap.txt @@ -0,0 +1,291 @@ +> vite lib -h # lib help message +tsdown/ + +Usage: + $ tsdown [...files] + +Commands: + [...files] Bundle files + migrate Migrate from tsup to tsdown + +For more info, run any command with the `--help` flag: + $ tsdown --help + $ tsdown migrate --help + +Options: + -c, --config Use a custom config file + --config-loader Config loader to use: auto, native, unconfig (default: auto) + --no-config Disable config file (default: true) + -f, --format Bundle format: esm, cjs, iife, umd (default: esm) + --clean Clean output directory, --no-clean to disable + --external Mark dependencies as external + --minify Minify output + --debug [feat] Show debug logs + --target Bundle target, e.g "es2015", "esnext" + -l, --logLevel Set log level: info, warn, error, silent + --fail-on-warn Fail on warnings (default: true) + -d, --out-dir Output directory (default: dist) + --treeshake Tree-shake bundle (default: true) + --sourcemap Generate source map (default: false) + --shims Enable cjs and esm shims (default: false) + --platform Target platform (default: node) + --dts Generate dts files + --publint Enable publint (default: false) + --attw Enable Are the types wrong integration (default: false) + --unused Enable unused dependencies check (default: false) + -w, --watch [path] Watch mode + --ignore-watch Ignore custom paths in watch mode + --from-vite [vitest] Reuse config from Vite or Vitest + --report Size report (default: true) + --env.* Define compile-time env variables + --on-success Command to run on success + --copy Copy files to output dir + --public-dir Alias for --copy, deprecated + --tsconfig Set tsconfig path + --unbundle Unbundle mode + -W, --workspace [dir] Enable workspace mode + -F, --filter Filter workspace packages, e.g. /regex/ or substring + --exports Generate export-related metadata for package.json (experimental) + -h, --help Display this message + -v, --version Display version number + + +> vite fmt -h # fmt help message +Usage: [--check | --list-different] [PATH]... + +Output Options + --check Check mode - check if files are formatted + --list-different List mode - list files that would be changed + +Miscellaneous + --no-error-on-unmatched-pattern Do not exit with error when pattern is unmatched + --threads=INT Number of threads to use. Set to 1 for using only 1 CPU core + +Available positional items: + PATH Single file, single path or list of paths. If not provided, current + working directory is used. + +Available options: + -h, --help Prints help information + -V, --version Prints version information + + + +> vite lint -h # lint help message +Usage: [-c=<./.oxlintrc.json>] [PATH]... + +Basic Configuration + -c, --config=<./.oxlintrc.json> Oxlint configuration file (experimental) + * only `.json` extension is supported + * you can use comments in configuration files. + * tries to be compatible with the ESLint v8's format + --tsconfig=<./tsconfig.json> TypeScript `tsconfig.json` path for reading path alias and + project references for import plugin + --init Initialize oxlint configuration with default values + +Allowing / Denying Multiple Lints + Accumulate rules and categories from left to right on the command-line. + For example `-D correctness -A no-debugger` or `-A all -D no-debugger`. + The categories are: + * `correctness` - code that is outright wrong or useless (default). + * `suspicious` - code that is most likely wrong or useless. + * `pedantic` - lints which are rather strict or have occasional false positives. + * `style` - code that should be written in a more idiomatic way. + * `nursery` - new lints that are still under development. + * `restriction` - lints which prevent the use of language and library features. + * `all` - all the categories listed above except nursery. Does not enable plugins + automatically. + -A, --allow=NAME Allow the rule or category (suppress the lint) + -W, --warn=NAME Deny the rule or category (emit a warning) + -D, --deny=NAME Deny the rule or category (emit an error) + +Enable Plugins + --disable-unicorn-plugin Disable unicorn plugin, which is turned on by default + --disable-oxc-plugin Disable oxc unique rules, which is turned on by default + --disable-typescript-plugin Disable TypeScript plugin, which is turned on by default + --import-plugin Enable the experimental import plugin and detect ESM problems. It is + recommended to use along side with the `--tsconfig` option. + --react-plugin Enable react plugin, which is turned off by default + --jsdoc-plugin Enable the experimental jsdoc plugin and detect JSDoc problems + --jest-plugin Enable the Jest plugin and detect test problems + --vitest-plugin Enable the Vitest plugin and detect test problems + --jsx-a11y-plugin Enable the JSX-a11y plugin and detect accessibility problems + --nextjs-plugin Enable the Next.js plugin and detect Next.js problems + --react-perf-plugin Enable the React performance plugin and detect rendering performance + problems + --promise-plugin Enable the promise plugin and detect promise usage problems + --node-plugin Enable the node plugin and detect node usage problems + --regex-plugin Enable the regex plugin and detect regex usage problems + --vue-plugin Enable the vue plugin and detect vue usage problems + +Fix Problems + --fix Fix as many issues as possible. Only unfixed issues are reported in + the output + --fix-suggestions Apply auto-fixable suggestions. May change program behavior. + --fix-dangerously Apply dangerous fixes and suggestions. + +Ignore Files + --ignore-path=PATH Specify the file to use as your .eslintignore + --ignore-pattern=PAT Specify patterns of files to ignore (in addition to those in + .eslintignore) + --no-ignore Disables excluding of files from .eslintignore files, --ignore-path + flags and --ignore-pattern flags + +Handle Warnings + --quiet Disable reporting on warnings, only errors are reported + --deny-warnings Ensure warnings produce a non-zero exit code + --max-warnings=INT Specify a warning threshold, which can be used to force exit with an + error status if there are too many warning-level rule violations in + your project + +Output + -f, --format=ARG Use a specific output format. Possible values: `checkstyle`, + `default`, `github`, `gitlab`, `json`, `junit`, `stylish`, `unix` + +Miscellaneous + --silent Do not display any diagnostics + --threads=INT Number of threads to use. Set to 1 for using only 1 CPU core + --print-config This option outputs the configuration to be used. When present, no + linting is performed and only config-related options are valid. + +Inline Configuration Comments + --report-unused-disable-directives Report directive comments like `// eslint-disable-line` + when no errors would have been reported on that line anyway. + --report-unused-disable-directives-severity=SEVERITY Same as + `--report-unused-disable-directives`, but allows you to specify the + severity level of the reported errors. Only one of these two options + can be used at a time. + +Available positional items: + PATH Single file, single path or list of paths + +Available options: + --rules list all the rules that are currently registered + --disable-nested-config Disables the automatic loading of nested configuration files. + --type-aware Enables rules that require type information. + -h, --help Prints help information + -V, --version Prints version information + + + +> vite build -h # build help message +vite/ + +Usage: + $ vite build [root] + +Options: + --target [string] transpile target (default: 'baseline-widely-available') + --outDir [string] output directory (default: dist) + --assetsDir [string] directory under outDir to place assets in (default: assets) + --assetsInlineLimit [number] static asset base64 inline threshold in bytes (default: 4096) + --ssr [entry] [string] build specified entry for server-side rendering + --sourcemap [output] [boolean | "inline" | "hidden"] output source maps for build (default: false) + --minify [minifier] [boolean | "terser" | "esbuild"] enable/disable minification, or specify minifier to use (default: esbuild) + --manifest [name] [boolean | string] emit build manifest json + --ssrManifest [name] [boolean | string] emit ssr manifest json + --emptyOutDir [boolean] force empty outDir when it's outside of root + -w, --watch [boolean] rebuilds when modules have changed on disk + --app [boolean] same as `builder: {}` + -c, --config [string] use specified config file + --base [string] public base path (default: /) + -l, --logLevel [string] info | warn | error | silent + --clearScreen [boolean] allow/disable clear screen when logging + --configLoader [string] use 'bundle' to bundle the config with esbuild, or 'runner' (experimental) to process it on the fly, or 'native' (experimental) to load using the native runtime (default: bundle) + -d, --debug [feat] [string | boolean] show debug logs + -f, --filter [string] filter debug logs + -m, --mode [string] set env mode + -h, --help Display this message + + +> vite test -h # test help message +vitest/ + WARN: no options were found for your subcommands so we printed the whole output + +Usage: + $ vitest [...filters] + +Commands: + run [...filters] + related [...filters] + watch [...filters] + dev [...filters] + bench [...filters] + init + list [...filters] + [...filters] + +For more info, run any command with the `--help` flag: + $ vitest run --help + $ vitest related --help + $ vitest watch --help + $ vitest dev --help + $ vitest bench --help + $ vitest init --help + $ vitest list --help + $ vitest --help + $ vitest --help --expand-help + +Options: + -v, --version Display version number + -r, --root Root path + -c, --config Path to config file + -u, --update Update snapshot + -w, --watch Enable watch mode + -t, --testNamePattern Run tests with full names matching the specified regexp pattern + --dir Base directory to scan for the test files + --ui Enable UI + --open Open UI automatically (default: !process.env.CI) + --api [port] Specify server port. Note if the port is already being used, Vite will automatically try the next available port so this may not be the actual port the server ends up listening on. If true will be set to 51204. Use '--help --api' for more info. + --silent [value] Silent console output from tests. Use 'passed-only' to see logs from failing tests only. + --hideSkippedTests Hide logs for skipped tests + --reporter Specify reporters (default, basic, blob, verbose, dot, json, tap, tap-flat, junit, hanging-process, github-actions) + --outputFile Write test results to a file when supporter reporter is also specified, use cac's dot notation for individual outputs of multiple reporters (example: --outputFile.tap=./tap.txt) + --coverage Enable coverage report. Use '--help --coverage' for more info. + --mode Override Vite mode (default: test or benchmark) + --workspace [deprecated] Path to a workspace configuration file + --isolate Run every test file in isolation. To disable isolation, use --no-isolate (default: true) + --globals Inject apis globally + --dom Mock browser API with happy-dom + --browser Run tests in the browser. Equivalent to --browser.enabled (default: false). Use '--help --browser' for more info. + --pool Specify pool, if not running in the browser (default: forks) + --poolOptions Specify pool options. Use '--help --poolOptions' for more info. + --fileParallelism Should all test files run in parallel. Use --no-file-parallelism to disable (default: true) + --maxWorkers Maximum number or percentage of workers to run tests in + --minWorkers Minimum number or percentage of workers to run tests in + --environment Specify runner environment, if not running in the browser (default: node) + --passWithNoTests Pass when no tests are found + --logHeapUsage Show the size of heap for each test when running in node + --allowOnly Allow tests and suites that are marked as only (default: !process.env.CI) + --dangerouslyIgnoreUnhandledErrors Ignore any unhandled errors that occur + --shard Test suite shard to execute in a format of / + --changed [since] Run tests that are affected by the changed files (default: false) + --sequence Options for how tests should be sorted. Use '--help --sequence' for more info. + --inspect [[host:]port] Enable Node.js inspector (default: .1:9229) + --inspectBrk [[host:]port] Enable Node.js inspector and break before the test starts + --testTimeout Default timeout of a test in milliseconds (default: 5000). Use 0 to disable timeout completely. + --hookTimeout Default hook timeout in milliseconds (default: 10000). Use 0 to disable timeout completely. + --bail Stop test execution when given number of tests have failed (default: 0) + --retry Retry the test specific number of times if it fails (default: 0) + --diff DiffOptions object or a path to a module which exports DiffOptions object. Use '--help --diff' for more info. + --exclude Additional file globs to be excluded from test + --expandSnapshotDiff Show full diff when snapshot fails + --disableConsoleIntercept Disable automatic interception of console logging (default: false) + --typecheck Enable typechecking alongside tests (default: false). Use '--help --typecheck' for more info. + --project The name of the project to run if you are using Vitest workspace feature. This can be repeated for multiple projects: --project=1 --project=2. You can also filter projects using wildcards like --project=packages*, and exclude projects with --project=!pattern. + --slowTestThreshold Threshold in milliseconds for a test or suite to be considered slow (default: 300) + --teardownTimeout Default timeout of a teardown function in milliseconds (default: 10000) + --cache Enable cache. Use '--help --cache' for more info. + --maxConcurrency Maximum number of concurrent tests in a suite (default: 5) + --expect Configuration options for expect() matches. Use '--help --expect' for more info. + --printConsoleTrace Always print console stack traces + --includeTaskLocation Collect test and suite locations in the location property + --attachmentsDir The directory where attachments from context.annotate are stored in (default: .vitest-attachments) + --run Disable watch mode + --no-color Removes colors from the console output (default: true) + --clearScreen Clear terminal screen when re-running tests during watch mode (default: true) + --configLoader Use bundle to bundle the config with esbuild or runner (experimental) to process it on the fly. This is only available in vite version and above. (default: bundle) + --standalone Start Vitest without running tests. File filters will be ignored, tests will be running only on change (default: false) + --mergeReports [path] Path to a blob reports directory. If this options is used, Vitest won't run any tests, it will only report previously recorded tests + -h, --help Display this message + diff --git a/packages/cli/snap-tests/command-helper/steps.json b/packages/cli/snap-tests/command-helper/steps.json new file mode 100644 index 0000000000..e632de7184 --- /dev/null +++ b/packages/cli/snap-tests/command-helper/steps.json @@ -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" + ] +} diff --git a/packages/cli/snap-tests/command-lib/snap.txt b/packages/cli/snap-tests/command-lib/snap.txt index 515e1b3b57..f166452071 100644 --- a/packages/cli/snap-tests/command-lib/snap.txt +++ b/packages/cli/snap-tests/command-lib/snap.txt @@ -1,5 +1,5 @@ > vite lib -h # should print the help message -tsdown/0.15.1 +tsdown/ Usage: $ tsdown [...files] diff --git a/packages/cli/src/doc.ts b/packages/cli/src/doc.ts index bb87b25ddf..ae20b86b12 100644 --- a/packages/cli/src/doc.ts +++ b/packages/cli/src/doc.ts @@ -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. @@ -29,23 +26,15 @@ export async function doc(): Promise<{ binPath: string; envs: Record; }> { - 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, }, }; } diff --git a/packages/cli/src/fmt.ts b/packages/cli/src/fmt.ts index c7eb8633db..011bd4ee4e 100644 --- a/packages/cli/src/fmt.ts +++ b/packages/cli/src/fmt.ts @@ -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. @@ -32,19 +28,13 @@ export async function fmt(): Promise<{ envs: Record; }> { // 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, }, }; -} \ No newline at end of file +} diff --git a/packages/cli/src/lib.ts b/packages/cli/src/lib.ts index 637c75aad4..a02a03407b 100644 --- a/packages/cli/src/lib.ts +++ b/packages/cli/src/lib.ts @@ -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. @@ -28,19 +24,13 @@ export async function lib(): Promise<{ envs: Record; }> { // 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, }, }; } diff --git a/packages/cli/src/lint.ts b/packages/cli/src/lint.ts index 0746c01de1..67a6e99661 100644 --- a/packages/cli/src/lint.ts +++ b/packages/cli/src/lint.ts @@ -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. @@ -31,24 +27,15 @@ export async function lint(): Promise<{ binPath: string; envs: Record; }> { - 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'), }, }; } diff --git a/packages/cli/src/test.ts b/packages/cli/src/test.ts index a10a6da6c0..4150679444 100644 --- a/packages/cli/src/test.ts +++ b/packages/cli/src/test.ts @@ -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. @@ -29,17 +25,18 @@ export async function test(): Promise<{ envs: Record; }> { // 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, + }, }; } diff --git a/packages/cli/src/utils.ts b/packages/cli/src/utils.ts new file mode 100644 index 0000000000..0a06e690fc --- /dev/null +++ b/packages/cli/src/utils.ts @@ -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], + }); +} + +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; diff --git a/packages/cli/src/vite.ts b/packages/cli/src/vite.ts index 5a7375892c..9cbe09f1e9 100644 --- a/packages/cli/src/vite.ts +++ b/packages/cli/src/vite.ts @@ -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. @@ -30,21 +27,15 @@ export async function vite(): Promise<{ binPath: string; envs: Record; }> { - 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'); @@ -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, + }, }; } diff --git a/packages/tools/src/__tests__/__snapshots__/utils.spec.ts.snap b/packages/tools/src/__tests__/__snapshots__/utils.spec.ts.snap index 3befa37222..e638d6211f 100644 --- a/packages/tools/src/__tests__/__snapshots__/utils.spec.ts.snap +++ b/packages/tools/src/__tests__/__snapshots__/utils.spec.ts.snap @@ -43,10 +43,13 @@ Done in ms using pnpm v" `; 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 + v + v + + + +tsdown/ +vitest/ +foo/v" `; diff --git a/packages/tools/src/__tests__/utils.spec.ts b/packages/tools/src/__tests__/utils.spec.ts index 9c54fdd6dd..1a83e98c9b 100644 --- a/packages/tools/src/__tests__/utils.spec.ts +++ b/packages/tools/src/__tests__/utils.spec.ts @@ -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(); }); diff --git a/packages/tools/src/utils.ts b/packages/tools/src/utils.ts index 2f5ef54d53..533755c9d4 100644 --- a/packages/tools/src/utils.ts +++ b/packages/tools/src/utils.ts @@ -4,7 +4,9 @@ export function replaceUnstableOutput(output: string, cwd?: string) { } return output // semver version - .replaceAll(/ (v)?\d+\.\d+\.\d+(?:-.*)?/g, ' $1') + // e.g.: ` v1.0.0` -> ` ` + // e.g.: `/1.0.0` -> `/` + .replaceAll(/([/\s]v?)\d+\.\d+\.\d+(?:-.*)?/g, '$1') // date .replaceAll(/\d{2}:\d{2}:\d{2}/g, '') // oxlint