Skip to content

Commit

Permalink
Merge pull request #11 from coderhaoxin/ignore-node_modules
Browse files Browse the repository at this point in the history
ignore node_modules
  • Loading branch information
aseemk committed Mar 20, 2015
2 parents fb6c0e2 + a070d2c commit a74bc77
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 2 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
language: node_js
node_js:
- "0.11"
- "0.10"
- "0.8"
- "0.12"
- "iojs"
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ var dir = requireDir('./path/to/dir', {recurse: true});
## Options

`recurse`: Whether to recursively `require()` subdirectories too.
(`node_modules` within subdirectories will be ignored.)
Default is false.

`duplicates`: By default, if multiple files share the same basename, only the
Expand Down
3 changes: 3 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ module.exports = function requireDir(dir, opts) {

if (FS.statSync(path).isDirectory()) {
if (opts.recurse) {
if (base === 'node_modules') {
continue;
}
map[base] = requireDir(path, opts);

// if duplicates are wanted, key off the full name too:
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
, "dependencies": {}
, "devDependencies":
{ "coffee-script": "~1.3.3"
, "mkdirp": "^0.5.0"
}
, "engines":
{ "node": "*"
Expand Down
12 changes: 12 additions & 0 deletions test/recurse.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
var assert = require('assert');
var mkdirp = require('mkdirp');
var path = require('path');
var fs = require('fs');

var requireDir = require('..');

// first test without recursing:
Expand All @@ -7,6 +11,14 @@ assert.deepEqual(requireDir('./recurse'), {
});

// then test with recursing:
var dir = path.join(__dirname, 'recurse', 'node_modules');
try {
fs.statSync(path.join(dir, 'fake.js'));
} catch (e) {
mkdirp.sync(dir);
fs.writeFileSync(path.join(dir, 'fake.js'), 'module.exports = "ignore";');
}

assert.deepEqual(requireDir('./recurse', {recurse: true}), {
a: 'a',
b: {
Expand Down

0 comments on commit a74bc77

Please sign in to comment.