Skip to content

Commit

Permalink
Refactor LocalCatalog
Browse files Browse the repository at this point in the history
- Simplify internal data structure to just have one map of name ->
  various data instead of a whole bunch of different unsynchronized data
  structures (most of which were used with frequent O(n) operations).

- Move the getLoadPathForPackage logic which combines local and remote
  packages into LayeredCatalog from LocalCatalog, and delete the
  unnecessary copy in BootstrapCatalogCheckout.

- Rename a bunch of fields to make it explicit which ones contain
  package objects, which ones contain package directories, and which
  ones contain package *search* directories

- Replace random version IDs and a long comment about why random is safe
  with sequential. (I don't think these version IDs are ever used
  anyway.)

- Drop unused "initializing" option to refresh

- Drop redundant call to _recomputeEffectiveLocalPackages in
  addLocalPackage (it is called immediately below by refresh).
  • Loading branch information
glasser committed Oct 31, 2014
1 parent ca33c41 commit b5d2cce
Show file tree
Hide file tree
Showing 9 changed files with 235 additions and 334 deletions.
53 changes: 3 additions & 50 deletions tools/catalog-bootstrap-checkout.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,61 +44,14 @@ _.extend(BootstrapCatalogCheckout.prototype, {
constraint.constraints[0].type !== 'any-reasonable') {
throw Error("Surprising constraint: " + JSON.stringify(constraint));
}
if (!_.has(self.versions, constraint.name)) {
if (!_.has(self.packages, constraint.name)) {
throw Error("Trying to resolve unknown package: " + constraint.name);
}
if (_.isEmpty(self.versions[constraint.name])) {
throw Error("Trying to resolve versionless package: " + constraint.name);
}
if (_.size(self.versions[constraint.name]) > 1) {
throw Error("Too many versions for package: " + constraint.name);
}
ret[constraint.name] = _.keys(self.versions[constraint.name])[0];
ret[constraint.name] =
self.packages[constraint.name].versionRecord.version;
});
return ret;
},


// Given a name and a version of a package, return a path on disk
// from which we can load it. If we don't have it on disk (we
// haven't downloaded it, or it just plain doesn't exist in the
// catalog) return null.
//
// Doesn't download packages. Downloading should be done at the time
// that .meteor/versions is updated.
//
// HACK: Version can be null if you are certain that the package is to be
// loaded from local packages. In the future, version should always be
// required and we should confirm that the version on disk is the version that
// we asked for. This is to support isopack loader not having a version
// manifest.
getLoadPathForPackage: function (name, version, constraintSolverOpts) {
var self = this;
self._requireInitialized();
buildmessage.assertInCapture();
constraintSolverOpts = constraintSolverOpts || {};

// Check local packages first.
if (_.has(self.packageSources, name)) {

// If we don't have a build of this package, we need to rebuild it.
self._build(name, {}, constraintSolverOpts);

// Return the path.
return self.packageSources[name].sourceRoot;
}

if (! version) {
throw new Error(name + " not a local package, and no version specified?");
}

var packageDir = tropohouse.default.packagePath(name, version);
if (fs.existsSync(packageDir)) {
return packageDir;
}
return null;
}

});

exports.BootstrapCatalogCheckout = BootstrapCatalogCheckout;
Loading

0 comments on commit b5d2cce

Please sign in to comment.