Skip to content

Commit

Permalink
Support custom binary hosting mirror
Browse files Browse the repository at this point in the history
Like we setup a mirror site for node-inspector at
https://npm.taobao.org/mirrors/node-inspector/

These mirrors try to help people download binary files from China.
  • Loading branch information
fengmk2 committed Jul 21, 2015
1 parent ff72f35 commit 61ccff7
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
6 changes: 5 additions & 1 deletion lib/util/versioning.js
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,11 @@ module.exports.evaluate = function(package_json,options) {
module_main: package_json.main,
toolset : options.toolset || '' // address https://github.com/mapbox/node-pre-gyp/issues/119
};
opts.host = fix_slashes(eval_template(package_json.binary.host,opts));
// 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=http://npm.taobao.org/mirrors/node-inspector/
var host = process.env['npm_config_' + opts.module_name + '_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);
// now we resolve the module_path to ensure it is absolute so that binding.gyp variables work predictably
if (options.module_root) {
Expand Down
22 changes: 21 additions & 1 deletion test/versioning.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ describe('versioning', function() {
"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://node-pre-gyp-tests.s3-us-west-1.amazonaws.com"
"host" : "https://node-pre-gyp-tests.s3-us-west-1.amazonaws.com"
}
};
var opts = versioning.evaluate(mock_package_json, {});
Expand Down Expand Up @@ -64,4 +64,24 @@ describe('versioning', function() {
assert.equal(versioning.get_runtime_abi('node-webkit','0.10.5'),versioning.get_node_webkit_abi('node-webkit','0.10.5'));
});

it('should detect custom binary host from env', function() {
var 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://node-pre-gyp-tests.s3-us-west-1.amazonaws.com"
}
};
// mock npm_config_test_binary_host_mirror env
process.env['npm_config_test_binary_host_mirror'] = "http://npm.taobao.org/mirrors/node-inspector/";
var opts = versioning.evaluate(mock_package_json, {});
assert.equal(opts.host,"http://npm.taobao.org/mirrors/node-inspector/");
delete process.env['npm_config_test_binary_host_mirror'];
});

});

0 comments on commit 61ccff7

Please sign in to comment.