- 
          
 - 
                Notifications
    
You must be signed in to change notification settings  - Fork 611
 
fix(commonjs): avoid hoisting dynamically required node: builtins under strictRequires #1909
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(commonjs): avoid hoisting dynamically required node: builtins under strictRequires #1909
Conversation
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.
No issues identified in the provided diff since it only includes a snapshot update with binary changes omitted. Without visible source or snapshot content, there’s nothing actionable to review. If there are logic changes tied to this snapshot, they are not shown here.
Summary of changes
Snapshot updates
- Updated test snapshot: 
packages/commonjs/test/snapshots/function.js.snap. 
No source code changes are visible in the provided diff; only snapshot output changed (details omitted).
| 
           @CharlieHelps you need to rebase from upstream/master to pull in the workflow changes that mitigate the workflow run error  | 
    
          Expand this to see my work.
  | 
    
…er strictRequires
- Treat external node: builtins as wrapped requires only when the parent module is wrapped (strictRequires or dynamic require), so requires are left lazy via a __require helper and resolved with createRequire instead of top-level ESM imports.
- Add getExternalBuiltinRequireProxy to emit a proxy that exports a lazy __require for builtins.
- Keep non-strict behavior unchanged to preserve existing unresolved-import warnings (e.g., require("path")).
- Add test: strict-requires-external-node-builtin.
    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.
@CharlieHelps have you identified any breaking changes here?
          Expand this to see my work.
  | 
    
7e38149    to
    923b19e      
    Compare
  
    | 
           Rebased the branch onto the latest  
 A fresh Actions run should kick off with the mitigations applied. What I ran# Update and rebase
git fetch --prune origin
git rebase origin/master
git push --force-with-lease origin ai-1900-rollup-plugin-commonjs-strictrequires-shou
# Package-level verification for the changed plugin
pnpm -C packages/commonjs build
pnpm -C packages/commonjs test
pnpm -C packages/commonjs test:tsVerification # Build: success
$ pnpm -C packages/commonjs build
# Tests: 280/280 passed
$ pnpm -C packages/commonjs test
# Type tests: success
$ pnpm -C packages/commonjs test:tsLet me know if you want me to re-run anything else or scope checks differently.  | 
    
| 
           Short answer: No breaking changes identified. 
 Notes
  | 
    
…1937) * Initial plan * Add requireNodeBuiltins option to control createRequire injection Co-authored-by: sapphi-red <49056869+sapphi-red@users.noreply.github.com> * Address code review feedback - use explicit boolean checks Co-authored-by: sapphi-red <49056869+sapphi-red@users.noreply.github.com> * Add requireNodeBuiltins: false variant tests for 3 fixtures Co-authored-by: sapphi-red <49056869+sapphi-red@users.noreply.github.com> * Generate snapshots for requireNodeBuiltins: false variant tests Co-authored-by: sapphi-red <49056869+sapphi-red@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
This fixes #1900 by ensuring that dynamically required Node built-ins (via
node:*) are not hoisted whenstrictRequireswraps the requiring module.Changes
strictRequiresor dynamic-require), treat externalnode:*specifiers as "wrapped" requires so the transform rewrites calls to a lazy__require().getExternalBuiltinRequireProxy(id)that exports a lazy__requireimplemented withcreateRequire(import.meta.url). This avoids top-levelimport 'node:*'and therefore avoids runtime crashes on older Node versions (e.g.,node:sqliteon Node 20).require('path')) are preserved.strict-requires-external-node-builtin.Verification