From 290cdc1e8a253aa4e11658f376b692febf4b1dbb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=99=BD=E4=B8=80=E6=A2=93?= Date: Tue, 7 Apr 2026 16:37:50 +0800 Subject: [PATCH 1/2] Enhance binary host mirror configuration handling --- lib/util/versioning.js | 3 ++- test/versioning.test.js | 20 ++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/lib/util/versioning.js b/lib/util/versioning.js index b69b367e..3dd4baa3 100644 --- a/lib/util/versioning.js +++ b/lib/util/versioning.js @@ -314,7 +314,8 @@ module.exports.evaluate = function(package_json, options, napi_build_version) { // e.g.: https://github.com/node-inspector/v8-profiler/blob/master/package.json#L25 // > npm install v8-profiler --profiler_binary_host_mirror=https://registry.npmmirror.com/node-inspector/ const validModuleName = opts.module_name.replace('-', '_'); - const host = process.env['npm_config_' + validModuleName + '_binary_host_mirror'] || package_json.binary.host; + const envNameSuffix = validModuleName + '_binary_host_mirror'; + const host = process.env['npm_config_' + envNameSuffix] || process.env[envNameSuffix.toUpperCase()] || package_json.binary.host; opts.host = fix_slashes(eval_template(host, opts)); opts.module_path = eval_template(package_json.binary.module_path, opts); // now we resolve the module_path to ensure it is absolute so that binding.gyp variables work predictably diff --git a/test/versioning.test.js b/test/versioning.test.js index 77e3b75f..7544ee58 100644 --- a/test/versioning.test.js +++ b/test/versioning.test.js @@ -181,6 +181,26 @@ test('should detect custom binary host from env', (t) => { t.end(); }); +test('should detect custom binary host from uppercase env', (t) => { + const mock_package_json = { + 'name': 'test', + 'main': 'test.js', + 'version': '0.1.0', + 'binary': { + 'module_name': 'test', + 'module_path': './lib/binding/{configuration}/{toolset}/{name}', + 'remote_path': './{name}/v{version}/{configuration}/{version}/{toolset}/', + 'package_name': '{module_name}-v{major}.{minor}.{patch}-{prerelease}+{build}-{toolset}-{node_abi}-{platform}-{arch}.tar.gz', + 'host': 'https://some-bucket.s3.us-east-1.amazonaws.com' + } + }; + process.env.TEST_BINARY_HOST_MIRROR = 'https://registry.npmmirror.com/node-inspector/'; + const opts = versioning.evaluate(mock_package_json, {}); + t.equal(opts.host, 'https://registry.npmmirror.com/node-inspector/'); + delete process.env.TEST_BINARY_HOST_MIRROR; + t.end(); +}); + test('should detect libc', (t) => { const mock_package_json = { 'name': 'test', From 83685cba71fae5785acf389b4487fded0de2f768 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=99=BD=E4=B8=80=E6=A2=93?= Date: Tue, 21 Apr 2026 20:03:05 +0800 Subject: [PATCH 2/2] Replace all - in module_name to _ Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- lib/util/versioning.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/util/versioning.js b/lib/util/versioning.js index 3dd4baa3..de86282c 100644 --- a/lib/util/versioning.js +++ b/lib/util/versioning.js @@ -313,7 +313,7 @@ module.exports.evaluate = function(package_json, options, napi_build_version) { // support host mirror with npm config `--{module_name}_binary_host_mirror` // e.g.: https://github.com/node-inspector/v8-profiler/blob/master/package.json#L25 // > npm install v8-profiler --profiler_binary_host_mirror=https://registry.npmmirror.com/node-inspector/ - const validModuleName = opts.module_name.replace('-', '_'); + const validModuleName = opts.module_name.replace(/-/g, '_'); const envNameSuffix = validModuleName + '_binary_host_mirror'; const host = process.env['npm_config_' + envNameSuffix] || process.env[envNameSuffix.toUpperCase()] || package_json.binary.host; opts.host = fix_slashes(eval_template(host, opts));