Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if (rc.help) {
console.error(fs.readFileSync(path.join(__dirname, 'help.txt'), 'utf-8'))
process.exit(0)
}
log.info('begin', 'Prebuild version', prebuildVersion)
// nvm! do not mess with headers? kkthx!
delete process.env.NVM_IOJS_ORG_MIRROR
delete process.env.NVM_NODEJS_ORG_MIRROR
var buildLog = log.info.bind(log, 'build')
var opts = Object.assign({}, rc, { pkg: pkg, log: log, buildLog: buildLog, argv: process.argv })
if (napi.isNapiRuntime(rc.runtime)) napi.logMissingNapiVersions(rc.target, rc.prebuild, log)
if (opts['upload-all']) {
fs.readdir('prebuilds', function (err, pbFiles) {
if (err) return onbuilderror(err)
uploadFiles(pbFiles.map(function (file) { return 'prebuilds/' + file }))
})
} else {
var files = []
eachSeries(opts.prebuild, function (target, next) {
prebuild(opts, target.target, target.runtime, function (err, tarGz) {
if (err) return next(err)
files.push(tarGz)
next()
})
}, function (err) {
if (err) return onbuilderror(err)
if (!fs.existsSync('package.json')) {
log.error('setup', 'No package.json found. Aborting...')
process.exit(1)
}
if (rc.help) {
console.error(fs.readFileSync(path.join(__dirname, 'help.txt'), 'utf-8'))
process.exit(0)
}
log.info('begin', 'Prebuild-install version', prebuildClientVersion)
var opts = Object.assign({}, rc, { pkg: pkg, log: log })
if (napi.isNapiRuntime(rc.runtime)) napi.logUnsupportedVersion(rc.target, log)
var pm = whichPmRuns()
var isNpm = !pm || pm.name === 'npm'
if (!isNpm && /node_modules/.test(process.cwd())) {
// From yarn repository
} else if (opts.force) {
log.warn('install', 'prebuilt binaries enforced with --force!')
log.warn('install', 'prebuilt binaries may be out of date!')
} else if (!(typeof pkg._from === 'string')) {
log.info('install', 'installing standalone, skipping download.')
process.exit(1)
} else if (pkg._from.length > 4 && pkg._from.substr(0, 4) === 'git+') {
log.info('install', 'installing from git repository, skipping download.')
process.exit(1)
} else if (opts.compile === true || opts.prebuild === false) {
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
}
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]
})
}
}
}
if (rc.all === true && !napi.isNapiRuntime(rc.runtime)) {
delete rc.prebuild
rc.prebuild = targets
}
if (rc['upload-all']) {
rc.upload = rc['upload-all']
}
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]
})
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
}
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]
})
}
}
}