-
Notifications
You must be signed in to change notification settings - Fork 29.6k
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
lib: fix Module check when monkey patching #50109
Conversation
Review requested:
|
|
||
/** @type {RequireFunction} */ | ||
let require; | ||
if (redirects) { | ||
if (mod instanceof Module !== true) { | ||
throw new ERR_INVALID_ARG_TYPE('mod', 'Module', mod); | ||
} |
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.
This doesn’t seem correct; there’s another reference to mod
in the else
branch farther down; why would we validate the input only for this branch and not that one?
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.
This was added specifically to solve 15bced0bde. Since this check didn't exist previously I think it's safe to ignore the other branches.
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.
Well at the very least it looks like a mistake; if I were refactoring this, I would instinctively move the check to the top of the function. There should be a comment explaining why mod
is always defined for if (redirects)
but only sometimes defined otherwise.
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.
What's missing is a test that would fail if this check was at the top of the function.
Longer term, nyc needs to migrate to the module customization hooks rather than monkey patching. We do not and will not support monkey patching Node internals. The hooks are the public API that can enable code coverage. |
Any updates! We don't want to have to migrate to another code coverage tool. |
So, turns out it's not a Please note if you want this to be fixed quickly, consider doing it yourself or sponsoring someone to do so. Also note, that the commit that introduced this behavior was a security fix. There's no way to revert that. I will try to look at |
@RafaelGSS Thank you so much! This is worse as |
So, Considering If someone creates a minimal reproducible code (non-library dependency) I might come up with a solution |
What does this mean? Nyc should be able to migrate to the module customization hooks. That's not a quick fix but it's the long term solution. |
I meant it seems the "patch" would be considered a
:s/nyc/esm |
Well, you’re saying that |
|
Ah, I think I misunderstood. I thought |
It could be the interaction between |
Apparently, the last security release broke the coverage of reports of
nyc
. I'm still waiting for a reproducible example so I can create a test for that, but I am confident this should fix the problem.Fixes: istanbuljs/nyc#1530
cc: @bmeck