rc.js 2.1 KB

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