require-tree
Advanced tools
Comparing version 1.0.1 to 1.1.0
25
index.js
@@ -32,11 +32,28 @@ // require-tree | ||
var baseDir = process.env.NODE_PATH || path.dirname(module.parent.filename) | ||
, dir = path.resolve(baseDir, directory) | ||
var parentDir = path.dirname(module.parent.filename) | ||
, baseDirs = [parentDir] | ||
, forbidden = ['.json', '.node'] | ||
, filter = getFilter(options.filter) || Boolean | ||
, tree = {} | ||
, files = fs.readdirSync(dir) | ||
, dir = null | ||
, files = null | ||
files.filter(filter).forEach(function(file){ | ||
if (process.env.NODE_PATH) { | ||
Array.prototype.unshift.apply(baseDirs, process.env.NODE_PATH.split(';')); | ||
} | ||
var exists = baseDirs.some(function(baseDir){ | ||
try { | ||
dir = path.resolve(baseDir, directory) | ||
fs.accessSync ? fs.accessSync(dir) : fs.existsSync(dir) | ||
return true | ||
} catch (err) {} | ||
}) | ||
if (exists === false) { | ||
throw new Error('Cannot find directory ' + directory + ' in paths ' + baseDirs.join(';')) | ||
} | ||
fs.readdirSync(dir).filter(filter).forEach(function(file){ | ||
var ext = path.extname(file) | ||
@@ -43,0 +60,0 @@ , name = path.basename(file, ext) |
{ | ||
"name": "require-tree", | ||
"description": "Batch module loader, require() for directories", | ||
"version": "1.0.1", | ||
"version": "1.1.0", | ||
"main": "index.js", | ||
@@ -6,0 +6,0 @@ "dependencies": { |
@@ -121,3 +121,3 @@ require-tree | ||
#### index | ||
#### { index: 'merge', 'ignore', 'preserve' } | ||
@@ -124,0 +124,0 @@ * `merge` (default): merges the `index.js` exports at the root of it's parent |
var assert = require('assert') | ||
, path = require('path') | ||
, env = require('./lib/fake-env') | ||
, require_tree = require('../') | ||
@@ -69,2 +71,24 @@ | ||
describe('NODE PATH', function (){ | ||
it('should be used for lookup if present', function () { | ||
env.set('NODE_PATH', path.join(process.cwd(), 'test/node_path')) | ||
var hippo = require_tree('hippo') | ||
assert.deepEqual(hippo, { hippo: 1 }) | ||
env.restore() | ||
}) | ||
it('should accept multiple paths', function () { | ||
env.set('NODE_PATH', [ | ||
path.join(process.cwd(), 'test/not_a_path'), | ||
path.join(process.cwd(), 'test/node_path') | ||
].join(';') | ||
) | ||
var hippo = require_tree('hippo') | ||
assert.deepEqual(hippo, { hippo: 1 }) | ||
env.restore() | ||
}) | ||
}) | ||
}) | ||
@@ -71,0 +95,0 @@ |
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
18285
15
383
4