Skip to content

Commit 41e78e2

Browse files
authored
feat(cli/bin): Allow --stdin-filepath for oxfmt bin (#1429)
Partially helps #979 I think the path to deprecating the wrapper bin is still way too far, so I improve the current situation. Regarding oxlint, we do not have received any specific usage reports yet, so do nothing for now.
1 parent c5e09e7 commit 41e78e2

3 files changed

Lines changed: 49 additions & 6 deletions

File tree

packages/cli/bin/oxfmt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@
44
// This enables IDE extensions (e.g., oxc-vscode) to discover and start the LSP server.
55
// Binary resolution follows the same approach as `src/resolve-fmt.ts`.
66

7-
if (!process.argv.includes('--lsp')) {
8-
console.error('This oxfmt wrapper is for IDE extension use only (--lsp mode).');
7+
const isLSP = process.argv.includes('--lsp');
8+
const isStdin = process.argv.some((arg) => arg.startsWith('--stdin-filepath'));
9+
if (!isLSP && !isStdin) {
10+
console.error('This oxfmt wrapper is for IDE extension use only (lsp or stdin mode).');
911
console.error('To format your code, run: vp fmt');
1012
process.exit(1);
1113
}

packages/cli/snap-tests/bin-oxfmt-wrapper/snap.txt

Lines changed: 43 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,52 @@
11
[1]> node ../node_modules/vite-plus/bin/oxfmt # should reject non-LSP usage
2-
This oxfmt wrapper is for IDE extension use only (--lsp mode).
2+
This oxfmt wrapper is for IDE extension use only (lsp or stdin mode).
33
To format your code, run: vp fmt
44

55
[1]> node ../node_modules/vite-plus/bin/oxfmt --help # should reject non-LSP usage
6-
This oxfmt wrapper is for IDE extension use only (--lsp mode).
6+
This oxfmt wrapper is for IDE extension use only (lsp or stdin mode).
77
To format your code, run: vp fmt
88

9-
> node ../node_modules/vite-plus/bin/oxfmt --lsp --help # should exercise import path
9+
> node ../node_modules/vite-plus/bin/oxfmt --lsp --help # should allow LSP mode
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+
48+
49+
> node ../node_modules/vite-plus/bin/oxfmt --stdin-filepath=a.ts --help # should allow Stdin mode
1050
Usage: [-c=PATH] [PATH]...
1151

1252
Mode Options:

packages/cli/snap-tests/bin-oxfmt-wrapper/steps.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"commands": [
33
"node ../node_modules/vite-plus/bin/oxfmt # should reject non-LSP usage",
44
"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"
5+
"node ../node_modules/vite-plus/bin/oxfmt --lsp --help # should allow LSP mode",
6+
"node ../node_modules/vite-plus/bin/oxfmt --stdin-filepath=a.ts --help # should allow Stdin mode"
67
]
78
}

0 commit comments

Comments
 (0)