Skip to content

Commit c936a18

Browse files
committed
fix: defensive autolocation of node-gyp in make-spawn-args
prevents runtime error in environments where `require.resolve` is not available Fall back to any existing `npm_config_node_gyp` provided by environment
1 parent ee92273 commit c936a18

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

lib/make-spawn-args.js

+13-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,15 @@
11
/* eslint camelcase: "off" */
22
const setPATH = require('./set-path.js')
33
const { resolve } = require('path')
4-
const npm_config_node_gyp = require.resolve('node-gyp/bin/node-gyp.js')
4+
let npm_config_node_gyp
5+
try {
6+
/* istanbul ignore next */
7+
if (typeof require === 'function' && typeof require.resolve === 'function') {
8+
npm_config_node_gyp = require.resolve('node-gyp/bin/node-gyp.js')
9+
}
10+
} catch (er) {
11+
/* istanbul ignore next */
12+
}
513

614
const makeSpawnArgs = options => {
715
const {
@@ -23,8 +31,11 @@ const makeSpawnArgs = options => {
2331
npm_package_json: resolve(path, 'package.json'),
2432
npm_lifecycle_event: event,
2533
npm_lifecycle_script: cmd,
26-
npm_config_node_gyp,
2734
})
35+
/* istanbul ignore next */
36+
if (typeof npm_config_node_gyp === 'string') {
37+
spawnEnv.npm_config_node_gyp = npm_config_node_gyp
38+
}
2839

2940
const spawnOpts = {
3041
env: spawnEnv,

0 commit comments

Comments
 (0)