Skip to content

Commit a14aa79

Browse files
committed
feat(npm/oxlint): convert to ES modules (#13876)
## Summary - Convert npm/oxlint package to ES modules by setting `"type": "module"` in package.json ## Test plan - [ ] Verify CLI binaries continue to work correctly - [ ] Test package installation and execution - [ ] Run existing test suites - [ ] Confirm language server binary still functions 🤖 Generated with [Claude Code](https://claude.ai/code)
1 parent 4e6fc11 commit a14aa79

File tree

10 files changed

+16
-37
lines changed

10 files changed

+16
-37
lines changed

apps/oxlint/scripts/build.js

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,6 @@ writeFileSync(bindingsPath, bindingsJs);
2020
console.log('Building with tsdown...');
2121
execSync('pnpm tsdown', { stdio: 'inherit', cwd: oxlintDirPath });
2222

23-
// Add `package.json` to `dist` dir.
24-
// `npm/oxlint` package is CommonJS, so we need this file to tell Node.js that `dist` is ESM.
25-
console.log('Adding package.json to dist...');
26-
writeFileSync(
27-
join(distDirPath, 'package.json'),
28-
JSON.stringify({ type: 'module' }, null, 2) + '\n',
29-
);
30-
console.log('- Created package.json');
31-
3223
// Copy files from `napi/parser` to `apps/oxlint/dist`
3324
console.log('Copying files from parser...');
3425

crates/oxc_allocator/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ homepage.workspace = true
88
include = ["/src"]
99
keywords.workspace = true
1010
license.workspace = true
11+
publish = true
1112
repository.workspace = true
1213
rust-version.workspace = true
1314
description.workspace = true
14-
publish = true
1515

1616
[lints]
1717
workspace = true

crates/oxc_ast/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ homepage.workspace = true
88
include = ["/src"]
99
keywords.workspace = true
1010
license.workspace = true
11+
publish = true
1112
repository.workspace = true
1213
rust-version.workspace = true
1314
description.workspace = true
14-
publish = true
1515

1616
[lints]
1717
workspace = true

crates/oxc_ast_visit/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ homepage.workspace = true
88
include = ["/src"]
99
keywords.workspace = true
1010
license.workspace = true
11+
publish = true
1112
repository.workspace = true
1213
rust-version.workspace = true
1314
description.workspace = true
14-
publish = true
1515

1616
[lints]
1717
workspace = true

crates/oxc_diagnostics/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ homepage.workspace = true
88
include = ["/src"]
99
keywords.workspace = true
1010
license.workspace = true
11+
publish = true
1112
repository.workspace = true
1213
rust-version.workspace = true
1314
description.workspace = true
14-
publish = true
1515

1616
[lints]
1717
workspace = true

crates/oxc_parser/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ homepage.workspace = true
88
include = ["/examples", "/src"]
99
keywords.workspace = true
1010
license.workspace = true
11+
publish = true
1112
repository.workspace = true
1213
rust-version.workspace = true
1314
description.workspace = true
14-
publish = true
1515

1616
[lints]
1717
workspace = true

crates/oxc_semantic/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ homepage.workspace = true
88
include = ["/examples", "/src"]
99
keywords.workspace = true
1010
license.workspace = true
11+
publish = true
1112
repository.workspace = true
1213
rust-version.workspace = true
1314
description.workspace = true
14-
publish = true
1515

1616
[lints]
1717
workspace = true

npm/oxlint/bin/oxc_language_server

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
#!/usr/bin/env node
22

3+
import { readFileSync } from "fs";
4+
import { spawnSync, execSync } from "child_process";
5+
import { createRequire } from "module";
6+
7+
const require = createRequire(import.meta.url);
8+
39
const isMusl = () => {
410
let musl = false;
511
if (process.platform === "linux") {
@@ -17,7 +23,6 @@ const isMusl = () => {
1723
const isFileMusl = (f) => f.includes("libc.musl-") || f.includes("ld-musl-");
1824

1925
const isMuslFromFilesystem = () => {
20-
const { readFileSync } = require("fs");
2126
try {
2227
return readFileSync("/usr/bin/ldd", "utf-8").includes("musl");
2328
} catch {
@@ -46,8 +51,7 @@ const isMuslFromReport = () => {
4651

4752
const isMuslFromChildProcess = () => {
4853
try {
49-
return require("child_process")
50-
.execSync("ldd --version", { encoding: "utf8" })
54+
return execSync("ldd --version", { encoding: "utf8" })
5155
.includes("musl");
5256
} catch (e) {
5357
// If we reach this case, we don't know if the system is musl or not, so is better to just fallback to false
@@ -95,7 +99,7 @@ const PLATFORMS = {
9599
let binPath = PLATFORMS[platform]?.[arch]?.[isMusl() ? "musl" : "gnu"];
96100

97101
if (binPath) {
98-
const result = require("child_process").spawnSync(
102+
const result = spawnSync(
99103
require.resolve(binPath),
100104
process.argv.slice(2),
101105
{

npm/oxlint/bin/oxlint

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,3 @@
11
#!/usr/bin/env node
22

3-
// This script is run as CommonJS, so use dynamic import to load ESM module `dist/cli.js`.
4-
// Even if runtime supports require(ESM), can't use `require` here, because `dist/cli.js`
5-
// uses top-level `await`.
6-
//
7-
// `dist/cli.js` uses require(ESM) internally, but only on path where `--js-plugins`
8-
// CLI option is used. So we still support runtimes without require(ESM) for users who aren't
9-
// using experimental options.
10-
import("../dist/cli.js").catch(onError);
11-
12-
function onError(err) {
13-
console.error(err);
14-
// Note: NodeJS recommends setting `process.exitCode` instead of calling `process.exit()`.
15-
// `process.exit()` kills the process immediately and `stdout` may not be flushed before process dies.
16-
// https://nodejs.org/api/process.html#processexitcode
17-
// Process should exit immediately after this anyway, because event loop is empty.
18-
process.exitCode = 1;
19-
}
3+
import "../dist/cli.js";

npm/oxlint/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "oxlint",
33
"version": "1.16.0",
4-
"type": "commonjs",
4+
"type": "module",
55
"description": "Linter for the JavaScript Oxidation Compiler",
66
"keywords": [],
77
"author": "Boshen and oxc contributors",

0 commit comments

Comments
 (0)