diff --git a/native/package.json b/native/package.json index a580124..ed96e82 100644 --- a/native/package.json +++ b/native/package.json @@ -1,6 +1,6 @@ { "name": "@ashbyhq/libpg-query-native", - "version": "0.1.0", + "version": "0.1.1", "description": "PostgreSQL query parser — native N-API + jemalloc backend", "main": "./dist/index.js", "types": "./dist/index.d.ts", @@ -48,10 +48,10 @@ "typescript": "5.9.3" }, "optionalDependencies": { - "@ashbyhq/libpg-query-native-darwin-arm64": "0.1.0", - "@ashbyhq/libpg-query-native-linux-x64": "0.1.0", - "@ashbyhq/libpg-query-native-linux-arm64": "0.1.0", - "@ashbyhq/libpg-query-native-linux-x64-musl": "0.1.0", - "@ashbyhq/libpg-query-native-linux-arm64-musl": "0.1.0" + "@ashbyhq/libpg-query-native-darwin-arm64": "0.1.1", + "@ashbyhq/libpg-query-native-linux-x64": "0.1.1", + "@ashbyhq/libpg-query-native-linux-arm64": "0.1.1", + "@ashbyhq/libpg-query-native-linux-x64-musl": "0.1.1", + "@ashbyhq/libpg-query-native-linux-arm64-musl": "0.1.1" } } diff --git a/native/src/index.ts b/native/src/index.ts index 43bbf7f..f7994a7 100644 --- a/native/src/index.ts +++ b/native/src/index.ts @@ -83,13 +83,27 @@ function loadNativeAddon(): NativeAddon { function isMusl(): boolean { if (process.platform !== "linux") return false; + // Prefer Node's own libc marker: `glibcVersionRuntime` is set on glibc and + // absent on musl. This is reliable in minimal images (distroless/scratch) + // that ship no `ldd` binary — shelling out there throws and would otherwise + // be misread as musl, selecting the wrong platform package. try { - const { execSync } = require("child_process"); - const ldd = execSync("ldd --version 2>&1", { encoding: "utf8" }); - return ldd.includes("musl"); + const report = process.report?.getReport?.() as + | { header?: { glibcVersionRuntime?: string } } + | undefined; + if (report?.header != null) { + return report.header.glibcVersionRuntime == null; + } } catch { - // ldd --version exits non-zero on musl - return true; + // fall through to the filesystem probe + } + // Fallback (older runtimes without process.report): look for the musl + // dynamic loader on disk. Default to glibc — the common case — when unsure. + try { + const fs = require("fs"); + return fs.readdirSync("/lib").some((f: string) => f.startsWith("ld-musl-")); + } catch { + return false; } }