closure-util
Advanced tools
Comparing version 0.5.0 to 0.6.0
@@ -35,5 +35,5 @@ var EventEmitter = require('events').EventEmitter; | ||
var paths = options.paths || []; | ||
if (!Array.isArray(paths)) { | ||
paths = [paths]; | ||
var lib = options.lib || []; | ||
if (!Array.isArray(lib)) { | ||
lib = [lib]; | ||
} | ||
@@ -45,21 +45,32 @@ | ||
*/ | ||
this._paths = paths; | ||
this._lib = lib; | ||
var main = options.main || []; | ||
if (!Array.isArray(main)) { | ||
main = [main]; | ||
} | ||
/** | ||
* Main glob patterns. | ||
* @type {Array.<string>} | ||
*/ | ||
this._main = main; | ||
var self = this; | ||
process.nextTick(function() { | ||
self._processPaths(paths, function(err) { | ||
self._processPaths(lib, function(err) { | ||
var more = main; | ||
if (options.closure) { | ||
var closure = path.join(__dirname, '..', 'bower_components', | ||
'closure-library'); | ||
var more = [ | ||
more = more.concat([ | ||
path.join(closure, 'closure', 'goog', '**', '*.js'), | ||
path.join(closure, 'third_party', 'closure', 'goog', '**', '*.js') | ||
]; | ||
self._afterProcessPaths(err, function() { | ||
self._processPaths(more, self._afterProcessPaths.bind(self), true); | ||
}); | ||
} else { | ||
self._afterProcessPaths(err); | ||
]); | ||
} | ||
}); | ||
self._afterProcessPaths(err, function() { | ||
self._processPaths(more, self._afterProcessPaths.bind(self)); | ||
}); | ||
}, true); | ||
}); | ||
@@ -173,5 +184,6 @@ | ||
* Bundled closure library includes test and debug scripts that should | ||
* not be included unless explicitly required. Any main scripts should | ||
* not be included unless explicitly required. | ||
*/ | ||
if (!script.bundled) { | ||
if (script.lib) { | ||
visit(script); | ||
@@ -201,5 +213,5 @@ } | ||
* @param {function(Error)} done Callback. | ||
* @param {boolean=} opt_bundled Bundled library scripts. | ||
* @param {boolean=} opt_lib Library scripts. | ||
*/ | ||
Manager.prototype._processPaths = function(paths, done, opt_bundled) { | ||
Manager.prototype._processPaths = function(paths, done, opt_lib) { | ||
var self = this; | ||
@@ -217,3 +229,3 @@ async.waterfall([ | ||
results.forEach(function(script) { | ||
script.bundled = !!opt_bundled; | ||
script.lib = !!opt_lib; | ||
self._addScript(script); | ||
@@ -234,3 +246,4 @@ }); | ||
Manager.prototype._startWatch = function() { | ||
var gaze = new Gaze(this._paths); | ||
var paths = this._lib.concat(this._main); | ||
var gaze = new Gaze(paths); | ||
gaze.on('changed', this._handleChanged.bind(this)); | ||
@@ -237,0 +250,0 @@ gaze.on('added', this._handleChanged.bind(this)); |
@@ -21,3 +21,3 @@ var fs = require('fs'); | ||
this.loaderPath_ = config.loaderPath || '/@'; | ||
this.loader_ = config.loader || '/@'; | ||
@@ -99,6 +99,6 @@ // allow override | ||
var match = false; | ||
if (typeof this.loaderPath_ === 'string') { | ||
match = req.url.indexOf(this.loaderPath_) === 0 ? this.loaderPath_ : false; | ||
if (typeof this.loader_ === 'string') { | ||
match = req.url.indexOf(this.loader_) === 0 ? this.loader_ : false; | ||
} else { | ||
var matches = req.url.match(this.loaderPath_); | ||
var matches = req.url.match(this.loader_); | ||
match = matches && matches[0]; | ||
@@ -113,7 +113,8 @@ } | ||
* @param {http.IncomingRequest} req Request. | ||
* @param {string} loader Matched loader path. | ||
* @return {string} Script path. | ||
* @private | ||
*/ | ||
Server.prototype.getPath_ = function(req) { | ||
return url.parse(req.url).pathname.substring(this.loaderPath_.length); | ||
Server.prototype.getPath_ = function(req, loader) { | ||
return url.parse(req.url).pathname.substring(loader.length); | ||
}; | ||
@@ -242,3 +243,3 @@ | ||
// managed script | ||
var name = self.getPath_(req); | ||
var name = self.getPath_(req, match); | ||
if (!name) { | ||
@@ -248,4 +249,5 @@ // request for loader | ||
if (main && !manager.getScript(main)) { | ||
res.statusCode = 500; | ||
return res.end('Main script not in manager paths: ' + main); | ||
return self.renderTemplate_('error.js', { | ||
message: 'Main script not in manager paths: ' + main | ||
}, res); | ||
} | ||
@@ -252,0 +254,0 @@ var deps = manager.getDependencies(main); |
{ | ||
"name": "closure-util", | ||
"version": "0.5.0", | ||
"version": "0.6.0", | ||
"description": "Utilities for Closure Library based projects.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -28,3 +28,3 @@ var path = require('path'); | ||
var manager = new Manager({ | ||
paths: path.join(fixtures, 'dependencies', '**/*.js') | ||
lib: path.join(fixtures, 'dependencies', '**/*.js') | ||
}); | ||
@@ -45,3 +45,4 @@ manager.on('error', done); | ||
var manager = new Manager({ | ||
paths: path.join(fixtures, 'dependencies-main', '**/*.js') | ||
lib: path.join(fixtures, 'dependencies-main', '+(lib|goog)/**/*.js'), | ||
main: path.join(fixtures, 'dependencies-main', 'main-*.js') | ||
}); | ||
@@ -63,3 +64,4 @@ manager.on('error', done); | ||
var manager = new Manager({ | ||
paths: path.join(fixtures, 'dependencies-main', '**/*.js') | ||
lib: path.join(fixtures, 'dependencies-main', '+(lib|goog)/**/*.js'), | ||
main: path.join(fixtures, 'dependencies-main', 'main-*.js') | ||
}); | ||
@@ -79,5 +81,27 @@ manager.on('error', done); | ||
it('does not provide main scripts if not requested', function(done) { | ||
var manager = new Manager({ | ||
lib: path.join(fixtures, 'dependencies-main', '+(lib|goog)/**/*.js'), | ||
main: path.join(fixtures, 'dependencies-main', 'main-*.js') | ||
}); | ||
manager.on('error', done); | ||
manager.on('ready', function() { | ||
var dependencies = manager.getDependencies(); | ||
var names = dependencies.map(function(s) { | ||
return path.basename(s.name); | ||
}); | ||
assert.deepEqual(names.slice(0, 3), | ||
['base.js', 'fuel.js', 'vehicle.js']); | ||
assert.include(names, 'boat.js'); | ||
assert.include(names, 'car.js'); | ||
assert.include(names, 'truck.js'); | ||
assert.notInclude(names, 'main-boat.js'); | ||
assert.notInclude(names, 'main-car.js'); | ||
done(); | ||
}); | ||
}); | ||
it('ignores files without requires or provides', function(done) { | ||
var manager = new Manager({ | ||
paths: path.join(fixtures, 'dependencies-extra', '**/*.js') | ||
lib: path.join(fixtures, 'dependencies-extra', '**/*.js') | ||
}); | ||
@@ -84,0 +108,0 @@ manager.on('error', done); |
42779
40
1299