-
Notifications
You must be signed in to change notification settings - Fork 53
fix: fix a couple issues with duplicate entries and specifier (submodule) matching #237
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
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
…mproved import(cjs) export sniffing
…ine, but CI currently tests v21 which did NOT get sufficient backports to work for these test files
timfish
previously approved these changes
Jan 24, 2026
BridgeAR
reviewed
Jan 24, 2026
Comment on lines
+157
to
+163
| } else if (baseDir.endsWith(specifiers.get(filename))) { | ||
| // An import of the top-level module (e.g. `import 'ioredis'`). | ||
| // Note: Slight behaviour difference from RITM. RITM uses | ||
| // `require.resolve(name)` to see if `filename` is the module | ||
| // main file, which will catch `require('ioredis/built/index.js')`. | ||
| // The check here will not catch `import 'ioredis/built/index.js'`. | ||
| callHookFn(hookFn, namespace, name, baseDir) |
Member
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think matching this with RITM would be good. I would be fine to do that as a follow-up PR.
Contributor
Author
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
BridgeAR
approved these changes
Jan 26, 2026
1 task
timfish
approved these changes
Jan 27, 2026
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This clarifies the hook matching section (as discussed a bit at #187 (comment)) and fixes a couple issues when the Hook arg has duplicate entries or matches a module and a sub-module (and
internals: trueis being used).Prerequisites
require-in-the-middle(#194)" #236 gets merged first (i.e. thatexperimentalPatchInternalshas been dropped). I'll deal with merge conflicts if/when that is in.Details
1. Change specifier (sub-module) match to return
name==specifierGiven this hook that matches sub-module imports / entry points:
Currently the on-import callback gets these
namevalues:This PR changes the returned
nameto be the specifier:Which strikes me as more useful when using specifier matching. Otherwise a single hook that matches multiple entry-points in the same package couldn't differentiate with the
namewhich was hooked.2. Fix behaviour of
internals: truewhen there are duplicate module entriesGiven:
Currently the Hook returns matches for each entry:
However, with
internals:true:This get messed up (because
namevar handling in the match loop is keeping state,assuming there will only ever be one match).
The same issue also leads to bogus
namevalues when a module and an entry-point in that module are being matched:Results in:
This PR fixes both those cases (the part using
internalPathinstead of mutatingname).