Permalink
Browse files

better parsing for `engine` and `engines` properties in package descr…

…iptors
  • Loading branch information...
1 parent 4a9268b commit c51db39e64b9b87a068557645dcc0a0fbe29daa3 @cadorn cadorn committed Aug 8, 2011
Showing with 28 additions and 2 deletions.
  1. +5 −0 lib/pinf-loader-js/api.js
  2. +23 −2 lib/pinf-loader-js/package.js
@@ -159,6 +159,11 @@ DEBUG.indent = function(count)
// # UTIL
// ######################################################################
+UTIL.isArray = function(obj) {
+ return Object.prototype.toString.call(obj) == "[object Array]";
+};
+
+
/**
* Merge two objects recursively.
*
@@ -79,8 +79,29 @@ var Package = exports.Package = function(descriptor, options)
this.preloaders = null;
if (typeof this.normalizedDescriptor.json.engine != "undefined")
{
- if (this.normalizedDescriptor.json.engine.indexOf(API.ENV.platform) === -1)
- throw new Error("Cannot run package '"+this.path+"' (supporting engines '"+this.normalizedDescriptor.json.engine+"') on platform '" + API.ENV.platform + "'");
+ this.normalizedDescriptor.json.engines = this.normalizedDescriptor.json.engine;
+ delete this.normalizedDescriptor.json.engine;
+ }
+ if (typeof this.normalizedDescriptor.json.engines != "undefined")
+ {
+ if (!UTIL.isArray(this.normalizedDescriptor.json.engines)) {
+ this.normalizedDescriptor.json.engines = [this.normalizedDescriptor.json.engines];
+ }
+ var found = false;
+ for (var i=0 ; i<this.normalizedDescriptor.json.engines.length ; i++) {
+ // TODO: Verify correct version of engine
+ if (typeof this.normalizedDescriptor.json.engines[i] === "object") {
+ if (new RegExp("^" + API.ENV.platform).exec(Object.keys(this.normalizedDescriptor.json.engines[i])[0])) {
+ found = true;
+ }
+ } else {
+ if (new RegExp("^" + API.ENV.platform).exec(this.normalizedDescriptor.json.engines[i])) {
+ found = true;
+ }
+ }
+ }
+ if (!found)
+ throw new Error("Cannot run package '"+this.path+"' (supporting engines '"+this.normalizedDescriptor.json.engines+"') on platform '" + API.ENV.platform + "'");
}
if (typeof this.descriptor.json.scripts != "undefined")
{

0 comments on commit c51db39

Please sign in to comment.