Skip to content

Commit

Permalink
[#59] Add an optional extensions parameter to use instead of extensions
Browse files Browse the repository at this point in the history
  • Loading branch information
richardgarnier committed Nov 26, 2018
1 parent 48b583a commit 868a07f
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ module.exports = function requireDir(dir, opts) {
// to the map using the full filename as a key also.
var map = {};

// get the array of extensions we need to require
var extensions = opts.extensions || Object.keys(require.extensions);

for (var base in filesForBase) {
// protect against enumerable object prototype extensions:
if (!filesForBase.hasOwnProperty(base)) {
Expand Down Expand Up @@ -95,13 +98,7 @@ module.exports = function requireDir(dir, opts) {
}

// otherwise, go through and try each require.extension key!
for (ext in require.extensions) {
// Node v8+ uses "clean" objects w/o hasOwnProperty for require
// again protect against enumerable object prototype extensions:
if (!Object.prototype.hasOwnProperty.call(require.extensions, ext)) {
continue;
}

for (ext of extensions) {
// if a file exists with this extension, we'll require() it:
var file = base + ext;
var abs = filesMinusDirs[file];
Expand Down

0 comments on commit 868a07f

Please sign in to comment.