fix(node-swc): Recover from ldd not found

This commit is contained in:
Donny 2022-01-03 18:24:29 +09:00
parent 1e5bc88cd3
commit 1dfc2ee105
2 changed files with 13 additions and 9 deletions

View File

@ -9,10 +9,6 @@ export class ExternalObject<T> {
[K: symbol]: T
}
}
export interface TransformOutput {
code: string
map?: string | undefined | null
}
export function bundle(confItems: Buffer, signal?: AbortSignal | undefined | null): Promise<{ [index: string]: { code: string, map?: string } }>
export function minify(code: Buffer, opts: Buffer, signal?: AbortSignal | undefined | null): Promise<TransformOutput>
export function minifySync(code: Buffer, opts: Buffer): TransformOutput

View File

@ -5,9 +5,19 @@ const { platform, arch } = process
let nativeBinding = null
let localFileExisted = false
let isMusl = false
let loadError = null
const isMusl = () => {
try {
const isMusl = readFileSync('/usr/bin/ldd', 'utf8').includes('musl')
return isMusl;
} catch(e) {
return false;
}
}
switch (platform) {
case 'android':
if (arch !== 'arm64') {
@ -122,8 +132,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, 'swc.linux-x64-musl.node')
)
@ -152,8 +161,7 @@ switch (platform) {
}
break
case 'arm64':
isMusl = readFileSync('/usr/bin/ldd', 'utf8').includes('musl')
if (isMusl) {
if (isMusl()) {
localFileExisted = existsSync(
join(__dirname, 'swc.linux-arm64-musl.node')
)