fix(cli): handle lld not found

This commit is contained in:
LongYinan 2022-01-03 21:59:57 +08:00
parent 671ac80e8b
commit eb79ccebbe
No known key found for this signature in database
GPG key ID: C3666B7FC82ADAD7

View file

@ -8,9 +8,22 @@ const { platform, arch } = process
let nativeBinding = null let nativeBinding = null
let localFileExisted = false let localFileExisted = false
let isMusl = false
let loadError = null 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) { switch (platform) {
case 'android': case 'android':
if (arch !== 'arm64') { if (arch !== 'arm64') {
@ -125,8 +138,7 @@ switch (platform) {
case 'linux': case 'linux':
switch (arch) { switch (arch) {
case 'x64': case 'x64':
isMusl = readFileSync('/usr/bin/ldd', 'utf8').includes('musl') if (isMusl()) {
if (isMusl) {
localFileExisted = existsSync( localFileExisted = existsSync(
join(__dirname, '${localName}.linux-x64-musl.node') join(__dirname, '${localName}.linux-x64-musl.node')
) )
@ -155,8 +167,7 @@ switch (platform) {
} }
break break
case 'arm64': case 'arm64':
isMusl = readFileSync('/usr/bin/ldd', 'utf8').includes('musl') if (isMusl()) {
if (isMusl) {
localFileExisted = existsSync( localFileExisted = existsSync(
join(__dirname, '${localName}.linux-arm64-musl.node') join(__dirname, '${localName}.linux-arm64-musl.node')
) )