Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function prebuild (opts, target, runtime, callback) {
var pkg = opts.pkg
var buildLog = opts.buildLog || function () {}
opts.target = target
opts.runtime = runtime
if (opts.runtime === 'node-webkit') {
opts.backend = 'nw-gyp'
}
var buildLogMessage = 'Preparing to prebuild ' + pkg.name + '@' + pkg.version + ' for ' + runtime + ' ' + target + ' on ' + opts.platform + '-' + opts.arch + ' using ' + opts.backend
if (opts.libc && opts.libc.length > 0) buildLogMessage += 'using libc ' + opts.libc
buildLog(buildLogMessage)
// --target can be target or abi
if (!napi.isNapiRuntime(runtime)) target = getTarget(target, runtime)
var abi = getAbi(target, runtime)
var tarPath = getTarPath(opts, abi)
fs.stat(tarPath, function (err, st) {
if (!err && !opts.force) {
buildLog(tarPath + ' exists, skipping build')
return callback(null, tarPath)
}
var tasks = [
function (cb) {
build(opts, target, function (err, filenames) {
if (err) return cb(err)
cb(null, filenames)
})
},
function (filenames, cb) {
function build({target, runtime, abi}) {
try {
abi && getTarget(target, runtime);
} catch (err) {
return Promise.resolve();
}
const args = ['--verbose', '-r', runtime, '-t', target];
if (libc.isNonGlibcLinux) {
process.env.LIBC = libc.family;
}
if (PUBLISH_BINARY) {
args.push('-u', PREBUILD_TOKEN);
}
return new Promise((resolve, reject) => {
const proc = spawn('prebuild', args, { env: npmRunPath.env() });