| 1 | const path = require('path')
|
|---|
| 2 | const minimist = require('minimist')
|
|---|
| 3 | const getAbi = require('node-abi').getAbi
|
|---|
| 4 | const detectLibc = require('detect-libc')
|
|---|
| 5 | const napi = require('napi-build-utils')
|
|---|
| 6 |
|
|---|
| 7 | const env = process.env
|
|---|
| 8 |
|
|---|
| 9 | const libc = env.LIBC || process.env.npm_config_libc ||
|
|---|
| 10 | (detectLibc.isNonGlibcLinuxSync() && detectLibc.familySync()) || ''
|
|---|
| 11 |
|
|---|
| 12 | // Get the configuration
|
|---|
| 13 | module.exports = function (pkg) {
|
|---|
| 14 | const pkgConf = pkg.config || {}
|
|---|
| 15 | const buildFromSource = env.npm_config_build_from_source
|
|---|
| 16 |
|
|---|
| 17 | const rc = require('rc')('prebuild-install', {
|
|---|
| 18 | target: pkgConf.target || env.npm_config_target || process.versions.node,
|
|---|
| 19 | runtime: pkgConf.runtime || env.npm_config_runtime || 'node',
|
|---|
| 20 | arch: pkgConf.arch || env.npm_config_arch || process.arch,
|
|---|
| 21 | libc: libc,
|
|---|
| 22 | platform: env.npm_config_platform || process.platform,
|
|---|
| 23 | debug: env.npm_config_debug === 'true',
|
|---|
| 24 | force: false,
|
|---|
| 25 | verbose: env.npm_config_verbose === 'true',
|
|---|
| 26 | buildFromSource: buildFromSource === pkg.name || buildFromSource === 'true',
|
|---|
| 27 | path: '.',
|
|---|
| 28 | proxy: env.npm_config_proxy || env.http_proxy || env.HTTP_PROXY,
|
|---|
| 29 | 'https-proxy': env.npm_config_https_proxy || env.https_proxy || env.HTTPS_PROXY,
|
|---|
| 30 | 'local-address': env.npm_config_local_address,
|
|---|
| 31 | 'local-prebuilds': 'prebuilds',
|
|---|
| 32 | 'tag-prefix': 'v',
|
|---|
| 33 | download: env.npm_config_download
|
|---|
| 34 | }, minimist(process.argv, {
|
|---|
| 35 | alias: {
|
|---|
| 36 | target: 't',
|
|---|
| 37 | runtime: 'r',
|
|---|
| 38 | help: 'h',
|
|---|
| 39 | arch: 'a',
|
|---|
| 40 | path: 'p',
|
|---|
| 41 | version: 'v',
|
|---|
| 42 | download: 'd',
|
|---|
| 43 | buildFromSource: 'build-from-source',
|
|---|
| 44 | token: 'T'
|
|---|
| 45 | }
|
|---|
| 46 | }))
|
|---|
| 47 |
|
|---|
| 48 | rc.path = path.resolve(rc.path === true ? '.' : rc.path || '.')
|
|---|
| 49 |
|
|---|
| 50 | if (napi.isNapiRuntime(rc.runtime) && rc.target === process.versions.node) {
|
|---|
| 51 | rc.target = napi.getBestNapiBuildVersion()
|
|---|
| 52 | }
|
|---|
| 53 |
|
|---|
| 54 | rc.abi = napi.isNapiRuntime(rc.runtime) ? rc.target : getAbi(rc.target, rc.runtime)
|
|---|
| 55 |
|
|---|
| 56 | rc.libc = rc.platform !== 'linux' || rc.libc === detectLibc.GLIBC ? '' : rc.libc
|
|---|
| 57 |
|
|---|
| 58 | return rc
|
|---|
| 59 | }
|
|---|
| 60 |
|
|---|
| 61 | // Print the configuration values when executed standalone for testing purposses
|
|---|
| 62 | if (!module.parent) {
|
|---|
| 63 | console.log(JSON.stringify(module.exports({}), null, 2))
|
|---|
| 64 | }
|
|---|