Files
react-native-devtools-frontend/node_modules/requireindex/index.js
T
Tim van der Lippe 10714b5729 Upgrade eslint-plugin-lit-a11y
This pulls in the fix for https://github.com/open-wc/open-wc/issues/2206
which reduces the size of our node_modules significantly.

R=jacktfranklin@chromium.org

Bug: none
Change-Id: Id19be5e7ed6398ffd2edb1d08b4752ef6a1d6b17
Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/3268293
Auto-Submit: Tim van der Lippe <tvanderlippe@chromium.org>
Reviewed-by: Jack Franklin <jacktfranklin@chromium.org>
Commit-Queue: Tim van der Lippe <tvanderlippe@chromium.org>
2021-11-08 15:56:59 +00:00

61 lines
1.6 KiB
JavaScript

var FS = require('fs');
var Path = require('path');
module.exports = function (dir, basenames) {
var requires = {};
if (arguments.length === 2) {
// if basenames argument is passed, explicitly include those files
basenames.forEach(function (basename) {
var filepath = Path.resolve(Path.join(dir, basename));
requires[basename] = require(filepath);
});
} else if (arguments.length === 1) {
// if basenames arguments isn't passed, require all javascript
// files (except for those prefixed with _) and all directories
var files = FS.readdirSync(dir);
// sort files in lowercase alpha for linux
files.sort(function (a,b) {
a = a.toLowerCase();
b = b.toLowerCase();
if (a < b) {
return -1;
} else if (b < a) {
return 1;
} else {
return 0;
}
});
files.forEach(function (filename) {
// ignore index.js and files prefixed with underscore and
if ((filename === 'index.js') || (filename[0] === '_') || (filename[0] === '.')) {
return;
}
var filepath = Path.resolve(Path.join(dir, filename));
var ext = Path.extname(filename);
var stats = FS.statSync(filepath);
// don't require non-javascript files (.txt .md etc.)
var exts = ['.js', '.node', '.json'];
if (stats.isFile() && (exts.indexOf(ext) === -1)) {
return;
}
var basename = Path.basename(filename, ext);
requires[basename] = require(filepath);
});
} else {
throw new Error("Must pass directory as first argument");
}
return requires;
};