Skip to content

Commit b8038dc

Browse files
committed
fix: detect musl vs glibc for Alpine Linux npm install
- Add musl/glibc detection to bin/opencode wrapper script - Add musl/glibc detection to script/postinstall.mjs - Fixes issue where npm install fails on Alpine Linux - Uses same detection logic as publish-registries.ts Fixes anomalyco#9571
1 parent 616329a commit b8038dc

2 files changed

Lines changed: 48 additions & 4 deletions

File tree

‎packages/opencode/bin/opencode‎

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,29 @@ let arch = archMap[os.arch()]
4444
if (!arch) {
4545
arch = os.arch()
4646
}
47-
const base = "opencode-" + platform + "-" + arch
47+
48+
// Detect musl vs glibc on Linux
49+
let libc = ""
50+
if (platform === "linux") {
51+
try {
52+
const lddVersion = childProcess.execSync("ldd --version 2>&1", { encoding: "utf8" })
53+
if (lddVersion.toLowerCase().includes("musl")) {
54+
libc = "-musl"
55+
}
56+
} catch (e) {
57+
// ldd failed, try alternative detection
58+
try {
59+
const muslFiles = fs.readdirSync("/lib").filter((f) => f.startsWith("ld-musl-"))
60+
if (muslFiles.length > 0) {
61+
libc = "-musl"
62+
}
63+
} catch (e) {
64+
// Ignore, default to glibc
65+
}
66+
}
67+
}
68+
69+
const base = "opencode-" + platform + "-" + arch + libc
4870
const binary = platform === "windows" ? "opencode.exe" : "opencode"
4971

5072
function findBinary(startDir) {

‎packages/opencode/script/postinstall.mjs‎

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import path from "path"
55
import os from "os"
66
import { fileURLToPath } from "url"
77
import { createRequire } from "module"
8+
import { execSync } from "child_process"
89

910
const __dirname = path.dirname(fileURLToPath(import.meta.url))
1011
const require = createRequire(import.meta.url)
@@ -44,12 +45,33 @@ function detectPlatformAndArch() {
4445
break
4546
}
4647

47-
return { platform, arch }
48+
// Detect musl vs glibc on Linux
49+
let libc = ""
50+
if (platform === "linux") {
51+
try {
52+
const lddVersion = execSync("ldd --version 2>&1", { encoding: "utf8" })
53+
if (lddVersion.toLowerCase().includes("musl")) {
54+
libc = "-musl"
55+
}
56+
} catch (e) {
57+
// ldd failed, try alternative detection
58+
try {
59+
const muslFiles = fs.readdirSync("/lib").filter((f) => f.startsWith("ld-musl-"))
60+
if (muslFiles.length > 0) {
61+
libc = "-musl"
62+
}
63+
} catch (e) {
64+
// Ignore, default to glibc
65+
}
66+
}
67+
}
68+
69+
return { platform, arch, libc }
4870
}
4971

5072
function findBinary() {
51-
const { platform, arch } = detectPlatformAndArch()
52-
const packageName = `opencode-${platform}-${arch}`
73+
const { platform, arch, libc } = detectPlatformAndArch()
74+
const packageName = `opencode-${platform}-${arch}${libc}`
5375
const binaryName = platform === "windows" ? "opencode.exe" : "opencode"
5476

5577
try {

0 commit comments

Comments
 (0)