Skip to content

Commit 55f2e37

Browse files
committed
fix(cli): Resolve bin/oxfmt as like oxlint
1 parent f64bb6c commit 55f2e37

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

packages/cli/bin/oxfmt

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

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

1617
const require = createRequire(import.meta.url);
17-
const oxfmtBin = require.resolve('oxfmt/bin/oxfmt');
18+
const oxfmtMainPath = require.resolve('oxfmt');
19+
const oxfmtBin = join(dirname(dirname(oxfmtMainPath)), 'bin', 'oxfmt');
1820

1921
await import(pathToFileURL(oxfmtBin).href);

packages/cli/src/resolve-fmt.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
* provides high-performance code formatting capabilities.
1212
*/
1313

14+
import { dirname, join } from 'node:path';
15+
1416
import { DEFAULT_ENVS, resolve } from './utils/constants.ts';
1517

1618
/**
@@ -27,8 +29,13 @@ export async function fmt(): Promise<{
2729
binPath: string;
2830
envs: Record<string, string>;
2931
}> {
30-
// Resolve the oxfmt binary directly (it's a native executable)
31-
const binPath = resolve('oxfmt/bin/oxfmt');
32+
// Resolve the oxfmt package path first, then navigate to the bin file.
33+
// The bin/oxfmt subpath is not exported in package.json exports, so we
34+
// resolve the main entry point and derive the bin path from it.
35+
// resolve('oxfmt') returns .../oxfmt/dist/index.js, so we need to go up
36+
// two directories (past 'dist') to reach the package root.
37+
const oxfmtMainPath = resolve('oxfmt');
38+
const binPath = join(dirname(dirname(oxfmtMainPath)), 'bin', 'oxfmt');
3239

3340
return {
3441
binPath,

0 commit comments

Comments
 (0)