From 15389fa740d2729bc3453098e8ecc4784ffdc84c Mon Sep 17 00:00:00 2001 From: ekatek Date: Mon, 16 Jun 2014 23:06:10 -0700 Subject: [PATCH] don't throw if there is no specified version, unless told to. Mostly because programs don't need versions anymore --- tools/bundler.js | 3 ++- tools/catalog.js | 5 ++++- tools/commands-packages.js | 15 ++++++++++++--- tools/package-cache.js | 12 ++++++++---- tools/package-source.js | 28 +++++++++++++++++++++++++--- 5 files changed, 51 insertions(+), 12 deletions(-) diff --git a/tools/bundler.js b/tools/bundler.js index 12284e6604..b693943b0f 100644 --- a/tools/bundler.js +++ b/tools/bundler.js @@ -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; diff --git a/tools/catalog.js b/tools/catalog.js index df950049ff..2192abb556 100644 --- a/tools/catalog.js +++ b/tools/catalog.js @@ -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; }); diff --git a/tools/commands-packages.js b/tools/commands-packages.js index 07965e185e..3475e2ee0c 100644 --- a/tools/commands-packages.js +++ b/tools/commands-packages.js @@ -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; diff --git a/tools/package-cache.js b/tools/package-cache.js index a41febf6a3..cca7c0a667 100644 --- a/tools/package-cache.js +++ b/tools/package-cache.js @@ -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); diff --git a/tools/package-source.js b/tools/package-source.js index c26668de3b..78dd010c63 100644 --- a/tools/package-source.js +++ b/tools/package-source.js @@ -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;