Skip to content

Commit

Permalink
fix: _ in npm_config_ env variables
Browse files Browse the repository at this point in the history
  • Loading branch information
zcbenz authored and rvagg committed Feb 15, 2022
1 parent a32a9aa commit eef4eef
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/create-config-gypi.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ async function getBaseConfigGypi ({ gyp, nodeDir }) {
// try reading $nodeDir/include/node/config.gypi first when:
// 1. --dist-url or --nodedir is specified
// 2. and --force-process-config is not specified
const shouldReadConfigGypi = (gyp.opts.nodedir || gyp.opts['dist-url']) && !gyp.opts['force-process-config']
const useCustomHeaders = gyp.opts.nodedir || gyp.opts.disturl || gyp.opts['dist-url']
const shouldReadConfigGypi = useCustomHeaders && !gyp.opts['force-process-config']
if (shouldReadConfigGypi && nodeDir) {
try {
const baseConfigGypiPath = path.resolve(nodeDir, 'include/node/config.gypi')
Expand Down
4 changes: 4 additions & 0 deletions lib/node-gyp.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,10 @@ proto.parseArgv = function parseOpts (argv) {
// gyp@741b7f1 enters an infinite loop when it encounters
// zero-length options so ensure those don't get through.
if (name) {
// convert names like force_process_config to force-process-config
if (name.includes('_')) {
name = name.replace(/_/g, '-')
}
this.opts[name] = val
}
}
Expand Down
11 changes: 11 additions & 0 deletions test/test-options.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,14 @@ test('options in environment', (t) => {

t.deepEqual(Object.keys(g.opts).sort(), keys.sort())
})

test('options with spaces in environment', (t) => {
t.plan(1)

process.env.npm_config_force_process_config = 'true'

const g = gyp()
g.parseArgv(['rebuild']) // Also sets opts.argv.

t.equal(g.opts['force-process-config'], 'true')
})

0 comments on commit eef4eef

Please sign in to comment.