-
Notifications
You must be signed in to change notification settings - Fork 26
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
fix: Skip wrapping CJS modules which result in invalid identifiers #115
base: main
Are you sure you want to change the base?
fix: Skip wrapping CJS modules which result in invalid identifiers #115
Conversation
…nvalid-indentifiers
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.
If such modules are rare, how did the issue get exposed?
@@ -56,6 +56,7 @@ | |||
"acorn": "^8.8.2", | |||
"acorn-import-attributes": "^1.9.5", | |||
"cjs-module-lexer": "^1.2.2", | |||
"module-details-from-path": "^1.0.3" | |||
"module-details-from-path": "^1.0.3", | |||
"@babel/helper-validator-identifier": "^7.24.7" |
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.
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.
Bump
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.
We could vendor this code and it's around 13kB.
This package has 50m weekly downloads so there's a high chance it will already be in many users dependencies.
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 package has 50m weekly downloads so there's a high chance it will already be in many users dependencies.
Maybe. But I've never seen the package before this PR. I looked through it back when this PR was opened, and I remember getting the impression that it could be overkill. So I wanted an opinion from the folks much more in tune with this code than I am.
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'm fine with it, though I wonder if we really need all that and not just a simplified subset of it.
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.
If these are the only examples we have, it suggests it's quite uncommon but its prevalent enough for it to cause issues for users. |
Thank you. |
👋 Is the blocker on this PR still waiting for reviews from specific folks? Anything that can be done to move that along? Happy to help where I can. This change is still required to fix a bug in Sentry that is blocking us, as I understand it. |
@@ -56,6 +56,7 @@ | |||
"acorn": "^8.8.2", | |||
"acorn-import-attributes": "^1.9.5", | |||
"cjs-module-lexer": "^1.2.2", | |||
"module-details-from-path": "^1.0.3" | |||
"module-details-from-path": "^1.0.3", | |||
"@babel/helper-validator-identifier": "^7.24.7" |
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'm fine with it, though I wonder if we really need all that and not just a simplified subset of it.
FWIW, it looks like this:
With --trace-warnings:
If I know about the ...
register('./hook.mjs', import.meta.url, {
data: {
exclude: [/fixtures\/invalid-identifier.js$/]
}
}) Then, no more warning:
|
This doesn't need to block this PR, but my guess is this kind of message:
being seen by end users will result in support issues for us. :) That might be alleviated somewhat by getting that closer to something like (taking away the words "Error" and "failed"):
|
That would be possible with this diff: diff --git a/hook.js b/hook.js
index b5d72f5..93664b8 100644
--- a/hook.js
+++ b/hook.js
@@ -428,7 +428,8 @@ register(${JSON.stringify(realUrl)}, _, set, ${JSON.stringify(specifiers.get(rea
//
// We log the error because there might be bugs in iitm and without this
// it would be very tricky to debug
- const err = new Error(`'import-in-the-middle' failed to wrap '${realUrl}'`)
+ const err = new Error(`'import-in-the-middle' could not wrap '${realUrl}'`)
+ err.name = 'Warning'
err.cause = cause
emitWarning(err)
|
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.
Thanks!
Closes #94
Rather than trying to find a way to only export invalid identifiers in versions of Node that support exports with names like this, this PR simply skips wrapping these modules. Since modules that use exports like this are rare, it's unlikely anyone will ever want to
Hook
them and if they do we can revisit this later.@babel/helper-validator-identifier
was chosen to check for invalid identifiers because the code looks good, it sees 50m+ downloads per week, it's tested, it has no dependencies and maybe most importantly, it's CommonJs!