make-spawn-args.js 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. /* eslint camelcase: "off" */
  2. const setPATH = require('./set-path.js')
  3. const { resolve } = require('path')
  4. let npm_config_node_gyp
  5. const makeSpawnArgs = options => {
  6. const {
  7. args,
  8. binPaths,
  9. cmd,
  10. env,
  11. event,
  12. nodeGyp,
  13. path,
  14. scriptShell = true,
  15. stdio,
  16. stdioString,
  17. } = options
  18. if (nodeGyp) {
  19. // npm already pulled this from env and passes it in to options
  20. npm_config_node_gyp = nodeGyp
  21. } else if (env.npm_config_node_gyp) {
  22. // legacy mode for standalone user
  23. npm_config_node_gyp = env.npm_config_node_gyp
  24. } else {
  25. // default
  26. npm_config_node_gyp = require.resolve('node-gyp/bin/node-gyp.js')
  27. }
  28. const spawnEnv = setPATH(path, binPaths, {
  29. // we need to at least save the PATH environment var
  30. ...process.env,
  31. ...env,
  32. npm_package_json: resolve(path, 'package.json'),
  33. npm_lifecycle_event: event,
  34. npm_lifecycle_script: cmd,
  35. npm_config_node_gyp,
  36. })
  37. const spawnOpts = {
  38. env: spawnEnv,
  39. stdioString,
  40. stdio,
  41. cwd: path,
  42. shell: scriptShell,
  43. }
  44. return [cmd, args, spawnOpts]
  45. }
  46. module.exports = makeSpawnArgs