From b149eb34670644d42a0a7eaa5e2fc9b30191d04e Mon Sep 17 00:00:00 2001 From: MK Date: Sat, 14 Mar 2026 22:08:16 +0800 Subject: [PATCH 1/2] fix(cli): use pathToFileURL for dynamic imports in oxfmt/oxlint bin wrappers On Windows, Node.js ESM loader rejects absolute paths like `c:\Users\...` because it interprets the drive letter as a URL scheme. Convert resolved paths to file:// URLs via pathToFileURL() which works on all platforms. Also enable win32 snap tests for both wrappers since the non-LSP error path doesn't involve dynamic imports. Closes https://github.com/oxc-project/oxc-vscode/issues/149 --- packages/cli/bin/oxfmt | 3 ++- packages/cli/bin/oxlint | 3 ++- packages/cli/snap-tests/bin-oxfmt-wrapper/steps.json | 1 - packages/cli/snap-tests/bin-oxlint-wrapper/steps.json | 1 - 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/cli/bin/oxfmt b/packages/cli/bin/oxfmt index 69d003d0b1..efae3059a5 100755 --- a/packages/cli/bin/oxfmt +++ b/packages/cli/bin/oxfmt @@ -11,8 +11,9 @@ if (!process.argv.includes('--lsp')) { } import { createRequire } from 'node:module'; +import { pathToFileURL } from 'node:url'; const require = createRequire(import.meta.url); const oxfmtBin = require.resolve('oxfmt/bin/oxfmt'); -await import(oxfmtBin); +await import(pathToFileURL(oxfmtBin).href); diff --git a/packages/cli/bin/oxlint b/packages/cli/bin/oxlint index a02c9197bf..2385020e74 100755 --- a/packages/cli/bin/oxlint +++ b/packages/cli/bin/oxlint @@ -12,9 +12,10 @@ if (!process.argv.includes('--lsp')) { import { createRequire } from 'node:module'; import { dirname, join } from 'node:path'; +import { pathToFileURL } from 'node:url'; const require = createRequire(import.meta.url); const oxlintMainPath = require.resolve('oxlint'); const oxlintBin = join(dirname(dirname(oxlintMainPath)), 'bin', 'oxlint'); -await import(oxlintBin); +await import(pathToFileURL(oxlintBin).href); diff --git a/packages/cli/snap-tests/bin-oxfmt-wrapper/steps.json b/packages/cli/snap-tests/bin-oxfmt-wrapper/steps.json index 54aa554888..b98b49e416 100644 --- a/packages/cli/snap-tests/bin-oxfmt-wrapper/steps.json +++ b/packages/cli/snap-tests/bin-oxfmt-wrapper/steps.json @@ -1,4 +1,3 @@ { - "ignoredPlatforms": ["win32"], "commands": ["oxfmt # should reject non-LSP usage", "oxfmt --help # should reject non-LSP usage"] } diff --git a/packages/cli/snap-tests/bin-oxlint-wrapper/steps.json b/packages/cli/snap-tests/bin-oxlint-wrapper/steps.json index 76abb5af56..c9fb02f611 100644 --- a/packages/cli/snap-tests/bin-oxlint-wrapper/steps.json +++ b/packages/cli/snap-tests/bin-oxlint-wrapper/steps.json @@ -1,5 +1,4 @@ { - "ignoredPlatforms": ["win32"], "commands": [ "oxlint # should reject non-LSP usage", "oxlint --help # should reject non-LSP usage" From 0b713b819776e013acaf75722ee78f20a631a397 Mon Sep 17 00:00:00 2001 From: MK Date: Sat, 14 Mar 2026 22:56:04 +0800 Subject: [PATCH 2/2] test(cli): enable win32 snap tests for oxfmt/oxlint bin wrappers Invoke bin scripts via `node` with relative path instead of relying on PATH resolution, which fails on Windows because extensionless files are invisible to PATHEXT-based command lookup. Add `--lsp --help` test cases to exercise the dynamic import code path (the pathToFileURL fix) in both wrappers. --- .../cli/snap-tests/bin-oxfmt-wrapper/snap.txt | 44 ++++++- .../snap-tests/bin-oxfmt-wrapper/steps.json | 6 +- .../snap-tests/bin-oxlint-wrapper/snap.txt | 107 +++++++++++++++++- .../snap-tests/bin-oxlint-wrapper/steps.json | 5 +- 4 files changed, 155 insertions(+), 7 deletions(-) diff --git a/packages/cli/snap-tests/bin-oxfmt-wrapper/snap.txt b/packages/cli/snap-tests/bin-oxfmt-wrapper/snap.txt index dd16c008bb..7bab243e01 100644 --- a/packages/cli/snap-tests/bin-oxfmt-wrapper/snap.txt +++ b/packages/cli/snap-tests/bin-oxfmt-wrapper/snap.txt @@ -1,7 +1,47 @@ -[1]> oxfmt # should reject non-LSP usage +[1]> node ../node_modules/vite-plus/bin/oxfmt # should reject non-LSP usage This oxfmt wrapper is for IDE extension use only (--lsp mode). To format your code, run: vp fmt -[1]> oxfmt --help # should reject non-LSP usage +[1]> node ../node_modules/vite-plus/bin/oxfmt --help # should reject non-LSP usage This oxfmt wrapper is for IDE extension use only (--lsp mode). To format your code, run: vp fmt + +> node ../node_modules/vite-plus/bin/oxfmt --lsp --help # should exercise import path +Usage: [-c=PATH] [PATH]... + +Mode Options: + --init Initialize `.oxfmtrc.json` with default values + --migrate=SOURCE Migrate configuration to `.oxfmtrc.json` from specified source + Available sources: prettier, biome + --lsp Start language server protocol (LSP) server + --stdin-filepath=PATH Specify the file name to use to infer which parser to use + +Output Options: + --write Format and write files in place (default) + --check Check if files are formatted, also show statistics + --list-different List files that would be changed + +Config Options + -c, --config=PATH Path to the configuration file (.json, .jsonc, .ts, .mts, .cts, .js, + .mjs, .cjs) + +Ignore Options + --ignore-path=PATH Path to ignore file(s). Can be specified multiple times. If not + specified, .gitignore and .prettierignore in the current directory are + used. + --with-node-modules Format code in node_modules directory (skipped by default) + +Runtime Options + --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, path or list of paths. Glob patterns are also supported. + (Be sure to quote them, otherwise your shell may expand them before + passing.) Exclude patterns with `!` prefix like `'!**/fixtures/*.js'` + are also supported. If not provided, current working directory is used. + +Available options: + -h, --help Prints help information + -V, --version Prints version information + diff --git a/packages/cli/snap-tests/bin-oxfmt-wrapper/steps.json b/packages/cli/snap-tests/bin-oxfmt-wrapper/steps.json index b98b49e416..90fdd16b3b 100644 --- a/packages/cli/snap-tests/bin-oxfmt-wrapper/steps.json +++ b/packages/cli/snap-tests/bin-oxfmt-wrapper/steps.json @@ -1,3 +1,7 @@ { - "commands": ["oxfmt # should reject non-LSP usage", "oxfmt --help # should reject non-LSP usage"] + "commands": [ + "node ../node_modules/vite-plus/bin/oxfmt # should reject non-LSP usage", + "node ../node_modules/vite-plus/bin/oxfmt --help # should reject non-LSP usage", + "node ../node_modules/vite-plus/bin/oxfmt --lsp --help # should exercise import path" + ] } diff --git a/packages/cli/snap-tests/bin-oxlint-wrapper/snap.txt b/packages/cli/snap-tests/bin-oxlint-wrapper/snap.txt index 38b475f093..7def3787eb 100644 --- a/packages/cli/snap-tests/bin-oxlint-wrapper/snap.txt +++ b/packages/cli/snap-tests/bin-oxlint-wrapper/snap.txt @@ -1,7 +1,110 @@ -[1]> oxlint # should reject non-LSP usage +[1]> node ../node_modules/vite-plus/bin/oxlint # should reject non-LSP usage This oxlint wrapper is for IDE extension use only (--lsp mode). To lint your code, run: vp lint -[1]> oxlint --help # should reject non-LSP usage +[1]> node ../node_modules/vite-plus/bin/oxlint --help # should reject non-LSP usage This oxlint wrapper is for IDE extension use only (--lsp mode). To lint your code, run: vp lint + +> node ../node_modules/vite-plus/bin/oxlint --lsp --help # should exercise import path +Usage: [-c=<./.oxlintrc.json>] [PATH]... + +Basic Configuration + -c, --config=<./.oxlintrc.json> Oxlint configuration file + * `.json` and `.jsonc` config files are supported in all runtimes + * JavaScript/TypeScript config files are experimental and require + running via Node.js + * you can use comments in configuration files. + * tries to be compatible with ESLint v8's format + --tsconfig=<./tsconfig.json> TypeScript `tsconfig.json` path for reading path alias and + project references for import plugin. If not provided, will look for + `tsconfig.json` in the current working directory. + --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 + * `perf` - Code that could be written in a more performant way + * `style` - Code that should be written in a more idiomatic way + * `restriction` - Lints which prevent the use of language and library features + * `nursery` - New lints that are still under development + * `all` - All 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/Disable 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 import plugin and detect ESM problems. It should be used with + the `--tsconfig` flag if your project has a tsconfig with a name other + than `tsconfig.json`. + --react-plugin Enable react plugin, which is turned off by default + --jsdoc-plugin Enable 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 + --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 Disable excluding 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 `// oxlint-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 + --lsp Start the language server + --disable-nested-config Disable the automatic loading of nested configuration files + --type-aware Enable rules that require type information + --type-check Enable experimental type checking (includes TypeScript compiler + diagnostics) + -h, --help Prints help information + -V, --version Prints version information + diff --git a/packages/cli/snap-tests/bin-oxlint-wrapper/steps.json b/packages/cli/snap-tests/bin-oxlint-wrapper/steps.json index c9fb02f611..eb4d1afd61 100644 --- a/packages/cli/snap-tests/bin-oxlint-wrapper/steps.json +++ b/packages/cli/snap-tests/bin-oxlint-wrapper/steps.json @@ -1,6 +1,7 @@ { "commands": [ - "oxlint # should reject non-LSP usage", - "oxlint --help # should reject non-LSP usage" + "node ../node_modules/vite-plus/bin/oxlint # should reject non-LSP usage", + "node ../node_modules/vite-plus/bin/oxlint --help # should reject non-LSP usage", + "node ../node_modules/vite-plus/bin/oxlint --lsp --help # should exercise import path" ] }