From eb79ccebbeb0f9d1a3b4f4eff5e9a7271ff6f431 Mon Sep 17 00:00:00 2001 From: LongYinan Date: Mon, 3 Jan 2022 21:59:57 +0800 Subject: [PATCH] fix(cli): handle lld not found --- cli/src/js-binding-template.ts | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/cli/src/js-binding-template.ts b/cli/src/js-binding-template.ts index 5d64aeaf..e865d30d 100644 --- a/cli/src/js-binding-template.ts +++ b/cli/src/js-binding-template.ts @@ -8,9 +8,22 @@ const { platform, arch } = process let nativeBinding = null let localFileExisted = false -let isMusl = false let loadError = null +function isMusl() { + // For Node 10 + if (!process.report || typeof process.report.getReport !== 'function') { + try { + return readFileSync('/usr/bin/ldd', 'utf8').includes('musl') + } catch (e) { + return false + } + } else { + const { glibcVersionRuntime } = process.report.getReport().header + return !Boolean(glibcVersionRuntime) + } +} + switch (platform) { case 'android': if (arch !== 'arm64') { @@ -125,8 +138,7 @@ switch (platform) { case 'linux': switch (arch) { case 'x64': - isMusl = readFileSync('/usr/bin/ldd', 'utf8').includes('musl') - if (isMusl) { + if (isMusl()) { localFileExisted = existsSync( join(__dirname, '${localName}.linux-x64-musl.node') ) @@ -155,8 +167,7 @@ switch (platform) { } break case 'arm64': - isMusl = readFileSync('/usr/bin/ldd', 'utf8').includes('musl') - if (isMusl) { + if (isMusl()) { localFileExisted = existsSync( join(__dirname, '${localName}.linux-arm64-musl.node') )