Skip to content

Commit eef4eef

Browse files
zcbenzrvagg
authored andcommitted
fix: _ in npm_config_ env variables
1 parent a32a9aa commit eef4eef

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

lib/create-config-gypi.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ async function getBaseConfigGypi ({ gyp, nodeDir }) {
1919
// try reading $nodeDir/include/node/config.gypi first when:
2020
// 1. --dist-url or --nodedir is specified
2121
// 2. and --force-process-config is not specified
22-
const shouldReadConfigGypi = (gyp.opts.nodedir || gyp.opts['dist-url']) && !gyp.opts['force-process-config']
22+
const useCustomHeaders = gyp.opts.nodedir || gyp.opts.disturl || gyp.opts['dist-url']
23+
const shouldReadConfigGypi = useCustomHeaders && !gyp.opts['force-process-config']
2324
if (shouldReadConfigGypi && nodeDir) {
2425
try {
2526
const baseConfigGypiPath = path.resolve(nodeDir, 'include/node/config.gypi')

lib/node-gyp.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,10 @@ proto.parseArgv = function parseOpts (argv) {
149149
// gyp@741b7f1 enters an infinite loop when it encounters
150150
// zero-length options so ensure those don't get through.
151151
if (name) {
152+
// convert names like force_process_config to force-process-config
153+
if (name.includes('_')) {
154+
name = name.replace(/_/g, '-')
155+
}
152156
this.opts[name] = val
153157
}
154158
}

test/test-options.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,14 @@ test('options in environment', (t) => {
2929

3030
t.deepEqual(Object.keys(g.opts).sort(), keys.sort())
3131
})
32+
33+
test('options with spaces in environment', (t) => {
34+
t.plan(1)
35+
36+
process.env.npm_config_force_process_config = 'true'
37+
38+
const g = gyp()
39+
g.parseArgv(['rebuild']) // Also sets opts.argv.
40+
41+
t.equal(g.opts['force-process-config'], 'true')
42+
})

0 commit comments

Comments
 (0)