From 4a4680b5d2522b89d187bfcccb982edfa243ba3f Mon Sep 17 00:00:00 2001 From: David Greenspan Date: Mon, 30 Mar 2015 16:58:21 -0700 Subject: [PATCH] Exclude published package from previousSolution When you `meteor publish` a package (not from an app), a ProjectContext is created that gets the Version Solver "previousSolution" from the .versions file in the project directory. From the point of view of the Version Solver, the package itself is a root dependency, so if the version changes from last time, you may be asked to pass --allow-incompatible-update! That isn't right. However, the ProjectContext created by `meteor publish` doesn't know it is created for a particular package. But it does have the package marked as "explicitly added." So for now, the simplest thing to do is to alter the input to the Version Solver based on the value of explicitlyAddedLocalPackageDirs. Oh, another wrinkle here is that we don't actually know the name of the package we're publishing when we create the PackageContext, so it can't be an option. Example of a failing self-test that now passes: 'packages with organizations' --- tools/project-context.js | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/tools/project-context.js b/tools/project-context.js index d1c68da066..8090d8a784 100644 --- a/tools/project-context.js +++ b/tools/project-context.js @@ -168,6 +168,16 @@ _.extend(ProjectContext.prototype, { // Initialized by initializeCatalog. self.projectCatalog = null; self.localCatalog = null; + // Once the catalog is read and the names of the "explicitly + // added" packages are determined, they will be listed here. + // (See explicitlyAddedLocalPackageDirs.) + // "Explicitly added" packages are typically present in non-app + // projects, like the one created by `meteor publish`. This list + // is used to avoid pinning such packages to their previous + // versions when we run the version solver, which prevents an + // error telling you to pass `--allow-incompatible-update` when + // you publish your package after bumping the major version. + self.explicitlyAddedPackageNames = null; // Initialized by _resolveConstraints. self.packageMap = null; @@ -408,6 +418,13 @@ _.extend(ProjectContext.prototype, { var anticipatedPrereleases = self._getAnticipatedPrereleases( depsAndConstraints.constraints, cachedVersions); + if (self.explicitlyAddedPackageNames.length) { + cachedVersions = _.clone(cachedVersions); + _.each(self.explicitlyAddedPackageNames, function (p) { + delete cachedVersions[p]; + }); + } + var resolverRunCount = 0; // Nothing before this point looked in the official or project catalog! @@ -531,6 +548,15 @@ _.extend(ProjectContext.prototype, { return; } + self.explicitlyAddedPackageNames = []; + _.each(self._explicitlyAddedLocalPackageDirs, function (dir) { + var localVersionRecord = + self.localCatalog.getVersionBySourceRoot(dir); + if (localVersionRecord) { + self.explicitlyAddedPackageNames.push(localVersionRecord.packageName); + } + }); + self._completedStage = STAGE.INITIALIZE_CATALOG; } ); @@ -688,6 +714,7 @@ _.extend(ProjectContext.prototype, { (release.current.isCheckout() && self.releaseFile.isCheckout()) || (! release.current.isCheckout() && release.current.name === self.releaseFile.fullReleaseName))) { + self.packageMapFile.write(self.packageMap); }