Put additional 'no-upgrade' constraints only on root deps.

And depending on the `breaking` option, set different type of constraints.
This commit is contained in:
Slava Kim
2014-05-16 11:39:00 -07:00
parent 1fe9b29d35
commit 0760ffbc36

View File

@@ -127,8 +127,18 @@ ConstraintSolver.PackagesResolver.prototype.resolve =
var dc = self._splitDepsToConstraints(dependencies, constraints); var dc = self._splitDepsToConstraints(dependencies, constraints);
// Never allow to downgrade a version of a direct dependency in regards to the
// previous solution.
// Depending on whether the option `breaking` is set or not, allow only
// compatible upgrades or any upgrades.
_.each(options.previousSolution, function (uv) { _.each(options.previousSolution, function (uv) {
dc.constraints.push(new ConstraintSolver.Constraint(uv.name, ">=" + uv.version)); // if not a root dependency, there is no 'no-upgrade' constraint
if (! _.contains(dependencies, uv.name))
return;
var constrType = options.breaking ? ">=" : "";
dc.constraints.push(
new ConstraintSolver.Constraint(uv.name, constrType + uv.version));
}); });
options.rootDependencies = dc.dependencies; options.rootDependencies = dc.dependencies;