npm 6.9.x not passing environment to node-gyp? (regression from 6.4.x)

What I Wanted to Do

Node 10.15 uses npm 6.4.1. With that version, specifying NPM_CONFIG_NODEDIR in the environment causes node-gyp to see the gyp.opts.nodedir, thereby bypassing the node-v*-headers.tar.gz download. This environment variable simulates the --nodedir command line argument to node-gyp.

What Happened Instead

Node 10.16.1 uses npm 6.9.0. With that version, specifying NPM_CONFIG_NODEDIR does not trigger the same code path in node-gyp. The node-gyp version is 3.8.0 in both releases and the code is exactly the same, so this must have something to do with how the environment is passed to the process when npm spawns node-gyp.

Reproduction Steps

In both versions:
$ NPM_CONFIG_NODEDIR=/tmp/doesntexist npm ci

… for any module with a binding.gyp.

Details

Spent a while trying to figure out what this is. Might have something to do with this:

Logs with --verbose do not give any good differential info between the two versions.

Platform Info

$ npm --versions
{ npm: '6.4.1',
  ares: '1.15.0',
  cldr: '33.1',
  http_parser: '2.8.0',
  icu: '62.1',
  modules: '64',
  napi: '3',
  nghttp2: '1.34.0',
  node: '10.15.3',
  openssl: '1.1.0j',
  tz: '2018e',
  unicode: '11.0',
  uv: '1.26.0',
  v8: '6.8.275.32-node.51',
  zlib: '1.2.11' }

{ npm: '6.9.0',
  ares: '1.15.0',
  brotli: '1.0.7',
  cldr: '35.1',
  http_parser: '2.8.0',
  icu: '64.2',
  modules: '64',
  napi: '4',
  nghttp2: '1.34.0',
  node: '10.16.1',
  openssl: '1.1.1c',
  tz: '2019a',
  unicode: '12.1',
  uv: '1.30.1',
  v8: '6.8.275.32-node.54',
  zlib: '1.2.11' }

Related issues:

This will be fixed in the next release. https://github.com/npm/cli/commit/8b43c962498c8e2707527e4fca442d7a4fa51595