Socket
Socket
Sign inDemoInstall

require-dir

Package Overview
Dependencies
Maintainers
2
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

require-dir - npm Package Compare versions

Comparing version 1.0.0 to 1.1.0

test/noCache.js

5

index.js

@@ -116,2 +116,7 @@ // requireDir.js

// delete cache
if (opts.noCache) {
delete require.cache[abs];
}
// if duplicates are wanted, key off the full name always, and

@@ -118,0 +123,0 @@ // also the base if it hasn't been taken yet (since this ext

2

package.json
{
"name": "require-dir",
"description": "Helper to require() directories.",
"version": "1.0.0",
"version": "1.1.0",
"author": "Aseem Kishore <aseem.kishore@gmail.com>",

@@ -6,0 +6,0 @@ "license": "MIT",

@@ -25,8 +25,9 @@ [![Build Status](https://travis-ci.org/aseemk/requireDir.svg?branch=master)](https://travis-ci.org/aseemk/requireDir)

```js
{ a: require('./dir/a.js')
, b: require('./dir/b.json')
{
a: require('./dir/a.js'),
b: require('./dir/b.json')
}
```
And if CoffeeScript has been registered via `require('coffee-script/register')`,
If CoffeeScript is registered via `require('coffee-script/register')`,
`c.coffee` will also be returned. Any extension registered with node will work the same way without any additional configuration.

@@ -55,3 +56,3 @@

```js
var dir = requireDir('./path/to/dir', {recurse: true});
var dir = requireDir('./path/to/dir', { recurse: true });
```

@@ -65,21 +66,2 @@

`duplicates`: By default, if multiple files share the same basename, only the
highest priority one is `require()`'d and returned. (Priority is determined by
the order of `require.extensions` keys, with directories taking precedence
over files if `recurse` is true.) Specifying this option `require()`'s all
files and returns full filename keys in addition to basename keys.
Default is false.
E.g. in the example above, if there were also an `a.json`, the behavior would
be the same by default, but specifying `duplicates: true` would yield:
```js
{ a: require('./dir/a.js')
, 'a.js': require('./dir/a.js')
, 'a.json': require('./dir/a.json')
, b: require('./dir/b.json')
, 'b.json': require('./dir/b.json')
}
```
`filter`: Apply a filter on the filename before require-ing. For example, ignoring files prefixed with `dev` in a production environment:

@@ -115,31 +97,36 @@

## Tips
`duplicates`: By default, if multiple files share the same basename, only the
highest priority one is `require()`'d and returned. (Priority is determined by
the order of `require.extensions` keys, with directories taking precedence
over files if `recurse` is true.) Specifying this option `require()`'s all
files and returns full filename keys in addition to basename keys.
Default is false.
If you want to `require()` the same directory in multiple places, you can do
this in the directory itself! Just make an `index.js` file with the following:
In the example above, if there were also an `a.json`, the behavior would
be the same by default, but specifying `duplicates: true` would yield:
```js
module.exports = require('require-dir')(); // defaults to '.'
{
a: require('./dir/a.js'),
'a.js': require('./dir/a.js'),
'a.json': require('./dir/a.json'),
b: require('./dir/b.json'),
'b.json': require('./dir/b.json')
}
```
And don't worry, the calling file is always ignored to prevent infinite loops.
`noCache`: Prevent file caching. Could be useful using gulp.watch or other watch requiring refreshed file content Default is false.
## TODO
```js
requireDir('./dir', { noCache: true })
```
It'd be awesome if this could work with the regular `require()`, e.g. like a
regular `require()` hook. Not sure that's possible though; directories are
already special-cased to look for an `index` file or `package.json`.
## Tips
An `ignore` option would be nice: a string or regex, or an array of either or
both, of paths, relative to the directory, to ignore. String paths can be
extensionless to ignore all extensions for that path. Supporting shell-style
globs in string paths would be nice.
Make an `index.js` in a directory with this code to clean things up:
Currently, basenames are derived for directories too — e.g. a directory named
`a.txt` will be returned as `a` when recursing — but should that be the case?
Maybe directories should always be returned by their full name, and/or maybe
this behavior should be customizable. This is hopefully an edge case.
```js
module.exports = require('require-dir')(); // defaults to '.'
```
## License
MIT. &copy; 2012-2015 Aseem Kishore.
And don't worry, the calling file is always ignored to prevent infinite loops.

@@ -13,3 +13,3 @@ var assert = require('assert');

// on ordering of tests, and require.extensions and require.cache are global.
require('coffee-script');
require('coffee-script/register');
assert.deepEqual(requireDir('./simple'), {

@@ -16,0 +16,0 @@ a: 'a',

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc