Reputation: 55
I'm looking at a require() function that looks like this and I have no clue what it does. It seems like it gets an array of files and builds a string of some try-catch blocks with interpolated module names, but I'm a bit hazy on the specifics.
require('./modules/**/index.js', {mode: (base, files) => {
return files.map(module => {
return `
try {
require('${module}');
} catch (e) {
debug.error('Failed to ${module}', e.stack);
}
`;
}).join(' ');
}});
I looked for params in the Node documentation (https://nodejs.org/api/modules.html#modules_require_id) and couldn't find anything. Anyone have any ideas?
Upvotes: 0
Views: 144
Reputation: 433
It's not a regular require.
It's a require-globify
package. It allows globbing expressions to require. mode
key of second parameter defines how to handle the calls.
Upvotes: 1