Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: try to fix the max satisfy version (n.x) in grandfather's deps #50

Merged
merged 1 commit into from
Mar 11, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个逻辑怎么看怎么恶心。。

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

n.x 没关系吧,其他写法也有一样的问题。本质还是顺序问题。优先安装父级的相同依赖模块版本。

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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