-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpatch-eslint6.js
45 lines (41 loc) · 1.35 KB
/
patch-eslint6.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
const path = require("path");
let currentModule = module;
while (
!/[\\/]eslint[\\/]lib[\\/]cli-engine[\\/]config-array-factory\.js/i.test(
currentModule.filename
)
) {
if (!currentModule.parent) {
// This was tested with ESLint 6.1.0; other versions may not work
throw new Error(
"Failed to patch ESLint because the calling module was not recognized"
);
}
currentModule = currentModule.parent;
}
const eslintFolder = path.join(path.dirname(currentModule.filename), "../..");
const configArrayFactoryPath = path.join(
eslintFolder,
"lib/cli-engine/config-array-factory"
);
const configArrayFactoryModule = require(configArrayFactoryPath);
const moduleResolverPath = path.join(eslintFolder, "lib/shared/relative-module-resolver");
const ModuleResolver = require(moduleResolverPath);
const originalLoadPlugin =
configArrayFactoryModule.ConfigArrayFactory.prototype._loadPlugin;
configArrayFactoryModule.ConfigArrayFactory.prototype._loadPlugin = function (
name,
importerPath,
importerName
) {
const originalResolve = ModuleResolver.resolve;
try {
ModuleResolver.resolve = function (moduleName, relativeToPath) {
// resolve using importerPath instead of relativeToPath
return originalResolve.call(this, moduleName, importerPath);
};
return originalLoadPlugin.apply(this, arguments);
} finally {
ModuleResolver.resolve = originalResolve;
}
};