module-require.js 779 B

12345678910111213141516171819202122232425262728293031
  1. 'use strict';
  2. exports.__esModule = true;
  3. const Module = require('module');
  4. const path = require('path');
  5. // borrowed from babel-eslint
  6. function createModule(filename) {
  7. const mod = new Module(filename);
  8. mod.filename = filename;
  9. mod.paths = Module._nodeModulePaths(path.dirname(filename));
  10. return mod;
  11. }
  12. exports.default = function moduleRequire(p) {
  13. try {
  14. // attempt to get espree relative to eslint
  15. const eslintPath = require.resolve('eslint');
  16. const eslintModule = createModule(eslintPath);
  17. return require(Module._resolveFilename(p, eslintModule));
  18. } catch (err) { /* ignore */ }
  19. try {
  20. // try relative to entry point
  21. return require.main.require(p);
  22. } catch (err) { /* ignore */ }
  23. // finally, try from here
  24. return require(p);
  25. };