Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion packages/cli/bin/oxfmt
Original file line number Diff line number Diff line change
Expand Up @@ -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);
11 changes: 9 additions & 2 deletions packages/cli/src/resolve-fmt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
* provides high-performance code formatting capabilities.
*/

import { dirname, join } from 'node:path';

import { DEFAULT_ENVS, resolve } from './utils/constants.ts';

/**
Expand All @@ -27,8 +29,13 @@ export async function fmt(): Promise<{
binPath: string;
envs: Record<string, string>;
}> {
// 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,
Expand Down
Loading