mirror of
https://github.com/danbulant/oxc
synced 2026-05-24 20:32:10 +00:00
fix(npm): fix bin script for musl / gnu
This commit is contained in:
parent
fda2d7c334
commit
382a187175
3 changed files with 136 additions and 25 deletions
33
.github/workflows/release_oxlint.yml
vendored
33
.github/workflows/release_oxlint.yml
vendored
|
|
@ -121,21 +121,18 @@ jobs:
|
||||||
|
|
||||||
publish:
|
publish:
|
||||||
name: Publish
|
name: Publish
|
||||||
|
needs: build
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
permissions:
|
permissions:
|
||||||
contents: write # for softprops/action-gh-release@v1
|
contents: write # for softprops/action-gh-release@v1
|
||||||
id-token: write # for `npm publish --provenance`
|
id-token: write # for `npm publish --provenance`
|
||||||
needs:
|
|
||||||
- build
|
|
||||||
env:
|
|
||||||
version: ${{ needs.check.outputs.version }}
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
|
|
||||||
- name: Install Node.js
|
- name: Install Node.js
|
||||||
uses: actions/setup-node@v4
|
uses: actions/setup-node@v4
|
||||||
with:
|
with:
|
||||||
node-version: 18
|
node-version: 20
|
||||||
registry-url: 'https://registry.npmjs.org'
|
registry-url: 'https://registry.npmjs.org'
|
||||||
|
|
||||||
- name: Download Artifacts
|
- name: Download Artifacts
|
||||||
|
|
@ -176,8 +173,30 @@ jobs:
|
||||||
- name: Create GitHub Release
|
- name: Create GitHub Release
|
||||||
uses: softprops/action-gh-release@v1
|
uses: softprops/action-gh-release@v1
|
||||||
with:
|
with:
|
||||||
name: oxlint v${{ env.version }}
|
name: oxlint v${{ needs.check.outputs.version }}
|
||||||
tag_name: oxlint_v${{ env.version }}
|
tag_name: oxlint_v${{ needs.check.outputs.version }}
|
||||||
draft: true
|
draft: true
|
||||||
files: oxlint-*
|
files: oxlint-*
|
||||||
fail_on_unmatched_files: true
|
fail_on_unmatched_files: true
|
||||||
|
|
||||||
|
- name: wait 3 minutes for smoke test
|
||||||
|
shell: bash
|
||||||
|
run: sleep 180s
|
||||||
|
|
||||||
|
smoke:
|
||||||
|
needs: publish
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
include:
|
||||||
|
- os: windows-latest
|
||||||
|
- os: ubuntu-latest
|
||||||
|
- os: macos-latest
|
||||||
|
name: Smoke Test ${{ matrix.os }}
|
||||||
|
runs-on: ${{ matrix.os }}
|
||||||
|
steps:
|
||||||
|
- name: Test
|
||||||
|
shell: bash
|
||||||
|
run: |
|
||||||
|
touch test.js
|
||||||
|
npx oxlint@${{ needs.check.outputs.version }} ./test.js
|
||||||
|
exit 0
|
||||||
|
|
|
||||||
|
|
@ -1,22 +1,114 @@
|
||||||
#!/usr/bin/env node
|
#!/usr/bin/env node
|
||||||
const { platform, arch, env, version, release } = process;
|
|
||||||
|
|
||||||
const PLATFORMS = {
|
const isMusl = () => {
|
||||||
win32: {
|
let musl = false;
|
||||||
x64: "@oxlint/win32-x64/oxlint.exe",
|
if (process.platform === "linux") {
|
||||||
arm64: "@oxlint/win32-arm64/oxlint.exe",
|
musl = isMuslFromFilesystem();
|
||||||
},
|
if (musl === null) {
|
||||||
darwin: {
|
musl = isMuslFromReport();
|
||||||
x64: "@oxlint/darwin-x64/oxlint",
|
}
|
||||||
arm64: "@oxlint/darwin-arm64/oxlint",
|
if (musl === null) {
|
||||||
},
|
musl = isMuslFromChildProcess();
|
||||||
linux: {
|
}
|
||||||
x64: "@oxlint/linux-x64/oxlint",
|
}
|
||||||
arm64: "@oxlint/linux-arm64/oxlint",
|
return musl;
|
||||||
},
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const binPath = PLATFORMS?.[platform]?.[arch];
|
const isFileMusl = (f) => f.includes("libc.musl-") || f.includes("ld-musl-");
|
||||||
|
|
||||||
|
const isMuslFromFilesystem = () => {
|
||||||
|
const { readFileSync } = require("fs");
|
||||||
|
try {
|
||||||
|
return readFileSync("/usr/bin/ldd", "utf-8").includes("musl");
|
||||||
|
} catch {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const isMuslFromReport = () => {
|
||||||
|
const report =
|
||||||
|
typeof process.report.getReport === "function"
|
||||||
|
? process.report.getReport()
|
||||||
|
: null;
|
||||||
|
if (!report) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
if (report.header && report.header.glibcVersionRuntime) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (Array.isArray(report.sharedObjects)) {
|
||||||
|
if (report.sharedObjects.some(isFileMusl)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
};
|
||||||
|
|
||||||
|
const isMuslFromChildProcess = () => {
|
||||||
|
try {
|
||||||
|
return require("child_process")
|
||||||
|
.execSync("ldd --version", { encoding: "utf8" })
|
||||||
|
.includes("musl");
|
||||||
|
} catch (e) {
|
||||||
|
// If we reach this case, we don't know if the system is musl or not, so is better to just fallback to false
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const { platform, arch, env, version, release } = process;
|
||||||
|
|
||||||
|
let binPath;
|
||||||
|
|
||||||
|
switch (platform) {
|
||||||
|
case "win32": {
|
||||||
|
switch (arch) {
|
||||||
|
case "x64": {
|
||||||
|
binPath = "@oxlint/win32-x64/oxlint.exe";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case "arm64": {
|
||||||
|
binPath = "@oxlint/win32-arm64/oxlint.exe";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case "darwin": {
|
||||||
|
switch (arch) {
|
||||||
|
case "x64": {
|
||||||
|
binPath = "@oxlint/darwin-x64/oxlint";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case "arm64": {
|
||||||
|
binPath = "@oxlint/darwin-arm64/oxlint";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case "linux": {
|
||||||
|
switch (arch) {
|
||||||
|
case "x64": {
|
||||||
|
if (isMusl()) {
|
||||||
|
binPath = "@oxlint/linux-x64-musl/oxlint";
|
||||||
|
} else {
|
||||||
|
binPath = "@oxlint/linux-x64-gnu/oxlint";
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case "arm64": {
|
||||||
|
if (isMusl()) {
|
||||||
|
binPath = "@oxlint/linux-arm64-musl/oxlint";
|
||||||
|
} else {
|
||||||
|
binPath = "@oxlint/linux-arm64-gnu/oxlint";
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (binPath) {
|
if (binPath) {
|
||||||
const result = require("child_process").spawnSync(
|
const result = require("child_process").spawnSync(
|
||||||
require.resolve(binPath),
|
require.resolve(binPath),
|
||||||
|
|
@ -30,7 +122,7 @@ if (binPath) {
|
||||||
JS_RUNTIME_NAME: release.name,
|
JS_RUNTIME_NAME: release.name,
|
||||||
NODE_PACKAGE_MANAGER: detectPackageManager(),
|
NODE_PACKAGE_MANAGER: detectPackageManager(),
|
||||||
},
|
},
|
||||||
}
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
if (result.error) {
|
if (result.error) {
|
||||||
|
|
@ -41,7 +133,7 @@ if (binPath) {
|
||||||
} else {
|
} else {
|
||||||
console.error(
|
console.error(
|
||||||
"The oxlint CLI package doesn't ship with prebuilt binaries for your platform yet. " +
|
"The oxlint CLI package doesn't ship with prebuilt binaries for your platform yet. " +
|
||||||
"You can create an issue at https://github.com/oxc-project/oxc/issues for support."
|
"You can create an issue at https://github.com/oxc-project/oxc/issues for support.",
|
||||||
);
|
);
|
||||||
process.exitCode = 1;
|
process.exitCode = 1;
|
||||||
}
|
}
|
||||||
|
|
@ -64,4 +156,3 @@ function detectPackageManager() {
|
||||||
|
|
||||||
return userAgent.split(" ")[0];
|
return userAgent.split(" ")[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -85,6 +85,7 @@ function writeManifest() {
|
||||||
fs.writeFileSync(manifestPath, content);
|
fs.writeFileSync(manifestPath, content);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NOTE: Must update npm/oxlint/bin/oxlint
|
||||||
const TARGETS = [
|
const TARGETS = [
|
||||||
"win32-x64",
|
"win32-x64",
|
||||||
"win32-arm64",
|
"win32-arm64",
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue