feat(commonjs)!: revert PR #1909 and add requireNodeBuiltins option#1
Closed
feat(commonjs)!: revert PR #1909 and add requireNodeBuiltins option#1
Conversation
Co-authored-by: sapphi-red <49056869+sapphi-red@users.noreply.github.com>
Co-authored-by: sapphi-red <49056869+sapphi-red@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Revert and reapply changes with new option
feat(commonjs)!: revert PR #1909 and add requireNodeBuiltins option
Oct 26, 2025
9 tasks
Owner
|
@copilot add |
Co-authored-by: sapphi-red <49056869+sapphi-red@users.noreply.github.com>
Author
Added 3 new test fixtures with
These test the default behavior where node: builtins are treated as regular externals without createRequire injection. Snapshots will need to be generated locally (non-CI environment). Commit: 92634ff |
Owner
|
@copilot re-run tests to generate the snapshot and commit it |
Co-authored-by: sapphi-red <49056869+sapphi-red@users.noreply.github.com>
Author
Snapshots generated successfully. All 285 tests passing (282 original + 3 new variant tests). Generated snapshots for:
Commit: bd43a20 |
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
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.
Summary
Successfully implemented the
requireNodeBuiltinsoption to address issue rollup#1924 by reverting PR rollup#1909's automatic createRequire injection and making it opt-in.Completed Tasks
requireNodeBuiltins(boolean, default: false) to typesTest Coverage
Created 3 new test fixtures to verify default behavior (requireNodeBuiltins: false):
strict-requires-external-node-builtin-default- Tests dead code elimination without createRequirestrict-requires-auto-external-node-builtin-default- Tests hoisting with strictRequires: automodule-side-effects-external-node-builtin-wrapped-default- Tests side effects handlingAll snapshots generated and all tests passing (285/285).
Implementation Details
Option:
requireNodeBuiltins: boolean(default:false)Behavior:
false(default): External Node built-ins likenode:fsare treated as regular externals, avoiding thenode:moduledependency. This is safe for edge runtimes.true: UsescreateRequire(import.meta.url)for lazy loading, matching PR fix(commonjs): avoid hoisting dynamically required node: builtins under strictRequires rollup/plugins#1909 behavior. Addsnode:moduledependency.Files Modified:
packages/commonjs/types/index.d.ts- Added type definitionpackages/commonjs/src/index.js- Read option and apply conditionallypackages/commonjs/src/resolve-require-sources.js- Conditional special handlingpackages/commonjs/README.md- Comprehensive documentationTesting
Next Steps
Ready for maintainer review and merge.
Original prompt
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.