Skip to content

Commit

Permalink
refactor: preserve resolveFilename args accurately
Browse files Browse the repository at this point in the history
  • Loading branch information
privatenumber committed Jun 30, 2024
1 parent e0b581c commit 23ebe7e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
19 changes: 9 additions & 10 deletions src/cjs/api/module-resolve-filename.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,11 +160,10 @@ export const createResolveFilename = (
): ResolveFilename => (
request,
parent,
isMain,
options,
...restOfArgs
) => {
if (state.enabled === false) {
return nextResolve(request, parent, isMain, options);
return nextResolve(request, parent, ...restOfArgs);
}

request = interopCjsExports(request);
Expand All @@ -176,7 +175,8 @@ export const createResolveFilename = (
if (parent?.filename) {
const filePath = getOriginalFilePath(parent.filename);
if (filePath) {
const newFilename = filePath.split('?')[0];
const pathAndQuery = filePath.split('?');
const newFilename = pathAndQuery[0];

/**
* Can't delete the old cache entry because there's an assertion
Expand Down Expand Up @@ -204,7 +204,7 @@ export const createResolveFilename = (

// If request namespace doesnt match the namespace, ignore
if ((searchParams.get('namespace') ?? undefined) !== namespace) {
return nextResolve(request, parent, isMain, options);
return nextResolve(request, parent, ...restOfArgs);
}

let _nextResolve = nextResolve;
Expand All @@ -222,8 +222,7 @@ export const createResolveFilename = (
const resolve: SimpleResolve = request_ => _nextResolve(
request_,
parent,
isMain,
options,
...restOfArgs,
);

let resolved = resolveRequest(requestAndQuery[0], parent, resolve);
Expand All @@ -232,9 +231,9 @@ export const createResolveFilename = (
if (
path.isAbsolute(resolved)

// These two have native loaders which don't support queries
&& !resolved.endsWith('.json')
&& !resolved.endsWith('.node')
// These two have native loaders which don't support queries
&& !resolved.endsWith('.json')
&& !resolved.endsWith('.node')
) {
resolved += urlSearchParamsStringify(searchParams);
}
Expand Down
8 changes: 6 additions & 2 deletions src/esm/api/register.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,12 @@ export const register: Register = (
if (!cjsInteropApplied) {
const { _resolveFilename } = module;
module._resolveFilename = (
request, _parent, _isMain, _options,
) => _resolveFilename(interopCjsExports(request), _parent, _isMain, _options);
request,
...restOfArgs
) => _resolveFilename(
interopCjsExports(request),
...restOfArgs,
);
cjsInteropApplied = true;
}

Expand Down

0 comments on commit 23ebe7e

Please sign in to comment.