continue factoring out Library

This commit is contained in:
Geoff Schmidt
2013-04-02 20:24:10 -07:00
committed by David Glasser
parent 562490b776
commit 67356c0988
4 changed files with 38 additions and 27 deletions

View File

@@ -700,13 +700,13 @@ _.extend(Bundle.prototype, {
*
* - releaseStamp : The Meteor release version to use. This is *ONLY*
* used as a stamp (eg Meteor.release). The package
* search path is configured with packageSearchOptions.
* search path is configured with 'library'.
*
* - library : Package library to use to fetch any required
* packages. NOTE: if there's an appDir here, it's used for package
* searching but it is NOT the appDir that we bundle! So for
* "meteor test-packages" in an app, appDir is the test-runner-app
* but packageSearchOptions.appDir is the app the user is in.
* but library.appDir is the app the user is in.
*/
exports.bundle = function (app_dir, output_path, options) {
if (!options)

View File

@@ -86,10 +86,10 @@ Fiber(function () {
"Please check to make sure that you are online.");
}
}
context.packageSearchOptions = {
context.library = new packages.Library({
appDir: context.appDir,
releaseManifest: context.releaseManifest
};
});
};
var calculateReleaseVersion = function (argv) {
@@ -479,7 +479,7 @@ Fiber(function () {
}
requireDirInApp('add');
var all = (new packages.Library(context.packageSearchOptions)).list();
var all = context.library.list();
var using = {};
_.each(project.get_packages(context.appDir), function (name) {
using[name] = true;
@@ -565,7 +565,7 @@ Fiber(function () {
}
requireDirInApp('list');
var list = (new packages.Library(context.packageSearchOptions)).list()
var list = context.library.list();
var names = _.keys(list);
names.sort();
var pkgs = [];
@@ -610,7 +610,7 @@ Fiber(function () {
nodeModulesMode: 'copy',
minify: true, // XXX allow --debug
releaseStamp: context.releaseVersion,
library: new packages.Library(context.packageSearchOptions)
library: context.library
});
if (errors) {
process.stdout.write("Errors prevented bundling:\n");
@@ -763,7 +763,7 @@ Fiber(function () {
nodeModulesMode: 'skip',
minify: !new_argv.debug,
releaseStamp: context.releaseVersion,
library: new packages.Library(context.packageSearchOptions)
library: context.library
}
});
}
@@ -868,9 +868,8 @@ Fiber(function () {
var testPackages;
if (_.isEmpty(argv._)) {
testPackages = _.keys((new packages.Library(context.packageSearchOptions)).list());
testPackages = _.keys(context.library.list());
} else {
context.packageSearchOptions.preloadedPackages = {};
testPackages = _.map(argv._, function (p) {
// If it's a package name, the bundler will resolve it using
// context.packageSearchOptions later.
@@ -882,8 +881,7 @@ Fiber(function () {
// have a trailing slash.
var packageDir = path.resolve(p);
var packageName = path.basename(packageDir);
context.packageSearchOptions.preloadedPackages[packageName] =
packages.loadFromDir(packageName, packageDir);
context.library.preload(packageName, packageDir);
return packageName;
});
}
@@ -894,7 +892,7 @@ Fiber(function () {
// on each other.
//
// Note: context.appDir now is DIFFERENT from
// bundleOptions.packageSearchOptions.appDir: we are bundling the test
// bundleOptions.library.appDir: we are bundling the test
// runner app, but finding app packages from the current app (if any).
context.appDir = files.mkdtemp('meteor-test-run');
files.cp_r(path.join(__dirname, 'test-runner-app'), context.appDir);
@@ -911,7 +909,7 @@ Fiber(function () {
testPackages: testPackages,
minify: new_argv.production,
releaseStamp: context.releaseVersion,
library: new packages.Library(context.packageSearchOptions)
library: context.library
}, {
site: new_argv.deploy,
settings: new_argv.settings && runner.getSettings(new_argv.settings)
@@ -989,7 +987,7 @@ Fiber(function () {
}
// dev bundle is downloaded by the wrapper script. We just need to install
// NPM dependencies.
_.each((new Packages.Library(context.packageSearchOptions)).list(), function (p) {
_.each(context.library.list(), function (p) {
p.installNpmDependencies();
});
process.exit(0);

View File

@@ -31,12 +31,26 @@ var fs = require('fs');
// XXX XXX as implemented, it reads the environment and the current
// directory. It shouldn't do that. Those should ultimately be ctor
// arguments or something.
var Library = function (packageSearchOptions) {
var Library = function (options) {
var self = this;
self.packageSearchOptions = packageSearchOptions || {};
options = options || {};
self.preloadedPackages = {};
self.releaseManifest = options.releaseManifest;
self.appDir = options.appDir;
};
_.extend(Library.prototype, {
// Temporarily add a package to the library (or override a package
// that actually exists in the library.) `packageName` is the name
// to use for the package and `packageDir` is the directory that
// contains its source.
preload: function (packageName, packageDir) {
var self = this;
self.preloadedPackages[packageName] =
packages.loadFromDir(packageName, packageDir);
},
// get a package by name. also maps package objects to themselves.
// load order is:
// - APP_DIR/packages
@@ -48,16 +62,15 @@ _.extend(Library.prototype, {
if (name instanceof Package)
return name;
if (!(name in loadedPackages)) {
if (self.packageSearchOptions.preloadedPackages &&
name in self.packageSearchOptions.preloadedPackages) {
loadedPackages[name] = self.packageSearchOptions.preloadedPackages[name];
if (self.preloadedPackages && name in self.preloadedPackages) {
loadedPackages[name] = self.preloadedPackages[name];
} else {
var pkg = new Package;
if (pkg.initFromLocalPackages(name, self)) {
loadedPackages[name] = pkg;
} else if (self.packageSearchOptions.releaseManifest) {
} else if (self.releaseManifest) {
pkg.initFromWarehouse(
name, self.packageSearchOptions.releaseManifest.packages[name]);
name, self.releaseManifest.packages[name]);
loadedPackages[name] = pkg;
}
}
@@ -92,8 +105,8 @@ _.extend(Library.prototype, {
});
});
if (self.packageSearchOptions.releaseManifest) {
_.each(self.packageSearchOptions.releaseManifest.packages, function(version, name) {
if (self.releaseManifest) {
_.each(self.releaseManifest.packages, function(version, name) {
// don't even look for packages if they've already been
// overridden (though this `if` isn't necessary for
// correctness, since `packages.get` looks for packages in the
@@ -126,8 +139,8 @@ _.extend(Library.prototype, {
// If we're running from an app (as opposed to a global-level "meteor
// test-packages"), use app packages.
if (self.packageSearchOptions.appDir)
packageDirs.push(path.join(self.packageSearchOptions.appDir, 'packages'));
if (self.appDir)
packageDirs.push(path.join(self.appDir, 'packages'));
// Next, search $PACKAGE_DIRS.
if (process.env.PACKAGE_DIRS)

View File

@@ -635,7 +635,7 @@ exports.run = function (context, options) {
minify: options.minify,
testPackages: options.testPackages,
releaseStamp: context.releaseVersion,
library: new packages.Library(context.packageSearchOptions)
library: context.library
};
var start_watching = function () {