diff --git a/lib/util/versioning.js b/lib/util/versioning.js index b69b367e..73307946 100644 --- a/lib/util/versioning.js +++ b/lib/util/versioning.js @@ -313,7 +313,8 @@ 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('-', '_'); + // A module name can contain more than one dash. replace() stops at the first. + const validModuleName = opts.module_name.replace(/-/g, '_'); const host = process.env['npm_config_' + validModuleName + '_binary_host_mirror'] || package_json.binary.host; opts.host = fix_slashes(eval_template(host, opts)); opts.module_path = eval_template(package_json.binary.module_path, opts); diff --git a/test/versioning.test.js b/test/versioning.test.js index 77e3b75f..29110b97 100644 --- a/test/versioning.test.js +++ b/test/versioning.test.js @@ -363,3 +363,22 @@ test('should replace "-" with "_" in custom binary host', (t) => { t.end(); }); +test('should replace every "-" with "_" in custom binary host', (t) => { + const mock_package_json = { + name: 'test', + main: 'test.js', + version: '0.1.0', + binary: { + module_name: 'confluent-kafka-javascript', + module_path: 'build/Release', + host: 'https://example.com/official/' + } + }; + + process.env.npm_config_confluent_kafka_javascript_binary_host_mirror = 'https://registry.example.com/mirror/'; + const opts = versioning.evaluate(mock_package_json, {}); + t.equal(opts.host, 'https://registry.example.com/mirror/'); + delete process.env.npm_config_confluent_kafka_javascript_binary_host_mirror; + t.end(); +}); +