diff --git a/lib/make-spawn-args.js b/lib/make-spawn-args.js index 8a32d71..42224a6 100644 --- a/lib/make-spawn-args.js +++ b/lib/make-spawn-args.js @@ -1,7 +1,15 @@ /* eslint camelcase: "off" */ const setPATH = require('./set-path.js') const { resolve } = require('path') -const npm_config_node_gyp = require.resolve('node-gyp/bin/node-gyp.js') +let npm_config_node_gyp +try { + /* istanbul ignore next */ + if (typeof require === 'function' && typeof require.resolve === 'function') { + npm_config_node_gyp = require.resolve('node-gyp/bin/node-gyp.js') + } +} catch (er) { + /* istanbul ignore next */ +} const makeSpawnArgs = options => { const { @@ -19,12 +27,15 @@ const makeSpawnArgs = options => { const spawnEnv = setPATH(path, binPaths, { // we need to at least save the PATH environment var ...process.env, - ...env, npm_package_json: resolve(path, 'package.json'), npm_lifecycle_event: event, npm_lifecycle_script: cmd, - npm_config_node_gyp, + ...env, }) + /* istanbul ignore next */ + if (typeof npm_config_node_gyp === 'string') { + spawnEnv.npm_config_node_gyp = npm_config_node_gyp + } const spawnOpts = { env: spawnEnv,