Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

module: fix $ pattern replacements #40044

Closed
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/internal/modules/esm/resolve.js
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ function resolvePackageTargetString(
} catch {}
if (!isURL) {
const exportTarget = pattern ?
StringPrototypeReplace(target, patternRegEx, subpath) :
StringPrototypeReplace(target, patternRegEx, () => subpath) :
guybedford marked this conversation as resolved.
Show resolved Hide resolved
target + subpath;
return packageResolve(exportTarget, packageJSONUrl, conditions);
}
Expand All @@ -486,7 +486,7 @@ function resolvePackageTargetString(

if (pattern)
return new URL(StringPrototypeReplace(resolved.href, patternRegEx,
guybedford marked this conversation as resolved.
Show resolved Hide resolved
subpath));
() => subpath));
return new URL(subpath, resolved);
}

Expand Down
2 changes: 2 additions & 0 deletions test/es-module/test-esm-exports.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,8 @@ import fromInside from '../fixtures/node_modules/pkgexports/lib/hole.js';
['pkgexports/no-ext', `pkgexports${sep}asdf`],
// Pattern specificity
['pkgexports/dir2/trailer', `subpath${sep}dir2.js`],
// Pattern double $$ escaping!
['pkgexports/a/$$', `subpath${sep}$$.js`],
]);

if (!isRequire) {
Expand Down