From 143a5bd8394154fbaa2bef235168678ad96a6454 Mon Sep 17 00:00:00 2001 From: Hiroki Osame Date: Sun, 30 Jun 2024 11:06:45 +0900 Subject: [PATCH] fix(cjs): isolate implicit resolver enhancement (#59) --- src/cjs/api/module-resolve-filename.ts | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/cjs/api/module-resolve-filename.ts b/src/cjs/api/module-resolve-filename.ts index c3b912487..154cf68b7 100644 --- a/src/cjs/api/module-resolve-filename.ts +++ b/src/cjs/api/module-resolve-filename.ts @@ -167,13 +167,6 @@ export const createResolveFilename = ( return nextResolve(request, parent, isMain, options); } - const resolve: SimpleResolve = request_ => nextResolve( - request_, - parent, - isMain, - options, - ); - request = interopCjsExports(request); if (parent?.filename) { @@ -198,9 +191,10 @@ export const createResolveFilename = ( // If request namespace doesnt match the namespace, ignore if ((searchParams.get('namespace') ?? undefined) !== namespace) { - return resolve(request); + return nextResolve(request, parent, isMain, options); } + let _nextResolve = nextResolve; if (namespace) { /** * When namespaced, the loaders are registered to the extensions in a hidden way @@ -209,9 +203,16 @@ export const createResolveFilename = ( * To support implicit extensions, we need to enhance the resolver with our own * re-implementation of the implicit extension resolution */ - nextResolve = createImplicitResolver(nextResolve); + _nextResolve = createImplicitResolver(_nextResolve); } + const resolve: SimpleResolve = request_ => _nextResolve( + request_, + parent, + isMain, + options, + ); + let resolved = resolveRequest(requestAndQuery[0], parent, resolve); // Only add query back if it's a file path (not a core Node module)