register_loader.js 639 B

123456789101112131415161718192021222324
  1. const rechoir = require('rechoir');
  2. module.exports = function(eventEmitter, extensions, configPath, cwd) {
  3. extensions = extensions || {};
  4. if (typeof configPath !== 'string') {
  5. return;
  6. }
  7. var autoloads = rechoir.prepare(extensions, configPath, cwd, true);
  8. if (autoloads instanceof Error) {
  9. autoloads = autoloads.failures;
  10. }
  11. if (Array.isArray(autoloads)) {
  12. autoloads.forEach(function (attempt) {
  13. if (attempt.error) {
  14. eventEmitter.emit('requireFail', attempt.moduleName, attempt.error);
  15. } else {
  16. eventEmitter.emit('require', attempt.moduleName, attempt.module);
  17. }
  18. });
  19. }
  20. };