diff --git a/lib/create-config-gypi.js b/lib/create-config-gypi.js index dbcb8b485c..ced4911502 100644 --- a/lib/create-config-gypi.js +++ b/lib/create-config-gypi.js @@ -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') diff --git a/lib/node-gyp.js b/lib/node-gyp.js index 0f11185641..e492ec1026 100644 --- a/lib/node-gyp.js +++ b/lib/node-gyp.js @@ -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 } } diff --git a/test/test-options.js b/test/test-options.js index b2ac62c874..8a634f0e09 100644 --- a/test/test-options.js +++ b/test/test-options.js @@ -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') +})