Skip to content

Commit d8e268d

Browse files
authored
fix(cli): use pathToFileURL for dynamic imports in oxfmt/oxlint bin wrappers (#867)
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 #865
1 parent b50a329 commit d8e268d

6 files changed

Lines changed: 159 additions & 11 deletions

File tree

packages/cli/bin/oxfmt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@ if (!process.argv.includes('--lsp')) {
1111
}
1212

1313
import { createRequire } from 'node:module';
14+
import { pathToFileURL } from 'node:url';
1415

1516
const require = createRequire(import.meta.url);
1617
const oxfmtBin = require.resolve('oxfmt/bin/oxfmt');
1718

18-
await import(oxfmtBin);
19+
await import(pathToFileURL(oxfmtBin).href);

packages/cli/bin/oxlint

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,10 @@ if (!process.argv.includes('--lsp')) {
1212

1313
import { createRequire } from 'node:module';
1414
import { dirname, join } from 'node:path';
15+
import { pathToFileURL } from 'node:url';
1516

1617
const require = createRequire(import.meta.url);
1718
const oxlintMainPath = require.resolve('oxlint');
1819
const oxlintBin = join(dirname(dirname(oxlintMainPath)), 'bin', 'oxlint');
1920

20-
await import(oxlintBin);
21+
await import(pathToFileURL(oxlintBin).href);
Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,47 @@
1-
[1]> oxfmt # should reject non-LSP usage
1+
[1]> node ../node_modules/vite-plus/bin/oxfmt # should reject non-LSP usage
22
This oxfmt wrapper is for IDE extension use only (--lsp mode).
33
To format your code, run: vp fmt
44

5-
[1]> oxfmt --help # should reject non-LSP usage
5+
[1]> node ../node_modules/vite-plus/bin/oxfmt --help # should reject non-LSP usage
66
This oxfmt wrapper is for IDE extension use only (--lsp mode).
77
To format your code, run: vp fmt
8+
9+
> node ../node_modules/vite-plus/bin/oxfmt --lsp --help # should exercise import path
10+
Usage: [-c=PATH] [PATH]...
11+
12+
Mode Options:
13+
--init Initialize `.oxfmtrc.json` with default values
14+
--migrate=SOURCE Migrate configuration to `.oxfmtrc.json` from specified source
15+
Available sources: prettier, biome
16+
--lsp Start language server protocol (LSP) server
17+
--stdin-filepath=PATH Specify the file name to use to infer which parser to use
18+
19+
Output Options:
20+
--write Format and write files in place (default)
21+
--check Check if files are formatted, also show statistics
22+
--list-different List files that would be changed
23+
24+
Config Options
25+
-c, --config=PATH Path to the configuration file (.json, .jsonc, .ts, .mts, .cts, .js,
26+
.mjs, .cjs)
27+
28+
Ignore Options
29+
--ignore-path=PATH Path to ignore file(s). Can be specified multiple times. If not
30+
specified, .gitignore and .prettierignore in the current directory are
31+
used.
32+
--with-node-modules Format code in node_modules directory (skipped by default)
33+
34+
Runtime Options
35+
--no-error-on-unmatched-pattern Do not exit with error when pattern is unmatched
36+
--threads=INT Number of threads to use. Set to 1 for using only 1 CPU core.
37+
38+
Available positional items:
39+
PATH Single file, path or list of paths. Glob patterns are also supported.
40+
(Be sure to quote them, otherwise your shell may expand them before
41+
passing.) Exclude patterns with `!` prefix like `'!**/fixtures/*.js'`
42+
are also supported. If not provided, current working directory is used.
43+
44+
Available options:
45+
-h, --help Prints help information
46+
-V, --version Prints version information
47+
Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
{
2-
"ignoredPlatforms": ["win32"],
3-
"commands": ["oxfmt # should reject non-LSP usage", "oxfmt --help # should reject non-LSP usage"]
2+
"commands": [
3+
"node ../node_modules/vite-plus/bin/oxfmt # should reject non-LSP usage",
4+
"node ../node_modules/vite-plus/bin/oxfmt --help # should reject non-LSP usage",
5+
"node ../node_modules/vite-plus/bin/oxfmt --lsp --help # should exercise import path"
6+
]
47
}
Lines changed: 105 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,110 @@
1-
[1]> oxlint # should reject non-LSP usage
1+
[1]> node ../node_modules/vite-plus/bin/oxlint # should reject non-LSP usage
22
This oxlint wrapper is for IDE extension use only (--lsp mode).
33
To lint your code, run: vp lint
44

5-
[1]> oxlint --help # should reject non-LSP usage
5+
[1]> node ../node_modules/vite-plus/bin/oxlint --help # should reject non-LSP usage
66
This oxlint wrapper is for IDE extension use only (--lsp mode).
77
To lint your code, run: vp lint
8+
9+
> node ../node_modules/vite-plus/bin/oxlint --lsp --help # should exercise import path
10+
Usage: [-c=<./.oxlintrc.json>] [PATH]...
11+
12+
Basic Configuration
13+
-c, --config=<./.oxlintrc.json> Oxlint configuration file
14+
* `.json` and `.jsonc` config files are supported in all runtimes
15+
* JavaScript/TypeScript config files are experimental and require
16+
running via Node.js
17+
* you can use comments in configuration files.
18+
* tries to be compatible with ESLint v8's format
19+
--tsconfig=<./tsconfig.json> TypeScript `tsconfig.json` path for reading path alias and
20+
project references for import plugin. If not provided, will look for
21+
`tsconfig.json` in the current working directory.
22+
--init Initialize oxlint configuration with default values
23+
24+
Allowing / Denying Multiple Lints
25+
Accumulate rules and categories from left to right on the command-line.
26+
For example `-D correctness -A no-debugger` or `-A all -D no-debugger`.
27+
The categories are:
28+
* `correctness` - Code that is outright wrong or useless (default)
29+
* `suspicious` - Code that is most likely wrong or useless
30+
* `pedantic` - Lints which are rather strict or have occasional false positives
31+
* `perf` - Code that could be written in a more performant way
32+
* `style` - Code that should be written in a more idiomatic way
33+
* `restriction` - Lints which prevent the use of language and library features
34+
* `nursery` - New lints that are still under development
35+
* `all` - All categories listed above except `nursery`. Does not enable plugins
36+
automatically.
37+
-A, --allow=NAME Allow the rule or category (suppress the lint)
38+
-W, --warn=NAME Deny the rule or category (emit a warning)
39+
-D, --deny=NAME Deny the rule or category (emit an error)
40+
41+
Enable/Disable Plugins
42+
--disable-unicorn-plugin Disable unicorn plugin, which is turned on by default
43+
--disable-oxc-plugin Disable oxc unique rules, which is turned on by default
44+
--disable-typescript-plugin Disable TypeScript plugin, which is turned on by default
45+
--import-plugin Enable import plugin and detect ESM problems. It should be used with
46+
the `--tsconfig` flag if your project has a tsconfig with a name other
47+
than `tsconfig.json`.
48+
--react-plugin Enable react plugin, which is turned off by default
49+
--jsdoc-plugin Enable jsdoc plugin and detect JSDoc problems
50+
--jest-plugin Enable the Jest plugin and detect test problems
51+
--vitest-plugin Enable the Vitest plugin and detect test problems
52+
--jsx-a11y-plugin Enable the JSX-a11y plugin and detect accessibility problems
53+
--nextjs-plugin Enable the Next.js plugin and detect Next.js problems
54+
--react-perf-plugin Enable the React performance plugin and detect rendering performance
55+
problems
56+
--promise-plugin Enable the promise plugin and detect promise usage problems
57+
--node-plugin Enable the node plugin and detect node usage problems
58+
--vue-plugin Enable the vue plugin and detect vue usage problems
59+
60+
Fix Problems
61+
--fix Fix as many issues as possible. Only unfixed issues are reported in
62+
the output.
63+
--fix-suggestions Apply auto-fixable suggestions. May change program behavior.
64+
--fix-dangerously Apply dangerous fixes and suggestions
65+
66+
Ignore Files
67+
--ignore-path=PATH Specify the file to use as your `.eslintignore`
68+
--ignore-pattern=PAT Specify patterns of files to ignore (in addition to those in
69+
`.eslintignore`)
70+
--no-ignore Disable excluding files from `.eslintignore` files, --ignore-path
71+
flags and --ignore-pattern flags
72+
73+
Handle Warnings
74+
--quiet Disable reporting on warnings, only errors are reported
75+
--deny-warnings Ensure warnings produce a non-zero exit code
76+
--max-warnings=INT Specify a warning threshold, which can be used to force exit with an
77+
error status if there are too many warning-level rule violations in
78+
your project
79+
80+
Output
81+
-f, --format=ARG Use a specific output format. Possible values: `checkstyle`,
82+
`default`, `github`, `gitlab`, `json`, `junit`, `stylish`, `unix`
83+
84+
Miscellaneous
85+
--silent Do not display any diagnostics
86+
--threads=INT Number of threads to use. Set to 1 for using only 1 CPU core.
87+
--print-config This option outputs the configuration to be used. When present, no
88+
linting is performed and only config-related options are valid.
89+
90+
Inline Configuration Comments
91+
--report-unused-disable-directives Report directive comments like `// oxlint-disable-line`,
92+
when no errors would have been reported on that line anyway
93+
--report-unused-disable-directives-severity=SEVERITY Same as
94+
`--report-unused-disable-directives`, but allows you to specify the
95+
severity level of the reported errors. Only one of these two options
96+
can be used at a time.
97+
98+
Available positional items:
99+
PATH Single file, single path or list of paths
100+
101+
Available options:
102+
--rules List all the rules that are currently registered
103+
--lsp Start the language server
104+
--disable-nested-config Disable the automatic loading of nested configuration files
105+
--type-aware Enable rules that require type information
106+
--type-check Enable experimental type checking (includes TypeScript compiler
107+
diagnostics)
108+
-h, --help Prints help information
109+
-V, --version Prints version information
110+
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
2-
"ignoredPlatforms": ["win32"],
32
"commands": [
4-
"oxlint # should reject non-LSP usage",
5-
"oxlint --help # should reject non-LSP usage"
3+
"node ../node_modules/vite-plus/bin/oxlint # should reject non-LSP usage",
4+
"node ../node_modules/vite-plus/bin/oxlint --help # should reject non-LSP usage",
5+
"node ../node_modules/vite-plus/bin/oxlint --lsp --help # should exercise import path"
66
]
77
}

0 commit comments

Comments
 (0)