Skip to content

Commit

Permalink
refactor(resolve): uses Maps for the context maps
Browse files Browse the repository at this point in the history
  • Loading branch information
sverweij committed Dec 1, 2024
1 parent 0d49477 commit 2d2b0e5
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions src/extract/resolve/resolve.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,19 @@ import enhancedResolve from "enhanced-resolve";
import { stripQueryParameters } from "../helpers.mjs";
import pathToPosix from "#utl/path-to-posix.mjs";

let gResolvers = {};
let gInitialized = {};
let gResolvers = new Map();
let gInitialized = new Map();

function init(pEHResolveOptions, pCachingContext) {
if (!gInitialized[pCachingContext] || pEHResolveOptions.bustTheCache) {
if (!gInitialized.get(pCachingContext) || pEHResolveOptions.bustTheCache) {
// assuming the cached file system here
pEHResolveOptions.fileSystem.purge();
gResolvers[pCachingContext] =
enhancedResolve.ResolverFactory.createResolver(pEHResolveOptions);
gResolvers.set(
pCachingContext,
enhancedResolve.ResolverFactory.createResolver(pEHResolveOptions),
);
/* eslint security/detect-object-injection:0 */
gInitialized[pCachingContext] = true;
gInitialized.set(pCachingContext, true);
}
}

Expand All @@ -35,7 +37,7 @@ export function resolve(
init(pResolveOptions, pCachingContext);

return stripQueryParameters(
gResolvers[pCachingContext].resolveSync(
gResolvers.get(pCachingContext).resolveSync(
{},
// lookupStartPath
pathToPosix(pFileDirectory),
Expand All @@ -46,6 +48,6 @@ export function resolve(
}

export function clearCache() {
gInitialized = {};
gResolvers = {};
gInitialized.clear();
gResolvers.clear();
}

0 comments on commit 2d2b0e5

Please sign in to comment.