make-spawn-args.js 825 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. /* eslint camelcase: "off" */
  2. const setPATH = require('./set-path.js')
  3. const { resolve } = require('path')
  4. const npm_config_node_gyp = require.resolve('node-gyp/bin/node-gyp.js')
  5. const makeSpawnArgs = options => {
  6. const {
  7. event,
  8. path,
  9. scriptShell = true,
  10. binPaths,
  11. env = {},
  12. stdio,
  13. cmd,
  14. args = [],
  15. stdioString,
  16. } = options
  17. const spawnEnv = setPATH(path, binPaths, {
  18. // we need to at least save the PATH environment var
  19. ...process.env,
  20. ...env,
  21. npm_package_json: resolve(path, 'package.json'),
  22. npm_lifecycle_event: event,
  23. npm_lifecycle_script: cmd,
  24. npm_config_node_gyp,
  25. })
  26. const spawnOpts = {
  27. env: spawnEnv,
  28. stdioString,
  29. stdio,
  30. cwd: path,
  31. shell: scriptShell,
  32. }
  33. return [cmd, args, spawnOpts]
  34. }
  35. module.exports = makeSpawnArgs