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