nodejs / node-gyp

Node.js native addon build tool
MIT License
9.83k stars 1.78k forks source link

dist-url option in environment variable not working as expected #2250

Open gera2ld opened 3 years ago

gera2ld commented 3 years ago

The document says:

Use the form npm_config_OPTION_NAME for any of the command options listed above (dashes in option names should be replaced by underscores).

But dist-url does not work this way:

export npm_config_dist_url=xxx

because what we get from the above is gyp.opts.dist_url but the code is using other forms:

https://github.com/nodejs/node-gyp/blob/66c0f0446749caa591ad841cd029b6d5b5c8da42/lib/process-release.js#L22

However it works when keeping or removing the dash:

# environment variable with dash is not valid to export
$ env npm_config_dist-url=xxx node-gyp

Should dist_url also be supported as described in the document? Thanks.

watchingfun commented 10 months ago

in node-gyp/lib/process-release.js

function processRelease (argv, gyp, defaultVersion, defaultRelease) {
  var version = (semver.valid(argv[0]) && argv[0]) || gyp.opts.target || defaultVersion
  var versionSemver = semver.parse(version)
  var overrideDistUrl = gyp.opts['dist-url'] || gyp.opts.disturl
  console.log('gyp.opts',gyp.opts) // print opts
  var isDefaultVersion
  var isNamedForLegacyIojs

Log output:

gyp.opts {
  debug: false,
  argv: {
    remain: [ 'rebuild' ],
    cooked: [ 'rebuild', '--no-debug' ],
    original: [ 'rebuild', '--release' ]
  },
  cache: 'D:\\ScoopApps\\persist\\nodejs-lts\\cache',
  dist_url: 'https://electronjs.org/headers',
  electron_mirror: 'https://npmmirror.com/mirrors/electron/',
  globalconfig: 'F:\\ScoopApps\\persist\\nodejs-lts\\bin\\etc\\npmrc',
  global_prefix: 'F:\\ScoopApps\\persist\\nodejs-lts\\bin',
  init_module: 'C:\\Users\\watchingfun\\.npm-init.js',
  local_prefix: 'G:\\work-space\\Joi\\node_modules\\better-sqlite3',
  metrics_registry: 'https://registry.npmmirror.com/',
  msbuild_path: 'F:\\Program Files\\Microsoft Visual Studio\\2022\\Community\\MSBuild\\Current\\Bin\\MSBuild.exe',
  msvs_version: '2022',
  node_gyp: 'F:\\ScoopApps\\persist\\nodejs-lts\\bin\\node_modules\\npm\\node_modules\\node-gyp\\bin\\node-gyp.js',
  noproxy: '',
  prefix: 'F:\\ScoopApps\\persist\\nodejs-lts\\bin',
  proxy: 'http://127.0.0.1:1081/',
  registry: 'https://registry.npmmirror.com/',
  target: '26.1.0',
  userconfig: 'C:\\Users\\watchingfun\\.npmrc',
  user_agent: 'npm/8.5.1 node/v18.18.0 win32 x64 workspaces/false',
  ensure: true
}

gyp http GET https://nodejs.org/dist/v26.1.0/node-v26.1.0-headers.tar.gz

use --dist-url in https://github.com/electron/electron/blob/v26.1.0/docs/tutorial/using-native-node-modules.md#manually-building-for-electron example

This processRelease function prints dist_url

To avoid this problem, I can only use --disturl when passing command line arguments,

i use node-gyp v9.4.0

watchingfun commented 10 months ago

in node-gyp/lib/process-release.js

function processRelease (argv, gyp, defaultVersion, defaultRelease) {
  var version = (semver.valid(argv[0]) && argv[0]) || gyp.opts.target || defaultVersion
  var versionSemver = semver.parse(version)
  var overrideDistUrl = gyp.opts['dist-url'] || gyp.opts.disturl
  console.log('gyp.opts',gyp.opts) // print opts
  var isDefaultVersion
  var isNamedForLegacyIojs

Log output:

gyp.opts {
  debug: false,
  argv: {
    remain: [ 'rebuild' ],
    cooked: [ 'rebuild', '--no-debug' ],
    original: [ 'rebuild', '--release' ]
  },
  cache: 'D:\\ScoopApps\\persist\\nodejs-lts\\cache',
  dist_url: 'https://electronjs.org/headers',
  electron_mirror: 'https://npmmirror.com/mirrors/electron/',
  globalconfig: 'F:\\ScoopApps\\persist\\nodejs-lts\\bin\\etc\\npmrc',
  global_prefix: 'F:\\ScoopApps\\persist\\nodejs-lts\\bin',
  init_module: 'C:\\Users\\watchingfun\\.npm-init.js',
  local_prefix: 'G:\\work-space\\Joi\\node_modules\\better-sqlite3',
  metrics_registry: 'https://registry.npmmirror.com/',
  msbuild_path: 'F:\\Program Files\\Microsoft Visual Studio\\2022\\Community\\MSBuild\\Current\\Bin\\MSBuild.exe',
  msvs_version: '2022',
  node_gyp: 'F:\\ScoopApps\\persist\\nodejs-lts\\bin\\node_modules\\npm\\node_modules\\node-gyp\\bin\\node-gyp.js',
  noproxy: '',
  prefix: 'F:\\ScoopApps\\persist\\nodejs-lts\\bin',
  proxy: 'http://127.0.0.1:1081/',
  registry: 'https://registry.npmmirror.com/',
  target: '26.1.0',
  userconfig: 'C:\\Users\\watchingfun\\.npmrc',
  user_agent: 'npm/8.5.1 node/v18.18.0 win32 x64 workspaces/false',
  ensure: true
}

gyp http GET https://nodejs.org/dist/v26.1.0/node-v26.1.0-headers.tar.gz

use --dist-url in https://github.com/electron/electron/blob/v26.1.0/docs/tutorial/using-native-node-modules.md#manually-building-for-electron example

This processRelease function prints dist_url

To avoid this problem, I can only use --disturl when passing command line arguments,

i use node-gyp v9.4.0

all right, my bad, i update npm Work it out