From d688e5d85a1971b00cd41352030f6699d0a8a094 Mon Sep 17 00:00:00 2001 From: Victor Powell Date: Tue, 22 Jan 2013 18:44:40 -0800 Subject: [PATCH 1/2] add validator to check for issues in the component.json file --- lib/builder.js | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/lib/builder.js b/lib/builder.js index 8c9a2db..98e5416 100644 --- a/lib/builder.js +++ b/lib/builder.js @@ -342,12 +342,13 @@ Builder.prototype.append = function(str){ Builder.prototype.json = function(fn){ var self = this; var cache = this._cache; - + + // conf has already been validated if (this.conf) return fn(null, this.conf); var path = this.path('component.json'); var conf = cache[path]; - if (conf) return fn(null, this.conf = conf); + if (conf) return validate(this.conf); debug('reading %s', path); fs.readFile(path, 'utf8', function(err, str){ @@ -359,11 +360,17 @@ Builder.prototype.json = function(fn){ self._emittedConfig = true; self.emit('config'); } - fn(null, self.conf); + validate(self.conf); } catch (err) { fn(err); } }); + + function validate(conf){ + if(!conf.name) return fn(new Error( path + " attribute \"name\" missing")); + self.conf = conf; + fn(null, conf); + } }; /** From f9b87a040e1be87b29741069f9f4711919cfa0c4 Mon Sep 17 00:00:00 2001 From: Victor Powell Date: Tue, 22 Jan 2013 19:53:42 -0800 Subject: [PATCH 2/2] bug in validator code for component.json --- lib/builder.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/builder.js b/lib/builder.js index 98e5416..8a472ba 100644 --- a/lib/builder.js +++ b/lib/builder.js @@ -348,7 +348,7 @@ Builder.prototype.json = function(fn){ var path = this.path('component.json'); var conf = cache[path]; - if (conf) return validate(this.conf); + if (conf) return validate(conf); debug('reading %s', path); fs.readFile(path, 'utf8', function(err, str){