Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/util/versioning.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
19 changes: 19 additions & 0 deletions test/versioning.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});