Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: _ in npm_config_ env variables #2547

Merged
merged 1 commit into from
Feb 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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')
})