Git Product home page Git Product logo

requiredir's People

Contributors

aseemk avatar hrdwdmrbl avatar lennym avatar richardgarnier avatar scragg0x avatar vincentroth avatar yocontra avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

requiredir's Issues

Require directories within directory?

I have a situation like this:

  • /foo/index.js - require-dir is executed here
  • /foo/bar/index.js
  • /foo/baz/index.js

I would like to expose bar and baz through foo. Unfortunately require-dir takes just files in count. Maybe this would be a good extra option? I know it's a special case.

Get only an array of paths

Add a requireDir.resolve() which would return a map of the paths instead of a map of the required paths.

It would help plugins like browserify to follow your requires, without loosing time loading unnecessary modules.

I chose the name .resolve() to stay consistent with require.resolve().

Can't import file and folder with the same name

Hi. I just tried import files from folder recursively, and unfortunately my folders have name conflict with another files.

├── build
│   ├── clean.js
├── build.js
├── default.js
├── dev
│   ├── browserSync.js
└── dev.js

With this example files 'build.js' and 'dev.js' wont be loaded.

Reading tasks from parent directories?

Is it not possible to read gulp task files from a parent directory? I have the following directory structure and using

require('require-dir')('../../config/gulp/tasks');

Doesn't read in the files. But if I copy the folder gulp/tasks into my Modules A directory and update the paths then it works perfectly. I'm trying to prevent unncessary duplicate task files.

  • project root
    • config
      • gulp
        -tasks
  • modules
    • module A
    • module B

Thank you for any help.

How can I have this working in coffeescript?

It works for node.js with the index.js

Is it possible to have this working with the 'index.coffee' files too?

The version with specific require's in coffeescript is also working,
but when I want to use require-dir and use dot-notation like 'm1.m11.m12.m13.module13', this does not work.

Here I have the results of my tests:

C:_TEST\m1>node _m11.js
Duplicate tests passed.
Recurse tests passed.
Simple tests passed.

All tests passed!
M12/m1 created!
List of modules ... M12/m1
M12/m2 created!
List of modules ... M12/m1,M12/m2
M12/m3 created!
List of modules ... M12/m1,M12/m2,M12/m3
M12/m4 created!
List of modules ... M12/m1,M12/m2,M12/m3,M12/m4
M12/m5 created!
List of modules ... M12/m1,M12/m2,M12/m3,M12/m4,M12/m5
M12/m6 created!
List of modules ... M12/m1,M12/m2,M12/m3,M12/m4,M12/m5,M12/m6

C:_TEST\m1>node m11/m12/m13/_m13.js
Duplicate tests passed.
Recurse tests passed.
Simple tests passed.

All tests passed!
M13/m1 created!
List of modules ... M13/m1
M13/m2 created!
List of modules ... M13/m1,M13/m2
M13/m3 created!
List of modules ... M13/m1,M13/m2,M13/m3
M13/m4 created!
List of modules ... M13/m1,M13/m2,M13/m3,M13/m4
M13/m5 created!
List of modules ... M13/m1,M13/m2,M13/m3,M13/m4,M13/m5
M13/m6 created!
List of modules ... M13/m1,M13/m2,M13/m3,M13/m4,M13/m5,M13/m6

C:_TEST\m1>coffee _m11.coffee
Duplicate tests passed.
Recurse tests passed.
AssertionError: {"a":"a","b":"b","c":"c"} deepEqual {"a":"a","b":"b"}
at Object. (C:_TEST\m1\node_modules\require-dir\test\simple.js:5:8)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (C:_SOFTWARE\nodejs\node_modules\coffee-script\lib\coffee-script\coffee-script.js:211:36)
at Function.Module._load (module.js:312:12)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at requireDir (C:_TEST\m1\node_modules\require-dir\index.js:112:33)
at Object. (C:_TEST\m1\node_modules\require-dir\test\index.js:1:76)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (C:_SOFTWARE\nodejs\node_modules\coffee-script\lib\coffee-script\coffee-script.js:211:36)
at Function.Module._load (module.js:312:12)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at requireDir (C:_TEST\m1\node_modules\require-dir\index.js:112:33)
at requireDir (C:_TEST\m1\node_modules\require-dir\index.js:72:33)
at requireDir (C:_TEST\m1\node_modules\require-dir\index.js:72:33)
at requireDir (C:_TEST\m1\node_modules\require-dir\index.js:72:33)
at Object. (C:_TEST\m1\index.coffee:1:18, :2:42)
at Object. (C:_TEST\m1\index.coffee:1:1, :6:4)
at Module._compile (module.js:456:26)
at Object.loadFile (C:_SOFTWARE\nodejs\node_modules\coffee-script\lib\coffee-script\coffee-script.js:182:19)
at Module.load (C:_SOFTWARE\nodejs\node_modules\coffee-script\lib\coffee-script\coffee-script.js:211:36)
at Function.Module._load (module.js:312:12)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at requireDir (C:_TEST\m1\node_modules\require-dir\index.js:112:33)
at Object. (C:_TEST\m1\index.js:3:42)
at Object. (C:_TEST\m1\index.js:7:4)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (C:_SOFTWARE\nodejs\node_modules\coffee-script\lib\coffee-script\coffee-script.js:211:36)
at Function.Module._load (module.js:312:12)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at Object. (C:_TEST\m1\m11\m12\m13_m13.js:5:8)
at Object. (C:_TEST\m1\m11\m12\m13_m13.js:35:4)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (C:_SOFTWARE\nodejs\node_modules\coffee-script\lib\coffee-script\coffee-script.js:211:36)
at Function.Module._load (module.js:312:12)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at requireDir (C:_TEST\m1\node_modules\require-dir\index.js:112:33)
at Object. (C:_TEST\m1\m11\m12\m13\index.coffee:1:18, :2:42)
at Object. (C:_TEST\m1\m11\m12\m13\index.coffee:1:1, :6:4)
at Module._compile (module.js:456:26)
at Object.loadFile (C:_SOFTWARE\nodejs\node_modules\coffee-script\lib\coffee-script\coffee-script.js:182:19)
at Module.load (C:_SOFTWARE\nodejs\node_modules\coffee-script\lib\coffee-script\coffee-script.js:211:36)
at Function.Module._load (module.js:312:12)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at requireDir (C:_TEST\m1\node_modules\require-dir\index.js:112:33)
at Object. (C:_TEST\m1\m11\m12\m13\index.js:3:42)
at Object. (C:_TEST\m1\m11\m12\m13\index.js:7:4)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (C:_SOFTWARE\nodejs\node_modules\coffee-script\lib\coffee-script\coffee-script.js:211:36)
at Function.Module._load (module.js:312:12)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at requireDir (C:_TEST\m1\node_modules\require-dir\index.js:112:33)
at requireDir (C:_TEST\m1\node_modules\require-dir\index.js:72:33)
at Object. (C:_TEST\m1\m11\m12\index.coffee:1:18, :2:42)
at Object. (C:_TEST\m1\m11\m12\index.coffee:1:1, :6:4)
at Module._compile (module.js:456:26)
at Object.loadFile (C:_SOFTWARE\nodejs\node_modules\coffee-script\lib\coffee-script\coffee-script.js:182:19)
at Module.load (C:_SOFTWARE\nodejs\node_modules\coffee-script\lib\coffee-script\coffee-script.js:211:36)
at Function.Module._load (module.js:312:12)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at requireDir (C:_TEST\m1\node_modules\require-dir\index.js:112:33)
at Object. (C:_TEST\m1\m11\m12\index.js:3:42)
at Object. (C:_TEST\m1\m11\m12\index.js:7:4)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (C:_SOFTWARE\nodejs\node_modules\coffee-script\lib\coffee-script\coffee-script.js:211:36)
at Function.Module._load (module.js:312:12)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at requireDir (C:_TEST\m1\node_modules\require-dir\index.js:112:33)
at requireDir (C:_TEST\m1\node_modules\require-dir\index.js:72:33)
at Object. (C:_TEST\m1\m11\index.coffee:1:18, :2:42)
at Object. (C:_TEST\m1\m11\index.coffee:1:1, :6:4)
at Module._compile (module.js:456:26)
at Object.loadFile (C:_SOFTWARE\nodejs\node_modules\coffee-script\lib\coffee-script\coffee-script.js:182:19)
at Module.load (C:_SOFTWARE\nodejs\node_modules\coffee-script\lib\coffee-script\coffee-script.js:211:36)
at Function.Module._load (module.js:312:12)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at requireDir (C:_TEST\m1\node_modules\require-dir\index.js:112:33)
at Object. (C:_TEST\m1\m11\index.js:3:42)
at Object. (C:_TEST\m1\m11\index.js:7:4)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (C:_SOFTWARE\nodejs\node_modules\coffee-script\lib\coffee-script\coffee-script.js:211:36)
at Function.Module._load (module.js:312:12)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at Object. (C:_TEST\m1_m11.coffee:1:7, :4:9)
at Object. (C:_TEST\m1_m11.coffee:1:1, :34:4)
at Module._compile (module.js:456:26)

C:_TEST\m1>coffee m11/m12/m13/_m13.coffee
TypeError: Cannot read property 'm12' of undefined
at Object. (C:_TEST\m1\m11\m12\m13_m13.js:7:18)
at Object. (C:_TEST\m1\m11\m12\m13_m13.js:35:4)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (C:_SOFTWARE\nodejs\node_modules\coffee-script\lib\coffee-script\coffee-script.js:211:36)
at Function.Module._load (module.js:312:12)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at requireDir (C:_TEST\m1\node_modules\require-dir\index.js:112:33)
at Object. (C:_TEST\m1\m11\m12\m13\index.coffee:1:18, :2:42)
at Object. (C:_TEST\m1\m11\m12\m13\index.coffee:1:1, :6:4)
at Module._compile (module.js:456:26)
at Object.loadFile (C:_SOFTWARE\nodejs\node_modules\coffee-script\lib\coffee-script\coffee-script.js:182:19)
at Module.load (C:_SOFTWARE\nodejs\node_modules\coffee-script\lib\coffee-script\coffee-script.js:211:36)
at Function.Module._load (module.js:312:12)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at requireDir (C:_TEST\m1\node_modules\require-dir\index.js:112:33)
at Object. (C:_TEST\m1\m11\m12\m13\index.js:3:42)
at Object. (C:_TEST\m1\m11\m12\m13\index.js:7:4)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (C:_SOFTWARE\nodejs\node_modules\coffee-script\lib\coffee-script\coffee-script.js:211:36)
at Function.Module._load (module.js:312:12)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at requireDir (C:_TEST\m1\node_modules\require-dir\index.js:112:33)
at requireDir (C:_TEST\m1\node_modules\require-dir\index.js:72:33)
at Object. (C:_TEST\m1\m11\m12\index.coffee:1:18, :2:42)
at Object. (C:_TEST\m1\m11\m12\index.coffee:1:1, :6:4)
at Module._compile (module.js:456:26)
at Object.loadFile (C:_SOFTWARE\nodejs\node_modules\coffee-script\lib\coffee-script\coffee-script.js:182:19)
at Module.load (C:_SOFTWARE\nodejs\node_modules\coffee-script\lib\coffee-script\coffee-script.js:211:36)
at Function.Module._load (module.js:312:12)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at requireDir (C:_TEST\m1\node_modules\require-dir\index.js:112:33)
at Object. (C:_TEST\m1\m11\m12\index.js:3:42)
at Object. (C:_TEST\m1\m11\m12\index.js:7:4)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (C:_SOFTWARE\nodejs\node_modules\coffee-script\lib\coffee-script\coffee-script.js:211:36)
at Function.Module._load (module.js:312:12)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at requireDir (C:_TEST\m1\node_modules\require-dir\index.js:112:33)
at requireDir (C:_TEST\m1\node_modules\require-dir\index.js:72:33)
at Object. (C:_TEST\m1\m11\index.coffee:1:18, :2:42)
at Object. (C:_TEST\m1\m11\index.coffee:1:1, :6:4)
at Module._compile (module.js:456:26)
at Object.loadFile (C:_SOFTWARE\nodejs\node_modules\coffee-script\lib\coffee-script\coffee-script.js:182:19)
at Module.load (C:_SOFTWARE\nodejs\node_modules\coffee-script\lib\coffee-script\coffee-script.js:211:36)
at Function.Module._load (module.js:312:12)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at requireDir (C:_TEST\m1\node_modules\require-dir\index.js:112:33)
at Object. (C:_TEST\m1\m11\index.js:3:42)
at Object. (C:_TEST\m1\m11\index.js:7:4)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (C:_SOFTWARE\nodejs\node_modules\coffee-script\lib\coffee-script\coffee-script.js:211:36)
at Function.Module._load (module.js:312:12)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at requireDir (C:_TEST\m1\node_modules\require-dir\index.js:112:33)
at requireDir (C:_TEST\m1\node_modules\require-dir\index.js:72:33)
at Object. (C:_TEST\m1\index.coffee:1:18, :2:42)
at Object. (C:_TEST\m1\index.coffee:1:1, :6:4)
at Module._compile (module.js:456:26)
at Object.loadFile (C:_SOFTWARE\nodejs\node_modules\coffee-script\lib\coffee-script\coffee-script.js:182:19)
at Module.load (C:_SOFTWARE\nodejs\node_modules\coffee-script\lib\coffee-script\coffee-script.js:211:36)
at Function.Module._load (module.js:312:12)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at requireDir (C:_TEST\m1\node_modules\require-dir\index.js:112:33)
at Object. (C:_TEST\m1\index.js:3:42)
at Object. (C:_TEST\m1\index.js:7:4)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (C:_SOFTWARE\nodejs\node_modules\coffee-script\lib\coffee-script\coffee-script.js:211:36)
at Function.Module._load (module.js:312:12)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at Object. (C:_TEST\m1\m11\m12\m13_m13.coffee:1:6, :4:8)
at Object. (C:_TEST\m1\m11\m12\m13_m13.coffee:1:1, :34:4)
at Module._compile (module.js:456:26)

C:_TEST\m1>

C:_TEST\m1>dir /S
Volume in drive C has no label.
Volume Serial Number is 327D-5717

Directories without node_modules (require-dir)

Directory of C:_TEST\m1

index.coffee
index.js
module11.coffee
module11.js
_m11.coffee
_m11.js
m11

Directory of C:_TEST\m1\m11

index.coffee
index.js
m12

Directory of C:_TEST\m1\m11\m12

index.coffee
index.js
module12.coffee
module12.js
m13

Directory of C:_TEST\m1\m11\m12\m13

index.coffee
index.js
module13.coffee
module13.js
_m13.coffee
_m13.js

EPEERINVALID under [email protected]

When testing readiness of my build to be used with the newest nodejs v4.2.3, I encounter (among others) this error:

npm info it worked if it ends with ok
npm info using [email protected]
npm info using [email protected]
npm info package.json [email protected] No license field.
npm info package.json [email protected] No license field.
npm info package.json [email protected] No license field.
npm info attempt registry request try #1 at 4:56:22 AM
npm http request GET https://registry.npmjs.org/require-dir
npm http 304 https://registry.npmjs.org/require-dir
npm info install [email protected] into /var/upgrade-ready/4d5cae60-9cc8-11e5-9d3e-9f93a8a5e566
npm info installOne [email protected]
npm info preinstall [email protected]
npm info build /var/upgrade-ready/4d5cae60-9cc8-11e5-9d3e-9f93a8a5e566/node_modules/require-dir
npm info linkStuff [email protected]
npm info install [email protected]
npm info postinstall [email protected]
npm ERR! Linux 3.13.0-57-generic
npm ERR! argv "/usr/bin/nodejs" "/usr/bin/npm" "install" "[email protected]" "-d" "--nodedir=\"/root/.nvm/versions/node/v4.2.3\""
npm ERR! node v4.2.3
npm ERR! npm  v2.14.14
npm ERR! code EPEERINVALID

npm ERR! peerinvalid The package undefined does not satisfy its siblings' peerDependencies requirements!
npm ERR! peerinvalid Peer [email protected] wants undefined@>=0.10
npm ERR! peerinvalid Peer [email protected] wants undefined@>=0.9

npm ERR! Please include the following file with any support request:
npm ERR!     /var/upgrade-ready/4d5cae60-9cc8-11e5-9d3e-9f93a8a5e566/npm-debug.log

This means that I cannot launch my project with current require-dir. Any thoughts? I am using https://www.npmjs.com/package/upgrade-ready tool for readiness verification.

browserify transform

I use browserify to bundle commonjs modules, browserify does this by detecting calls to require, so it won't work out-of-the-box with requireDir.
But this can be done by writing a plugin, aka "browserify transform" specific for require-dir, someone did it here https://www.npmjs.org/package/folderify for the analogous lib "includeFolder".
Is there any folderify equivalent for requireDir? any plans on having one?

How to handle errors in required file?

Some of my files have erroneous code in them. How can I catch the exceptions thrown by these during the require?
Currently I can only try-catch the whole require-dir, not on a file by file basis.

Filter

Hi

Is there no option to filter out directories you don't want to require? Folders such as .git or node_modules are 2 directories you may want to filter from a directory require.

broken after update to node.js 4.0

after update to node.js 4.0 all my projects who have requireDir was broken.
my gulp config

'use strict';
var requireDir = require('require-dir');
requireDir('./gulp/tasks', {recurse: true});

if

var gulp = require('gulp');
gulp.task('default', function() {
});

all fine

but if my config, then

Failed to list gulp tasks in fitness/gulpfile.js: process finished with exit code 1 (a non-zero exit code means an error)
 * Edit settings

$ /usr/local/bin/node /usr/local/lib/node_modules/gulp/bin/gulp.js --no-color --gulpfile /Users/ass/projects/fitness/gulpfile.js --tasks
module.js:338
    throw err;
    ^

Error: Cannot find module 'gulp-util'
    at Function.Module._resolveFilename (module.js:336:15)
    at Function.Module._load (module.js:286:25)
    at Module.require (module.js:365:17)
    at require (module.js:384:17)
    at Object.<anonymous> (/Users/ass/projects/fitness/gulpfile.js:2:13)
    at Module._compile (module.js:434:26)
    at Object.Module._extensions..js (module.js:452:10)
    at Module.load (module.js:355:32)
    at Function.Module._load (module.js:310:12)
    at Module.require (module.js:365:17)
    at require (module.js:384:17)

Process finished with exit code 1

in WebStorm

and

$ gulp
Segmentation fault: 11

in pure console

Invalid Readme

When I try to use your library (installed via NPM) with Webpack I get:

WARNING in ./~/require-dir/package.json
Module parse failed: /home/me/project/node_modules/require-dir/package.json Unexpected token (2:9)
You may need an appropriate loader to handle this file type.
SyntaxError: Unexpected token (2:9)

(presumably because of the processing instructions).

Is there a way to get this to play nicely with Intellisense/JSDocs?

Howdy,

I've been using require-dir indirectly via the Ranvier MUD project. The project has really nice source documentation which works as expected when dealing with the core repository. However, once you pull the core engine into another project with require('ranvier');, any Intellisense hinting with the JSDocs seems to be broken by the use of require-dir to pull in the source files and modularize it.

Is there a known way to fix this by configuring VSCode or otherwise setting up the use of require-dir differently?

doesn't require subdirectories

currently I have the following situation:

/foo/bar.js
/foo/baz/index.js
/foo/baz/bar.js

what I'm expecting when I do

requireDir('./foo');

is

{
  bar: '...',
  baz: '...'
}

like it follows the semantics of require with respect to subfolders, but what I get is

{
  bar: '...'
}

while the recurse options is not what I want because that would give me:

{
  bar: '...',
  baz: {
    index: '...',
    bar: '...'
  }
}

If a directory and a file have the same basename only one gets processed

Take a look at Semantic-UI's tasks folder: they have a build.js main task, that requires all the individual partial builders from the build directory, both are located at the same path.

I'm building something similar, but in a cleaner why with the help of this library. The problem is that since both objects have the same basename only the directory gets processed, hence the build.js file never gets loaded.

A possibile solution to this problem would be to overwrite the previously defined key of the returned hash, I think that processing all the files is more important. In my case none of the files located in the build directory is even actually exporting anything.

Broken on node v8

There appears to be a change in require in node v8 that breaks require-dir:

C:\workspace\software-engineering\angular-mean>ncu
C:\Zimmermann\npm-config\node_modules\npm-check-updates\node_modules\require-dir\index.js:97
            if (!require.extensions.hasOwnProperty(ext)) {
                                    ^

TypeError: require.extensions.hasOwnProperty is not a function
    at requireDir (C:\Zimmermann\npm-config\node_modules\npm-check-updates\node_modules\require-dir\index.js:97:37)
    at Object.<anonymous> (C:\Zimmermann\npm-config\node_modules\npm-check-updates\lib\versionmanager.js:8:23)
    at Module._compile (module.js:569:30)
    at Object.Module._extensions..js (module.js:580:10)
    at Module.load (module.js:503:32)
    at tryModuleLoad (module.js:466:12)
    at Function.Module._load (module.js:458:3)
    at Module.require (module.js:513:17)
    at require (internal/module.js:11:18)
    at Object.<anonymous> (C:\Zimmermann\npm-config\node_modules\npm-check-updates\lib\npm-check-updates.js:14:10)
    at Module._compile (module.js:569:30)
    at Object.Module._extensions..js (module.js:580:10)
    at Module.load (module.js:503:32)
    at tryModuleLoad (module.js:466:12)
    at Function.Module._load (module.js:458:3)
    at Module.require (module.js:513:17)

Reported at: raineorshine/npm-check-updates#355

Relative requires broken in Jest tests

Please refer to jestjs/jest#4567.

It appears that a Jest specific issue causes require-dir's module resolution to happen relatively to the test package instead of the parent package. This causes dependents of require-dir, including npm-check-updates, to break when used in Jest tests.

ignore option

Possibly a combination of #14 and #5, but instead uses globs/regexp for the extra ignore option.

Add option to "flatten" when recursing

It'd be great to have some sort of way to "flatten" a requireDir call so all modules are on the same level. I imagine either adding a flatten option or allowing users to specify recurse: 'flatten' in the options object.

Sharing global variable between files possible?

I have a main file gulpfile.js with variable env initialized.

var gulp = require('gulp');
require('require-dir')('./gulp');

var env = process.env.NODE_ENV  || 'DEV';

gulp.task('default', ['clean'], function () {
    gulp.start('build');
});

I want to use env in ./gulp/build.js

gulp.task('styles', function () {
    return gulp.src('app/styles/main.scss')
        .pipe($.plumber())
        .pipe($.rubySass({
            style: 'expanded',
            precision: 10,
            sourcemap: (env === 'DEV')
        }))
        .pipe($.autoprefixer('last 2 version'))
        .pipe(gulp.dest('.tmp/styles'));
});

may be in some other child file , i want to override env global variable. is it possible ?

Support .es6 extensions

Is there an easy way to support .es6 files, or should just modify require-dir source to allow it?

Adding to CITGM

Hey,

We'd like to add require-dir to Node.js's Canary In The Gold Mine. (currently tested packages)

This means new releases of Node will run require-dir's unit tests as integration tests and should prevent issues like #45 from happening in the future.

It would have let us catch the issue back at nodejs/node#10789

In order for us to do that - we need @aseemk (or another maintainer) to agree to be reachable and responsive for problems (as they may influence Node version releases directly).

@aseemk what do you say? Would you be up for it? It would have certainly saved me time personally if require-dir was there :)

Crash on Node 8

I got this error when running a project using it in Node 8

[...]/server/node_modules/require-dir/index.js:97
            if (!require.extensions.hasOwnProperty(ext)) {
                                    ^
TypeError: require.extensions.hasOwnProperty is not a function

It seems that require.extensions is deprecated and removed from Node 8. Any plan to upgrade this package for newer Node?

Doesn't load module in install globally

$ node -v
v0.10.35 # under nvm

$ npm install --global require-dir
$ node -e "var dir=require('require-dir')('.'); console.log(dir)"

module.js:340
    throw err;
          ^
Error: Cannot find module 'require-dir'
    at Function.Module._resolveFilename (module.js:338:15)
    at Function.Module._load (module.js:280:25)
    at Module.require (module.js:364:17)
    at require (module.js:380:17)
    at [eval]:1:9
    at Object.<anonymous> ([eval]-wrapper:6:22)
    at Module._compile (module.js:456:26)
    at evalScript (node.js:559:25)
    at startup (node.js:80:7)
    at node.js:929:3
$ npm install require-dir
$ node -e "var dir=require('require-dir')('.'); console.log(dir)"
{} 

Error: Cannot find module 'require‐dir'

I know this has been raised before but i don't see the solution.

npm install require-dir --save-dev

Package gets installed.

In gulpfile:

var requireDir = require('require‐dir');
requireDir('./folder-a/folder-b');

Error message:

module.js:338
    throw err;
    ^
Error: Cannot find module 'require‐dir'
etc ...

Node v0.12.7

Could you please explain why I am getting this error and if there is a simple fix?

Thanks

Support for Parameters

It would be fantastic to have the ability to pass in parameters to the require().

Example:

require('require-dir')('./path/to/tasks', [gulp, $]);

becomes something like...

_.each(tasks, function (task) {
  require(task)(gulp, $);
}

This would give us the ability to split up Gulp tasks into their own files.

Full Example:

// ./tasks/artifact.js

module.exports = function (gulp, $) {
  'use strict';

  /**
   * Artifact
   * @description Build `./target/app.zip` from distribution files.
   */
  return gulp.task('artifact', 'Build `./target/app.zip` from distribution files.', ['build'], function () {
    log('Building artifact...');

    gulp.src(config.dist + '**')
      .pipe($.if(args.verbose, $.print()))
      .pipe($.zip(config.artifact.filename))
      .pipe(gulp.dest('./.tmp'))
      .pipe($.notify(_.extend(config.notify, {
        message: 'Artifact created: ' + config.target + config.artifact.filename
      })));
  });
};
// ./gulpfile.js

require('require-dir')('./path/to/tasks', [gulp, $]);

Does anyone have any thoughts on this?

with require do I need gulp required on all tasks files?

all my require requireDir('path/dir') need this in their files:

var gulp = require('gulp');

Is there a way that require('gulp') only has the need to set this in the gulpfile.js and not on every individual files in the path?...I feel like there should be a way not to have to add these to all the files that are added but have to in this case. It seems to make process delay.

Possible conflict between directories and files with the same name

I've got a directory structure that looks like this:

  • tasks
    • test
      • local.js
      • remote.js
    • build.js
    • test.js

The output from recursively requiring is:

{ build: {}, test: { local: {}, remote: {} } }

But if I rename test.js to foobar.js, I get:

{ build: {}, foobar: {}, test: { local: {}, remote: {} } }

It would appear it can't require directories and files if they have the same.

"Cannot read property 'filename' of undefined" on require('require-dir')

I am trying to get the requireDir by calling require('require-dir') and am getting the following error:

"Cannot read property 'filename' of undefined".

For some reason, my module.parent is always being undefined - hence the problem.

Am I trying to require requireDir in the wrong context?

ES6 version

Are you planning to upgrade this library to ES6? Is there a similar version of this library written in ES6? Thanks

Blows up if directory doesn't exist

I was using requireDir to include optional files into my project. Over the course of time, all of those optional files ended up getting removed, so the directory itself was lost by git, and then my project suddenly stopped working. Took me awhile to track down the cause. In my case, adding a .gitkeep to the directory is an acceptable solution. But, I propose that there be some sort of error handling if a directory doesn't exist. Maybe return an empty object or null instead of completely blowing up. Example;

Error: ENOENT, no such file or directory '/somedirectorythatdoesntexist'

require.extensions deprecated usage

Thanks for the module, it is simple to use and very useful.

The code internally uses require.extensions but it is actually deprecated and has been for quite a while.
In my case, this behavior conflicts with jest, that replaces require.extensions by an empty object.

Instead of having to use require.extensions, it would be nice to be able to pass an object (an array?) in the options to describe the extensions we would like to require. It would have two benefits, first partially remove the usage of a deprecated feature, and second allow to easily ignore files based on their extensions.

Its not hard, but if you're open for it, I can work on a PR.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.