Skip to content

Commit

Permalink
feat(linter): added support to run in Node.JS legacy versions (#8648)
Browse files Browse the repository at this point in the history
With a few adjustments It is possible to run _oxlint_ in projects which
use legacy **Node.js** versions, such as **8.x.x**. Basically this is
possible by removing spread operator in 'binpath' environment assemble
and changing a catch command to inform an error variable.

Without this modification, we got always this error:

```
node_modules/oxlint/bin/oxlint:23
  } catch {
          ^

SyntaxError: Unexpected token {
    at createScript (vm.js:74:10)
    at Object.runInThisContext (vm.js:116:10)
    at Module._compile (module.js:533:28)
    at Object.Module._extensions..js (module.js:580:10)
    at Module.load (module.js:503:32)
    at tryModuleLoad (module.js:466:12)
    at Function.Module._load (module.js:458:3)
    at Function.Module.runMain (module.js:605:10)
    at startup (bootstrap_node.js:158:16)
    at bootstrap_node.js:575:3
```
  • Loading branch information
luizwbr authored Jan 23, 2025
1 parent dcaebe6 commit 79ba9b5
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
13 changes: 6 additions & 7 deletions npm/oxlint/bin/oxlint
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const isMuslFromFilesystem = () => {
const { readFileSync } = require("fs");
try {
return readFileSync("/usr/bin/ldd", "utf-8").includes("musl");
} catch {
} catch(_error) {
return null;
}
};
Expand Down Expand Up @@ -91,9 +91,9 @@ const PLATFORMS = {
};

let binPath = (
PLATFORMS &&
PLATFORMS[platform] &&
PLATFORMS[platform][arch] &&
PLATFORMS &&
PLATFORMS[platform] &&
PLATFORMS[platform][arch] &&
PLATFORMS[platform][arch][isMusl() ? "musl" : "gnu"]
) || null;

Expand All @@ -104,12 +104,11 @@ if (binPath) {
{
shell: false,
stdio: "inherit",
env: {
...env,
env: Object.assign({}, env, {
JS_RUNTIME_VERSION: version,
JS_RUNTIME_NAME: release.name,
NODE_PACKAGE_MANAGER: detectPackageManager(),
},
}),
}
);

Expand Down
2 changes: 1 addition & 1 deletion npm/oxlint/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"url": "https://github.com/sponsors/Boshen"
},
"engines": {
"node": ">=14.*"
"node": ">=8.*"
},
"files": [
"bin/oxlint",
Expand Down

0 comments on commit 79ba9b5

Please sign in to comment.