rc.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. var minimist = require('minimist')
  2. var getAbi = require('node-abi').getAbi
  3. var detectLibc = require('detect-libc')
  4. var napi = require('napi-build-utils')
  5. var env = process.env
  6. var libc = env.LIBC || (detectLibc.isNonGlibcLinux && detectLibc.family) || ''
  7. // Get `prebuild-install` arguments that were passed to the `npm` command
  8. if (env.npm_config_argv) {
  9. var npmargs = ['prebuild', 'compile', 'build-from-source', 'debug', 'verbose']
  10. try {
  11. var npmArgv = JSON.parse(env.npm_config_argv).cooked
  12. for (var i = 0; i < npmargs.length; ++i) {
  13. if (npmArgv.indexOf('--' + npmargs[i]) !== -1) {
  14. process.argv.push('--' + npmargs[i])
  15. }
  16. if (npmArgv.indexOf('--no-' + npmargs[i]) !== -1) {
  17. process.argv.push('--no-' + npmargs[i])
  18. }
  19. }
  20. if ((i = npmArgv.indexOf('--download')) !== -1) {
  21. process.argv.push(npmArgv[i], npmArgv[i + 1])
  22. }
  23. } catch (e) { }
  24. }
  25. // Get the configuration
  26. module.exports = function (pkg) {
  27. var pkgConf = pkg.config || {}
  28. var sourceBuild = env.npm_config_build_from_source
  29. var buildFromSource = sourceBuild === pkg.name || sourceBuild === 'true'
  30. var rc = require('rc')('prebuild-install', {
  31. target: pkgConf.target || env.npm_config_target || process.versions.node,
  32. runtime: pkgConf.runtime || env.npm_config_runtime || 'node',
  33. arch: pkgConf.arch || env.npm_config_arch || process.arch,
  34. libc: libc,
  35. platform: env.npm_config_platform || process.platform,
  36. debug: false,
  37. force: false,
  38. verbose: false,
  39. prebuild: true,
  40. compile: buildFromSource,
  41. path: '.',
  42. proxy: env.npm_config_proxy || env['HTTP_PROXY'],
  43. 'https-proxy': env.npm_config_https_proxy || env['HTTPS_PROXY'],
  44. 'local-address': env.npm_config_local_address,
  45. 'tag-prefix': 'v'
  46. }, minimist(process.argv, {
  47. alias: {
  48. target: 't',
  49. runtime: 'r',
  50. help: 'h',
  51. arch: 'a',
  52. path: 'p',
  53. version: 'v',
  54. download: 'd',
  55. 'build-from-source': 'compile',
  56. compile: 'c',
  57. token: 'T'
  58. }
  59. }))
  60. if (rc.path === true) {
  61. delete rc.path
  62. }
  63. if (napi.isNapiRuntime(rc.runtime) && rc.target === process.versions.node) {
  64. rc.target = napi.getBestNapiBuildVersion()
  65. }
  66. rc.abi = napi.isNapiRuntime(rc.runtime) ? rc.target : getAbi(rc.target, rc.runtime)
  67. return rc
  68. }
  69. // Print the configuration values when executed standalone for testing purposses
  70. if (!module.parent) {
  71. console.log(JSON.stringify(module.exports({}), null, 2))
  72. }