Skip to content

Commit

Permalink
fix(core): linux musl addon loader
Browse files Browse the repository at this point in the history
  • Loading branch information
LongYinan committed Aug 24, 2020
1 parent 24a4c33 commit c6e8a78
Showing 1 changed file with 26 additions and 3 deletions.
29 changes: 26 additions & 3 deletions packages/core/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,37 @@ const { platform } = require('os')
const { loadBinding } = require('@node-rs/helper')

let bindings
let linuxError = null

try {
bindings = loadBinding(__dirname, 'swc')
} catch (e) {
const platformName = platform()
try {
bindings = require(`@swc-node/core-${platform()}`)
bindings = require(`@swc-node/core-${platformName}`)
} catch (e) {
throw new TypeError('Not compatible with your platform. Error message: ' + e.message)
if (platformName !== 'linux') {
throw new TypeError('Not compatible with your platform. Error message: ' + e.message)
} else {
linuxError = e
}
}
}

if (!bindings) {
try {
require.resolve('@swc-node/core-linux-musl')
} catch (e) {
throw new TypeError(
`Could not load @swc-node/core-linux, You may need add @swc-node/core-linux-musl to optionalDependencies of your project`,
)
}
try {
bindings = require('@swc-node/core-linux-musl')
} catch (e) {
throw new TypeError(
`Linux glibc version load error: ${linuxError.message}; Linux musl version load error: Error message: ${e.message}`,
)
}
}

Expand Down Expand Up @@ -68,5 +91,5 @@ module.exports = {
return bindings.transform(source, path, Buffer.from(JSON.stringify(swcOptions)))
},

SWC_VERSION: 'e619144',
SWC_VERSION: '1.2.21',
}

0 comments on commit c6e8a78

Please sign in to comment.