2023-12-28 23:41:32 +08:00
|
|
|
'use strict';
|
2023-12-18 13:12:25 +08:00
|
|
|
|
2023-12-28 23:41:32 +08:00
|
|
|
exports.__esModule = true;
|
|
|
|
|
|
|
|
const Module = require('module');
|
|
|
|
const path = require('path');
|
2023-12-18 13:12:25 +08:00
|
|
|
|
|
|
|
// borrowed from babel-eslint
|
|
|
|
function createModule(filename) {
|
2023-12-28 23:41:32 +08:00
|
|
|
const mod = new Module(filename);
|
|
|
|
mod.filename = filename;
|
|
|
|
mod.paths = Module._nodeModulePaths(path.dirname(filename));
|
|
|
|
return mod;
|
2023-12-18 13:12:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
exports.default = function moduleRequire(p) {
|
|
|
|
try {
|
|
|
|
// attempt to get espree relative to eslint
|
2023-12-28 23:41:32 +08:00
|
|
|
const eslintPath = require.resolve('eslint');
|
|
|
|
const eslintModule = createModule(eslintPath);
|
|
|
|
return require(Module._resolveFilename(p, eslintModule));
|
|
|
|
} catch (err) { /* ignore */ }
|
2023-12-18 13:12:25 +08:00
|
|
|
|
|
|
|
try {
|
|
|
|
// try relative to entry point
|
2023-12-28 23:41:32 +08:00
|
|
|
return require.main.require(p);
|
|
|
|
} catch (err) { /* ignore */ }
|
2023-12-18 13:12:25 +08:00
|
|
|
|
|
|
|
// finally, try from here
|
2023-12-28 23:41:32 +08:00
|
|
|
return require(p);
|
|
|
|
};
|