diff --git a/packages/cli/bin/oxfmt b/packages/cli/bin/oxfmt index efae3059a5..6a0a68c568 100755 --- a/packages/cli/bin/oxfmt +++ b/packages/cli/bin/oxfmt @@ -11,9 +11,11 @@ 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 oxfmtBin = require.resolve('oxfmt/bin/oxfmt'); +const oxfmtMainPath = require.resolve('oxfmt'); +const oxfmtBin = join(dirname(dirname(oxfmtMainPath)), 'bin', 'oxfmt'); await import(pathToFileURL(oxfmtBin).href); diff --git a/packages/cli/src/resolve-fmt.ts b/packages/cli/src/resolve-fmt.ts index 198ca5e6a9..f9f319296b 100644 --- a/packages/cli/src/resolve-fmt.ts +++ b/packages/cli/src/resolve-fmt.ts @@ -11,6 +11,8 @@ * provides high-performance code formatting capabilities. */ +import { dirname, join } from 'node:path'; + import { DEFAULT_ENVS, resolve } from './utils/constants.ts'; /** @@ -27,8 +29,13 @@ export async function fmt(): Promise<{ binPath: string; envs: Record; }> { - // Resolve the oxfmt binary directly (it's a native executable) - const binPath = resolve('oxfmt/bin/oxfmt'); + // Resolve the oxfmt package path first, then navigate to the bin file. + // The bin/oxfmt subpath is not exported in package.json exports, so we + // resolve the main entry point and derive the bin path from it. + // resolve('oxfmt') returns .../oxfmt/dist/index.js, so we need to go up + // two directories (past 'dist') to reach the package root. + const oxfmtMainPath = resolve('oxfmt'); + const binPath = join(dirname(dirname(oxfmtMainPath)), 'bin', 'oxfmt'); return { binPath,