npminstall
Advanced tools
Comparing version 0.2.0 to 0.3.0
0.3.0 / 2016-02-08 | ||
================== | ||
* fix: add retry when GET request throw ECONNRESET error | ||
* feat: add peerDependencies validate | ||
0.2.0 / 2016-02-06 | ||
@@ -3,0 +9,0 @@ ================== |
@@ -38,3 +38,3 @@ /** | ||
options.headers['User-Agent'] = USER_AGENT; | ||
const result = yield urllib.request(url, options); | ||
const result = yield _get(url, options, 5); | ||
debug('GET %s, headers: %j from %j', result.status, result.headers, url); | ||
@@ -50,1 +50,14 @@ if (result.status < 100 || result.status >= 300) { | ||
} | ||
function* _get(url, options, retry) { | ||
try { | ||
return yield urllib.request(url, options); | ||
} catch (err) { | ||
retry--; | ||
if (err.code === 'ECONNRESET' && retry > 0) { | ||
debug('retry GET %s, retry left %s', url, retry); | ||
return yield _get(url, options, retry); | ||
} | ||
throw err; | ||
} | ||
} |
@@ -15,2 +15,3 @@ /** | ||
const debug = require('debug')('npminstall:index'); | ||
const EventEmitter = require('events'); | ||
@@ -23,2 +24,3 @@ const chalk = require('chalk'); | ||
const parallel = require('co-parallel'); | ||
const semver = require('semver'); | ||
const utils = require('./utils'); | ||
@@ -47,2 +49,7 @@ const postinstall = require('./postinstall'); | ||
// [ | ||
// [ pkg, parentDir ], | ||
// ... | ||
// ] | ||
options.peerDependencies = []; | ||
options.cache = {}; | ||
@@ -82,2 +89,6 @@ assert(options.root && typeof options.root === 'string', 'options.root required and must be string'); | ||
if (options.peerDependencies.length > 0) { | ||
yield options.peerDependencies.map(item => validatePeerDependencies(item[0], item[1])); | ||
} | ||
options.console.info(chalk.green('All packages installed, use %s'), | ||
@@ -97,1 +108,32 @@ ms(Date.now() - options.start)); | ||
} | ||
function* validatePeerDependencies(pkg, parentDir) { | ||
const peerDependencies = pkg.peerDependencies; | ||
const names = Object.keys(peerDependencies); | ||
for (const name of names) { | ||
const expectVersion = peerDependencies[name]; | ||
const realPkg = yield utils.readJSON(path.join(parentDir, 'node_modules', name, 'package.json')); | ||
if (!realPkg.name) { | ||
console.warn('%s [%s] requires a peer of %s but none was installed at %s.', | ||
chalk.yellow.bold('peerDependencies WARNING'), | ||
chalk.red(`${pkg.name}@${pkg.version}`), | ||
chalk.yellow(`${name}@${expectVersion}`), | ||
chalk.yellow(parentDir)); | ||
continue; | ||
} | ||
if (!semver.satisfies(realPkg.version, expectVersion)) { | ||
console.warn('%s [%s] requires a peer of %s but %s was installed at %s.', | ||
chalk.yellow.bold('peerDependencies WARNING'), | ||
chalk.red(`${pkg.name}@${pkg.version}`), | ||
chalk.yellow(`${name}@${expectVersion}`), | ||
chalk.yellow(`${name}@${realPkg.version}`), | ||
chalk.yellow(parentDir)); | ||
continue; | ||
} | ||
debug('[%s] requires a peer of %s and %s was installed at %s', | ||
chalk.green(`${pkg.name}@${pkg.version}`), | ||
chalk.green(`${name}@${expectVersion}`), | ||
chalk.green(`${name}@${realPkg.version}`), | ||
parentDir); | ||
} | ||
} |
@@ -55,3 +55,3 @@ /** | ||
if (!p || p.type === 'remote' || p.type === 'git') { | ||
console.error(chalk.red(`${pkg.name}@${pkg.version}] package is not supported yet, type: ${p.type}`)); | ||
console.error(chalk.red(`[${pkg.name}@${pkg.version}] is not supported yet, type: ${p.type}, parentDir: ${parentDir}`)); | ||
return ''; | ||
@@ -138,2 +138,8 @@ } | ||
yield link(parentDir, realPkg, realPkgDir); | ||
const peerDependencies = realPkg.peerDependencies || {}; | ||
const names = Object.keys(peerDependencies); | ||
if (names.length > 0) { | ||
options.peerDependencies.push([ realPkg, parentDir ]); | ||
} | ||
debug('[%s@%s] installed', realPkg.name, realPkg.version); | ||
@@ -140,0 +146,0 @@ return realPkgDir; |
{ | ||
"name": "npminstall", | ||
"version": "0.2.0", | ||
"version": "0.3.0", | ||
"description": "Let npm install fast and easy", | ||
@@ -35,2 +35,3 @@ "main": "lib/index.js", | ||
"runscript": "~1.0.0", | ||
"semver": "^5.1.0", | ||
"tar": "~2.2.1", | ||
@@ -37,0 +38,0 @@ "urllib": "~2.7.1", |
29480
767
17
+ Addedsemver@^5.1.0