register_loader.js 678 B

123456789101112131415161718192021222324
  1. var 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) { // Only errors
  9. autoloads.failures.forEach(function(failed) {
  10. eventEmitter.emit('requireFail', failed.moduleName, failed.error);
  11. });
  12. return;
  13. }
  14. if (!Array.isArray(autoloads)) { // Already required or no config.
  15. return;
  16. }
  17. var succeeded = autoloads[autoloads.length - 1];
  18. eventEmitter.emit('require', succeeded.moduleName, succeeded.module);
  19. };