Skip to content

Commit 52709db

Browse files
authored
feat(cli): Install wrapper bin/ox(lint|fmt) for oxc-vscode (#633)
Fixes #629 - [x] Implement - [x] Test with VSCode - [x] Add snapshot tests
1 parent 2bd2792 commit 52709db

9 files changed

Lines changed: 75 additions & 0 deletions

File tree

packages/cli/bin/oxfmt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/usr/bin/env node
2+
3+
// LSP-only wrapper for oxfmt.
4+
// This enables IDE extensions (e.g., oxc-vscode) to discover and start the LSP server.
5+
// Binary resolution follows the same approach as `src/resolve-fmt.ts`.
6+
7+
if (!process.argv.includes('--lsp')) {
8+
console.error('This oxfmt wrapper is for IDE extension use only (--lsp mode).');
9+
console.error('To format your code, run: vp fmt');
10+
process.exit(1);
11+
}
12+
13+
import { createRequire } from 'node:module';
14+
15+
const require = createRequire(import.meta.url);
16+
const oxfmtBin = require.resolve('oxfmt/bin/oxfmt');
17+
18+
await import(oxfmtBin);

packages/cli/bin/oxlint

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/usr/bin/env node
2+
3+
// LSP-only wrapper for oxlint.
4+
// This enables IDE extensions (e.g., oxc-vscode) to discover and start the LSP server.
5+
// Binary resolution follows the same approach as `src/resolve-lint.ts`.
6+
7+
if (!process.argv.includes('--lsp')) {
8+
console.error('This oxlint wrapper is for IDE extension use only (--lsp mode).');
9+
console.error('To lint your code, run: vp lint');
10+
process.exit(1);
11+
}
12+
13+
import { createRequire } from 'node:module';
14+
import { dirname, join } from 'node:path';
15+
16+
const require = createRequire(import.meta.url);
17+
const oxlintMainPath = require.resolve('oxlint');
18+
const oxlintBin = join(dirname(dirname(oxlintMainPath)), 'bin', 'oxlint');
19+
20+
await import(oxlintBin);

packages/cli/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
"name": "vite-plus",
33
"version": "0.0.0",
44
"bin": {
5+
"oxfmt": "./bin/oxfmt",
6+
"oxlint": "./bin/oxlint",
57
"vp": "./bin/vp"
68
},
79
"files": [
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"name": "bin-oxfmt-wrapper",
3+
"version": "0.0.0",
4+
"private": true
5+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[1]> oxfmt # should reject non-LSP usage
2+
This oxfmt wrapper is for IDE extension use only (--lsp mode).
3+
To format your code, run: vp fmt
4+
5+
[1]> oxfmt --help # should reject non-LSP usage
6+
This oxfmt wrapper is for IDE extension use only (--lsp mode).
7+
To format your code, run: vp fmt
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"ignoredPlatforms": ["win32"],
3+
"commands": ["oxfmt # should reject non-LSP usage", "oxfmt --help # should reject non-LSP usage"]
4+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"name": "bin-oxlint-wrapper",
3+
"version": "0.0.0",
4+
"private": true
5+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[1]> oxlint # should reject non-LSP usage
2+
This oxlint wrapper is for IDE extension use only (--lsp mode).
3+
To lint your code, run: vp lint
4+
5+
[1]> oxlint --help # should reject non-LSP usage
6+
This oxlint wrapper is for IDE extension use only (--lsp mode).
7+
To lint your code, run: vp lint
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"ignoredPlatforms": ["win32"],
3+
"commands": [
4+
"oxlint # should reject non-LSP usage",
5+
"oxlint --help # should reject non-LSP usage"
6+
]
7+
}

0 commit comments

Comments
 (0)