don't throw if there is no specified version, unless told to. Mostly because programs don't need versions anymore

This commit is contained in:
ekatek
2014-06-16 23:06:10 -07:00
parent fb709c9563
commit 15389fa740
5 changed files with 51 additions and 12 deletions

View File

@@ -1948,7 +1948,8 @@ exports.buildJsImage = function (options) {
serveRoot: path.sep,
npmDependencies: options.npmDependencies,
npmDir: options.npmDir,
dependencyVersions: options.dependencyVersions
dependencyVersions: options.dependencyVersions,
noVersionFile: true,
});
var unipackage = compiler.compile(packageSource).unipackage;

View File

@@ -408,7 +408,10 @@ _.extend(CompleteCatalog.prototype, {
title: "reading package `" + name + "`",
rootPath: packageDir
}, function () {
packageSource.initFromPackageDir(name, packageDir);
// All packages in the catalog must have versions.
packageSource.initFromPackageDir(name, packageDir, {
requireVersion: true
});
if (buildmessage.jobHasMessages())
broken = true;
});

View File

@@ -207,7 +207,10 @@ main.registerCommand({
}
packageSource = new PackageSource;
packageSource.initFromPackageDir(packageName, options.packageDir);
// Anything published to the server must have a version.
packageSource.initFromPackageDir(packageName, options.packageDir, {
requireVersion: true });
if (buildmessage.jobHasMessages())
return; // already have errors, so skip the build
@@ -293,7 +296,11 @@ main.registerCommand({
// immutable. It should be built exactly as is. If we need to modify anything,
// such as the version lock file, something has gone terribly wrong and we
// should throw.
packageSource.initFromPackageDir(options.name, packageDir, true /* immutable */);
packageSource.initFromPackageDir(options.name, packageDir, {
requireVersion: true,
immutable: true
});
var unipkg = compiler.compile(packageSource, {
officialBuild: true
}).unipackage;
@@ -529,7 +536,9 @@ main.registerCommand({
// Initialize the package source. (If we can't do this, then we should
// not proceed)
packageSource.initFromPackageDir(item, packageDir);
packageSource.initFromPackageDir(item, packageDir, {
requireVersion: true });
if (buildmessage.jobHasMessages()) {
process.stderr.write("Error reading package:" + item + "\n");
return;

View File

@@ -100,7 +100,9 @@ _.extend(PackageCache.prototype, {
isUpToDate = true;
} else {
var packageSource = new PackageSource;
packageSource.initFromPackageDir(name, loadPath);
// For now, if it turns into a unipackage, it should have a version.
packageSource.initFromPackageDir(name, loadPath, {
requireVersions: true });
unipackage = new Unipackage.Unipackage;
unipackage.initFromPath(name, entry.buildDir);
isUpToDate = compiler.checkUpToDate(packageSource, entry.pkg);
@@ -129,9 +131,11 @@ _.extend(PackageCache.prototype, {
return unipackage;
};
// It's a source tree. Load it.
var packageSource = new PackageSource;
packageSource.initFromPackageDir(name, loadPath);
// It's a source tree. Load it. It is going to turn into a unipackage, so it
// requires a version.
packageSource = new PackageSource;
packageSource.initFromPackageDir(name, loadPath, {
requireVersion: true });
// Does it have an up-to-date build?
var buildDir = path.join(loadPath, '.build.'+ name);

View File

@@ -284,6 +284,12 @@ var PackageSource = function () {
// specify the correct restrictions at 0.90.
// XXX: 0.90 package versions.
self.isCore = false;
// Alternatively, we can also specify noVersionFile directly. Useful for not
// recording version files for js images of plugins, since those go into the
// overall package versions file (if one exists). In the future, we can make
// this option transparent to the user in package.js.
self.noVersionFile = false;
};
@@ -360,6 +366,8 @@ _.extend(PackageSource.prototype, {
self.dependencyVersions = options.dependencyVersions ||
{dependencies: {}, pluginDependencies: {}};
self.noVersionFile = options.noVersionFile;
},
// Initialize a PackageSource from a package.js-style package directory. Uses
@@ -369,7 +377,14 @@ _.extend(PackageSource.prototype, {
//
// name: name of the package.
// dir: location of directory on disk.
initFromPackageDir: function (name, dir, immutable) {
// options:
// -requireVersion: This is a package that is going in a catalog or being
// published to the server. It must have a version. (as opposed to, for
// example, a program)
// -immutable: This package source is immutable. Do not write anything,
// including version files. Instead, its only purpose is to be used as
// guideline for a repeatable build.
initFromPackageDir: function (name, dir, options) {
var self = this;
var isPortable = true;
@@ -616,7 +631,7 @@ _.extend(PackageSource.prototype, {
npmDependencies = null;
}
if (! self.version) {
if (! self.version && options.requireVersion) {
if (! buildmessage.jobHasMessages()) {
// Only write the error if there have been no errors so
// far. (Otherwise if there is a parse error we'll always get
@@ -988,7 +1003,7 @@ _.extend(PackageSource.prototype, {
// If immutable is set, then we should make a note to never mutate this
// packageSource. We should never change its dependency versions, for
// example.
if (immutable) {
if (options.immutable) {
self.immutable = true;
};
@@ -1240,6 +1255,13 @@ _.extend(PackageSource.prototype, {
return;
}
// If we have specified to not record a version file for this package,
// don't. Currently used to avoid recording version files for separately
// compiled plugins.
if (self.noVersionFile) {
return;
}
// If nothing has changed, don't bother rewriting the versions file.
if (_.isEqual(self.dependencyVersions, versions)) return;