Skip to content

Commit

Permalink
escape + char at regexp to resolve pnpn issue
Browse files Browse the repository at this point in the history
  • Loading branch information
bumblehead committed Oct 17, 2024
1 parent fc9f380 commit 4a87be8
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# changelog

* 2.6.8 _tbd_
* 2.6.8 _Oct.17.2024_
* [resolve issue for pnpm](https://github.com/iambumblehead/esmock/pull/314) by escaping '+' char in regexp
* [add log utility function](https://github.com/iambumblehead/esmock/pull/314) for debugging loader
* [dropped ava and jest](https://github.com/iambumblehead/esmock/pull/314) from test sequence, node v22 --loader issues
* 2.6.7 _Jul.16.2024_
Expand Down
7 changes: 6 additions & 1 deletion src/esmockLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,14 @@ const isnotfoundRe = /isfound=false/
const iscommonjsmoduleRe = /^(commonjs|module)$/
const isstrict3 = /strict=3/
const hashbangRe = /^(#![^\n]*\n)/

// escape '+' char, pnpm generates long pathnames serialized with these
const moduleIdEsc = str =>
str.indexOf('+') >= 0 ? str.replace(/(?!\\)\+/g, '\\+') : str

// returned regexp will match embedded moduleid w/ treeid
const moduleIdReCreate = (moduleid, treeid) => new RegExp(
`.*(${moduleid}(\\?${treeid}(?:(?!#-#).)*)).*`)
`.*(${moduleIdEsc(moduleid)}(\\?${treeid}(?:(?!#-#).)*)).*`)

// node v12.0-v18.x, global
const mockKeys = global.mockKeys = (global.mockKeys || {})
Expand Down

0 comments on commit 4a87be8

Please sign in to comment.