Skip to content

Commit

Permalink
Merge pull request #3628 from itsjohncs/eslint-patch-fallback
Browse files Browse the repository at this point in the history
[eslint-patch] Use original resolver if patched resolver fails.
  • Loading branch information
iclanton authored Sep 14, 2022
2 parents f299343 + 7eca2cc commit c0c0de4
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@rushstack/eslint-patch",
"comment": "Use original resolver if patched resolver fails.",
"type": "minor"
}
],
"packageName": "@rushstack/eslint-patch"
}
22 changes: 18 additions & 4 deletions eslint/eslint-patch/src/modern-module-resolution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,8 +209,15 @@ if (!ConfigArrayFactory.__patched) {
const originalResolve = ModuleResolver.resolve;
try {
ModuleResolver.resolve = function (moduleName: string, relativeToPath: string) {
// resolve using importerPath instead of relativeToPath
return originalResolve.call(this, moduleName, importerPath);
try {
// resolve using importerPath instead of relativeToPath
return originalResolve.call(this, moduleName, importerPath);
} catch (e) {
if (isModuleResolutionError(e)) {
return originalResolve.call(this, moduleName, relativeToPath);
}
throw e;
}
};
return originalLoadPlugin.apply(this, arguments);
} finally {
Expand All @@ -223,8 +230,15 @@ if (!ConfigArrayFactory.__patched) {
const originalResolve = ModuleResolver.resolve;
try {
ModuleResolver.resolve = function (moduleName: string, relativeToPath: string) {
// resolve using ctx.filePath instead of relativeToPath
return originalResolve.call(this, moduleName, ctx.filePath);
try {
// resolve using ctx.filePath instead of relativeToPath
return originalResolve.call(this, moduleName, ctx.filePath);
} catch (e) {
if (isModuleResolutionError(e)) {
return originalResolve.call(this, moduleName, relativeToPath);
}
throw e;
}
};
return originalLoadPlugin.apply(this, arguments);
} finally {
Expand Down

0 comments on commit c0c0de4

Please sign in to comment.