From f9c20a1fd86b9321178328d3d231a82f63fa65e7 Mon Sep 17 00:00:00 2001 From: fengmk2 Date: Fri, 11 Mar 2016 20:03:22 +0800 Subject: [PATCH] fix: try to fix the max satisfy version (n.x) in grandfather's deps closes #49 --- lib/get.js | 15 ++++++++++++--- lib/install.js | 21 +++++++++++++++++++++ 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/lib/get.js b/lib/get.js index 8fb0710b..6bdf092f 100644 --- a/lib/get.js +++ b/lib/get.js @@ -54,15 +54,24 @@ function* get(url, options, globalOptions) { return result; } +const RETRY_CODES = [ + 'ETIMEDOUT', + 'ECONNRESET', + 'ENOTFOUND', +]; + function* _get(url, options, retry) { try { return yield urllib.request(url, options); } catch (err) { retry--; - if ((err.code === 'ECONNRESET' || err.code === 'ENOTFOUND' || err.message.indexOf('socket hang up') >= 0) && retry > 0) { - debug('retry GET %s, retry left %s', url, retry); - return yield _get(url, options, retry); + if (retry > 0) { + if (RETRY_CODES.indexOf(err.code) >= 0 || err.message.indexOf('socket hang up') >= 0) { + debug('retry GET %s, retry left %s', url, retry); + return yield _get(url, options, retry); + } } + throw err; } } diff --git a/lib/install.js b/lib/install.js index d784f40c..e1624900 100644 --- a/lib/install.js +++ b/lib/install.js @@ -126,6 +126,7 @@ function* _install(parentDir, pkg, options) { // 4. link bin files // 5. link package to node_modules dir + let grandfatherPkg; try { yield preinstall(realPkg, realPkgDir, options); // link bundleDependencies' bin @@ -142,6 +143,26 @@ function* _install(parentDir, pkg, options) { if (bundledDependencies.indexOf(childPkg.name) !== -1) { continue; } + // if version format "n.x", check grandfather's dependencies + if (/^\d+\.x$/.test(childPkg.version)) { + if (!grandfatherPkg) { + grandfatherPkg = yield utils.readJSON(path.join(parentDir, 'package.json')); + } + const version = grandfatherPkg.dependencies && grandfatherPkg.dependencies[childPkg.name]; + if (version && /^[~\^]\d+\.\d+\.\d+$/.test(version)) { + if (semver.satisfies(version.substring(1), childPkg.version)) { + options.console.info('[%s] use grandfather(%s@%s)\'s dependencies version: %j instead of %j, parent: %s@%s', + chalk.yellow(`${childPkg.name}@${childPkg.version}`), + grandfatherPkg.name, + grandfatherPkg.version, + version, + childPkg.version, + realPkg.name, + realPkg.version); + childPkg.version = version; + } + } + } tasks.push(install(realPkgDir, childPkg, options)); } yield tasks;