Skip to content

Commit b149eb3

Browse files
committed
fix(cli): use pathToFileURL for dynamic imports in oxfmt/oxlint bin wrappers
On Windows, Node.js ESM loader rejects absolute paths like `c:\Users\...` because it interprets the drive letter as a URL scheme. Convert resolved paths to file:// URLs via pathToFileURL() which works on all platforms. Also enable win32 snap tests for both wrappers since the non-LSP error path doesn't involve dynamic imports. Closes oxc-project/oxc-vscode#149
1 parent b50a329 commit b149eb3

4 files changed

Lines changed: 4 additions & 4 deletions

File tree

packages/cli/bin/oxfmt

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

1313
import { createRequire } from 'node:module';
14+
import { pathToFileURL } from 'node:url';
1415

1516
const require = createRequire(import.meta.url);
1617
const oxfmtBin = require.resolve('oxfmt/bin/oxfmt');
1718

18-
await import(oxfmtBin);
19+
await import(pathToFileURL(oxfmtBin).href);

packages/cli/bin/oxlint

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

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

1617
const require = createRequire(import.meta.url);
1718
const oxlintMainPath = require.resolve('oxlint');
1819
const oxlintBin = join(dirname(dirname(oxlintMainPath)), 'bin', 'oxlint');
1920

20-
await import(oxlintBin);
21+
await import(pathToFileURL(oxlintBin).href);
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
{
2-
"ignoredPlatforms": ["win32"],
32
"commands": ["oxfmt # should reject non-LSP usage", "oxfmt --help # should reject non-LSP usage"]
43
}

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
{
2-
"ignoredPlatforms": ["win32"],
32
"commands": [
43
"oxlint # should reject non-LSP usage",
54
"oxlint --help # should reject non-LSP usage"

0 commit comments

Comments
 (0)