diff --git a/packages/constraint-solver/constraint-solver.js b/packages/constraint-solver/constraint-solver.js index 7632b9fc73..4865352387 100644 --- a/packages/constraint-solver/constraint-solver.js +++ b/packages/constraint-solver/constraint-solver.js @@ -27,13 +27,26 @@ CS.PackagesResolver = function (catalog, options) { // included versions are the only pre-releases that are allowed to match // constraints that don't specifically name them during the "try not to // use unanticipated pre-releases" pass +// - missingPreviousVersionIsError - throw an error if a package version in +// previousSolution is not found in the catalog CS.PackagesResolver.prototype.resolve = function (dependencies, constraints, options) { var self = this; + options = options || {}; var input = new CS.Input(dependencies, constraints, self.catalogCache, - options); + _.pick(options, 'upgrade', 'anticipatedPrereleases', + 'previousSolution')); input.loadFromCatalog(self.catalogLoader); + if (options.previousSolution && options.missingPreviousVersionIsError) { + _.each(options.previousSolution, function (version, package) { + if (! input.catalogCache.hasPackageVersion(package, version)) { + CS.throwConstraintSolverError( + "Package version not in catalog: " + package + " " + version); + } + }); + } + return CS.PackagesResolver._resolveWithInput(input, this._options.nudge); }; diff --git a/tools/project-context.js b/tools/project-context.js index ac417a1d28..ff7729e46d 100644 --- a/tools/project-context.js +++ b/tools/project-context.js @@ -391,6 +391,8 @@ _.extend(ProjectContext.prototype, { var anticipatedPrereleases = self._getAnticipatedPrereleases( depsAndConstraints.constraints, cachedVersions); + var isFirstAttempt = true; + // Nothing before this point looked in the official or project catalog! // However, the resolver does, so it gets run in the retry context. catalog.runAndRetryWithRefreshIfHelpful(function () { @@ -399,7 +401,8 @@ _.extend(ProjectContext.prototype, { var resolveOptions = { previousSolution: cachedVersions, - anticipatedPrereleases: anticipatedPrereleases + anticipatedPrereleases: anticipatedPrereleases, + missingPreviousVersionIsError: isFirstAttempt }; if (self._upgradePackageNames) resolveOptions.upgrade = self._upgradePackageNames; @@ -432,6 +435,8 @@ _.extend(ProjectContext.prototype, { self._completedStage = STAGE.RESOLVE_CONSTRAINTS; }); + + isFirstAttempt = false; }); },