From f0d126a76bffa8f9455f2d2318464b2420a8f982 Mon Sep 17 00:00:00 2001 From: itsjohncs Date: Wed, 14 Sep 2022 00:21:30 -0700 Subject: [PATCH 1/2] Use original resolver if patched resolver fails. --- ...slint-patch-fallback_2022-09-14-07-30.json | 10 +++++++++ .../src/modern-module-resolution.ts | 22 +++++++++++++++---- 2 files changed, 28 insertions(+), 4 deletions(-) create mode 100644 common/changes/@rushstack/eslint-patch/eslint-patch-fallback_2022-09-14-07-30.json diff --git a/common/changes/@rushstack/eslint-patch/eslint-patch-fallback_2022-09-14-07-30.json b/common/changes/@rushstack/eslint-patch/eslint-patch-fallback_2022-09-14-07-30.json new file mode 100644 index 00000000000..8fd078e6f84 --- /dev/null +++ b/common/changes/@rushstack/eslint-patch/eslint-patch-fallback_2022-09-14-07-30.json @@ -0,0 +1,10 @@ +{ + "changes": [ + { + "packageName": "@rushstack/eslint-patch", + "comment": "Use original resolver if patched resolver fails.", + "type": "major" + } + ], + "packageName": "@rushstack/eslint-patch" +} \ No newline at end of file diff --git a/eslint/eslint-patch/src/modern-module-resolution.ts b/eslint/eslint-patch/src/modern-module-resolution.ts index 41e96143f18..04412c0ea70 100644 --- a/eslint/eslint-patch/src/modern-module-resolution.ts +++ b/eslint/eslint-patch/src/modern-module-resolution.ts @@ -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 { @@ -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 { From 7eca2cc208a9223d9f5950114b0c9674746c6446 Mon Sep 17 00:00:00 2001 From: Ian Clanton-Thuon Date: Wed, 14 Sep 2022 11:07:45 -0700 Subject: [PATCH 2/2] Rush change. --- .../eslint-patch/eslint-patch-fallback_2022-09-14-07-30.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/changes/@rushstack/eslint-patch/eslint-patch-fallback_2022-09-14-07-30.json b/common/changes/@rushstack/eslint-patch/eslint-patch-fallback_2022-09-14-07-30.json index 8fd078e6f84..761cc538efb 100644 --- a/common/changes/@rushstack/eslint-patch/eslint-patch-fallback_2022-09-14-07-30.json +++ b/common/changes/@rushstack/eslint-patch/eslint-patch-fallback_2022-09-14-07-30.json @@ -3,7 +3,7 @@ { "packageName": "@rushstack/eslint-patch", "comment": "Use original resolver if patched resolver fails.", - "type": "major" + "type": "minor" } ], "packageName": "@rushstack/eslint-patch"