Skip to content

Commit

Permalink
Merge pull request #2277 from zenorbi/0.17
Browse files Browse the repository at this point in the history
trying to fix flickering peer dependency range issue
  • Loading branch information
guybedford authored Mar 12, 2018
2 parents 10b410b + 1442853 commit ae092e1
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
19 changes: 16 additions & 3 deletions lib/install.js
Original file line number Diff line number Diff line change
Expand Up @@ -499,12 +499,25 @@ function install(name, target, options, seen) {
options.peer = true;
}

function replaceDependency(dependencies, name, newPackage) {
var existingDependency = dependencies[name];
if (!existingDependency) { //No existing dependency
dependencies[name] = newPackage;
} else { //Enforce maximum compatibility version
var existingMinVersion = semver.rangeToMinSemver(existingDependency.version);
var matches = semver.match(newPackage.version, existingMinVersion);
if (!matches) { //Need to update because current min version would not match the criteria set by this package
dependencies[name] = newPackage;
}
}
}

if (options.peer)
config.pjson.peerDependencies[name] = primaryRanges[name];
replaceDependency(config.pjson.peerDependencies, name, primaryRanges[name]);
else if (options.dev)
config.pjson.devDependencies[name] = primaryRanges[name];
replaceDependency(config.pjson.devDependencies, name, primaryRanges[name]);
else
config.pjson.dependencies[name] = primaryRanges[name];
replaceDependency(config.pjson.dependencies, name, primaryRanges[name]);

// remove any alternative installs of this dependency
if (!options.dev)
Expand Down
5 changes: 5 additions & 0 deletions lib/semver.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,11 @@ function parseRange(range) {

exports.semverRegEx = semverRegEx;

exports.rangeToMinSemver = function(r) {
var parsed = parseRange(r).version;
return parsed.major + '.' + parsed.minor + '.' + parsed.patch;
};

exports.compare = function(v1, v2) {
return semverCompareParsed(parseSemver(v1), parseSemver(v2));
};
Expand Down

0 comments on commit ae092e1

Please sign in to comment.