-
-
Notifications
You must be signed in to change notification settings - Fork 611
fix(commonjs): guard moduleSideEffects for wrapped externals #1914
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| module.exports = { | ||
| description: | ||
| 'does not crash and does not mark external node: builtins as pure when strictRequires is true', | ||
| pluginOptions: { | ||
| strictRequires: true | ||
| }, | ||
| context: { | ||
| __filename: __filename | ||
| } | ||
| }; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| // Top-level require of a Node builtin ensures the transform computes | ||
| // wrappedModuleSideEffects for an external wrapped dependency. | ||
| function unused() { | ||
| // External Node builtin require; not executed at runtime | ||
| require('node:crypto'); | ||
| } | ||
|
|
||
| module.exports = 1; | ||
|
Comment on lines
+1
to
+8
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This fixture places SuggestionConsider changing the fixture to keep the require call present but not executed, so the snapshot can assert that it is not annotated as pure: // Keep the require present in the output without executing it
if (Math.random() < 0) require('node:crypto');
module.exports = 1;This will exercise the |
||
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.
The description states the test "does not mark external node: builtins as pure when strictRequires is true", but there is no assertion or reliable snapshot evidence of this yet (because the require is currently tree‑shaken). Either clarify the description to focus on the non‑crash behavior, or adopt the suggested fixture change so the snapshot also verifies that no
/*@__PURE__*/annotation is emitted.Suggestion
You can update the description to reflect how this is validated via snapshot:
Alternatively, keep the description and adopt the
main.jschange so the snapshot actually proves the absence of the purity annotation. Reply with "@CharlieHelps yes please" if you'd like me to add a commit with this suggestion