55
}
56
addDirectory(
58
>
req: Function,
59
>
callerFile: string,
60
>
opts?: RequireDirectoryOptions
61
>
): void {
62
>
opts = opts || {};
63
>
this.requireCache.add(callerFile);
64
>
const fullDirPath = this.shim.path.resolve(
65
>
this.shim.path.dirname(callerFile),
66
>
dir
67
>
);
68
>
const files = this.shim.readdirSync(fullDirPath, {
69
>
recursive: opts.recurse ? true : false,
70
>
});
71
>
// exclude 'json', 'coffee' from require-directory defaults
72
>
if (!Array.isArray(opts.extensions)) opts.extensions = ['js'];
73
>
// allow consumer to define their own visitor function
74
>
const visit = typeof opts.visit === 'function' ? opts.visit : (o: any) => o;
75
>
for (const fileb of files) {
76
>
const file = fileb.toString();
77
>
78
>
// Support include / exclude logic from require-directory.
79
>
if (opts.exclude) {
80
let exclude = false;
81
if (typeof opts.exclude === 'function') {