Skip to content

Commit

Permalink
Merge pull request #50 from cnpm/try-to-use-exists-version
Browse files Browse the repository at this point in the history
fix: try to fix the max satisfy version (n.x) in grandfather's deps
  • Loading branch information
fengmk2 committed Mar 11, 2016
2 parents f5f78f2 + f9c20a1 commit 302ab3a
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 3 deletions.
15 changes: 12 additions & 3 deletions lib/get.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
21 changes: 21 additions & 0 deletions lib/install.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
Expand Down

0 comments on commit 302ab3a

Please sign in to comment.