npminstall
Advanced tools
Comparing version 1.2.5 to 1.3.0
@@ -28,2 +28,3 @@ #!/usr/bin/env node | ||
const config = require('../lib/config'); | ||
const get = require('../lib/get'); | ||
const installLocal = require('..').installLocal; | ||
@@ -143,2 +144,17 @@ const installGlobal = require('..').installGlobal; | ||
co(function*() { | ||
let binaryMirrors = {}; | ||
if (inChina) { | ||
const binaryMirrorUrl = registry + '/binary-mirror-config/latest'; | ||
try { | ||
const res = yield get(binaryMirrorUrl, { | ||
dataType: 'json', | ||
followRedirect: true, | ||
}); | ||
binaryMirrors = res.data.mirrors.china; | ||
} catch (err) { | ||
debug('Get %s error: %s', binaryMirrorUrl, err); | ||
} | ||
} | ||
const config = { | ||
@@ -151,2 +167,3 @@ root, | ||
env, | ||
binaryMirrors, | ||
}; | ||
@@ -153,0 +170,0 @@ config.strictSSL = getStrictSSL(); |
1.3.0 / 2016-03-09 | ||
================== | ||
* refactor: Get mirrors from https://github.com/cnpm/binary-mirror-config/blob/master/package.json#L43 | ||
* feat: Auto set China mirror for prebuild binary packages | ||
1.2.5 / 2016-03-07 | ||
@@ -3,0 +9,0 @@ ================== |
@@ -97,6 +97,21 @@ /** | ||
yield utils.addMetaToJSONFile(path.join(ungzipDir, 'package.json'), { | ||
const pkgMeta = { | ||
_from: `${pkg.name}@${pkg.version}`, | ||
_resolved: pkg.dist.tarball, | ||
}); | ||
}; | ||
const binaryMirror = options.binaryMirrors[pkg.name]; | ||
if (binaryMirror && pkg.scripts && pkg.scripts.install) { | ||
// leveldown and sqlite3 | ||
if (/prebuild \-\-install/.test(pkg.scripts.install) || | ||
/prebuild \-\-download/.test(pkg.scripts.install) || | ||
/node\-pre\-gyp install/.test(pkg.scripts.install)) { | ||
const newBinary = pkg.binary || {}; | ||
for (const key in binaryMirror) { | ||
newBinary[key] = binaryMirror[key]; | ||
} | ||
pkgMeta.binary = newBinary; | ||
options.console.info(`[${pkg.name}@${pkg.version}] download from binary mirror: %j`, newBinary); | ||
} | ||
} | ||
yield utils.addMetaToJSONFile(path.join(ungzipDir, 'package.json'), pkgMeta); | ||
@@ -103,0 +118,0 @@ options.cache[key].done = true; |
@@ -39,3 +39,5 @@ /** | ||
options.headers['User-Agent'] = USER_AGENT; | ||
options.rejectUnauthorized = globalOptions.strictSSL; | ||
if (globalOptions) { | ||
options.rejectUnauthorized = globalOptions.strictSSL; | ||
} | ||
const result = yield _get(url, options, 5); | ||
@@ -42,0 +44,0 @@ debug('GET %s, headers: %j from %j', result.status, result.headers, url); |
@@ -49,2 +49,3 @@ /** | ||
* if `production` mode enable, `cacheDir` will be disable. | ||
* - {Object} [binaryMirrors] - binary mirror config, default is `{}` | ||
*/ | ||
@@ -88,2 +89,3 @@ module.exports = function*(options) { | ||
options.gitPackages = 0; | ||
options.binaryMirrors = options.binaryMirrors || {}; | ||
if (options.production) { | ||
@@ -90,0 +92,0 @@ options.cacheDir = ''; |
{ | ||
"name": "npminstall", | ||
"version": "1.2.5", | ||
"version": "1.3.0", | ||
"description": "Let npm install fast and easy", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
67449
1653