Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 92f182b

Browse filesBrowse files
guybedfordBethGriggs
authored andcommitted
module: fix $ pattern replacements
PR-URL: #40044 Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Zeyu Yang <himself65@outlook.com>
1 parent 4367a61 commit 92f182b
Copy full SHA for 92f182b

File tree

Expand file treeCollapse file tree

2 files changed

+8
-5
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

2 files changed

+8
-5
lines changed
Open diff view settings
Collapse file

‎lib/internal/modules/esm/resolve.js‎

Copy file name to clipboardExpand all lines: lib/internal/modules/esm/resolve.js
+6-5Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ const {
1010
ObjectGetOwnPropertyNames,
1111
ObjectPrototypeHasOwnProperty,
1212
RegExp,
13+
RegExpPrototypeSymbolReplace,
1314
RegExpPrototypeTest,
1415
SafeMap,
1516
SafeSet,
@@ -18,7 +19,6 @@ const {
1819
StringPrototypeIncludes,
1920
StringPrototypeIndexOf,
2021
StringPrototypeLastIndexOf,
21-
StringPrototypeReplace,
2222
StringPrototypeSlice,
2323
StringPrototypeSplit,
2424
StringPrototypeStartsWith,
@@ -470,7 +470,7 @@ function resolvePackageTargetString(
470470
} catch {}
471471
if (!isURL) {
472472
const exportTarget = pattern ?
473-
StringPrototypeReplace(target, patternRegEx, subpath) :
473+
RegExpPrototypeSymbolReplace(patternRegEx, target, () => subpath) :
474474
target + subpath;
475475
return packageResolve(exportTarget, packageJSONUrl, conditions);
476476
}
@@ -494,8 +494,8 @@ function resolvePackageTargetString(
494494
throwInvalidSubpath(match + subpath, packageJSONUrl, internal, base);
495495

496496
if (pattern)
497-
return new URL(StringPrototypeReplace(resolved.href, patternRegEx,
498-
subpath));
497+
return new URL(RegExpPrototypeSymbolReplace(patternRegEx, resolved.href,
498+
() => subpath));
499499
return new URL(subpath, resolved);
500500
}
501501

@@ -939,7 +939,8 @@ function resolveAsCommonJS(specifier, parentURL) {
939939
// Normalize the path separator to give a valid suggestion
940940
// on Windows
941941
if (process.platform === 'win32') {
942-
found = StringPrototypeReplace(found, new RegExp(`\\${sep}`, 'g'), '/');
942+
found = RegExpPrototypeSymbolReplace(new RegExp(`\\${sep}`, 'g'),
943+
found, '/');
943944
}
944945
return found;
945946
} catch {
Collapse file

‎test/es-module/test-esm-exports.mjs‎

Copy file name to clipboardExpand all lines: test/es-module/test-esm-exports.mjs
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,8 @@ import fromInside from '../fixtures/node_modules/pkgexports/lib/hole.js';
156156
['pkgexports/no-ext', `pkgexports${sep}asdf`],
157157
// Pattern specificity
158158
['pkgexports/dir2/trailer', `subpath${sep}dir2.js`],
159+
// Pattern double $$ escaping!
160+
['pkgexports/a/$$', `subpath${sep}$$.js`],
159161
]);
160162

161163
if (!isRequire) {

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.