Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function runGyp (opts, target, cb) {
var args = ['node', 'index.js']
if (opts.backend === 'node-ninja') {
args.push('configure')
args.push('build')
args.push('--builddir=build/' + target)
} else {
args.push('rebuild')
}
if (napi.isNapiRuntime(opts.runtime)) {
args.push('--napi_build_version=' + target)
} else {
args.push('--target=' + target)
}
args.push('--target_arch=' + opts.arch)
if (opts.runtime === 'electron') {
args.push('--runtime=electron')
args.push('--dist-url=https://atom.io/download/electron')
} else if (opts.runtime === 'node-webkit') {
args.push('--runtime=node-webkit')
} else if (opts.runtime === 'node') {
// work around bug introduced in node 10's build https://github.com/nodejs/node-gyp/issues/1457
args.push('--build_v8_with_gn=false')
// work around the same kind of bug for node 11
args.push('--enable_lto=false')
}
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) {
help: 'h',
arch: 'a',
path: 'p',
version: 'v',
download: 'd',
'build-from-source': 'compile',
compile: 'c',
token: 'T'
}
}))
if (rc.path === true) {
delete rc.path
}
if (napi.isNapiRuntime(rc.runtime) && rc.target === process.versions.node) {
rc.target = napi.getBestNapiBuildVersion()
}
rc.abi = napi.isNapiRuntime(rc.runtime) ? rc.target : getAbi(rc.target, rc.runtime)
return rc
}
download: 'd',
'build-from-source': 'compile',
compile: 'c',
token: 'T'
}
}))
if (rc.path === true) {
delete rc.path
}
if (napi.isNapiRuntime(rc.runtime) && rc.target === process.versions.node) {
rc.target = napi.getBestNapiBuildVersion()
}
rc.abi = napi.isNapiRuntime(rc.runtime) ? rc.target : getAbi(rc.target, rc.runtime)
return rc
}
force: 'f',
version: 'v',
upload: 'u',
preinstall: 'i',
prepack: 'c'
},
string: [
'target'
]
}))
if (rc.path === true) {
delete rc.path
}
if (napi.isNapiRuntime(rc.runtime) && rc.target === process.versions.node) {
if (rc.all === true) {
rc.target = napi.getNapiBuildVersions()
} else {
rc.target = napi.getBestNapiBuildVersion()
}
}
if (rc.target) {
var arr = [].concat(rc.target)
rc.prebuild = []
for (var k = 0, len = arr.length; k < len; k++) {
if (!napi.isNapiRuntime(rc.runtime) || napi.isSupportedVersion(arr[k])) {
rc.prebuild.push({
runtime: rc.runtime,
target: arr[k]
})