Comparing version 0.1.1 to 0.1.2
@@ -63,2 +63,4 @@ 'use strict'; | ||
var filter = typeof options.filter === 'function' ? options.filter : defaultFilter; | ||
var modules = {}; | ||
@@ -68,20 +70,9 @@ read(dir, options); | ||
function defaultFilter(info) { | ||
return require(info.file); | ||
} | ||
function register(modules, info) { | ||
if (options['watch']) { | ||
if (!info.stat) { | ||
info.stat = fs.statSync(info.file); | ||
} | ||
modules.__defineGetter__(info.name, function() { | ||
var stat = fs.statSync(info.file); | ||
if (!info.cache || info.stat && info.stat.mtime < stat.mtime) { | ||
debug('reload ' + info.file); | ||
delete Module._cache[info.file]; | ||
info.cache = require(info.file); | ||
} | ||
info.stat = stat; | ||
return info.cache; | ||
}); | ||
} else { | ||
modules[info.name] = require(info.file); | ||
} | ||
var m = filter(info); | ||
if (!!m) modules[info.name] = m; | ||
} | ||
@@ -88,0 +79,0 @@ |
{ | ||
"name": "needs", | ||
"version": "0.1.1", | ||
"version": "0.1.2", | ||
"description": "Require multiple modules in node.js.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -90,2 +90,22 @@ var chai = require('chai'); | ||
it('requiring modules with filter', function () { | ||
var modules = needs(root, 'modules', { | ||
module: true, | ||
filter: function (info) { | ||
var mod = require(info.file); | ||
if (typeof mod === 'object') mod.moduleName = info.name; | ||
return mod; | ||
} | ||
}); | ||
t.deepEqual(modules, { | ||
foo: 'bar', | ||
hello: { | ||
world: true, | ||
universe: 42, | ||
moduleName: "hello" | ||
} | ||
}); | ||
}); | ||
}); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
9363
212