fix(hmr): register cjs module exports#4511
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR fixes the HMR registration for CommonJS modules by passing the full module object instead of module.exports. Key changes include updates to test snapshot expectations, changes in the runtime registration implementation, and modifications in the HMR AST finalizers to align with the new registration pattern.
Reviewed Changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| crates/rolldown/tests/snapshots/integration_rolldown__filename_with_hash.snap | Updated snapshot file names to match the new module registration changes |
| crates/rolldown/tests/rolldown/topics/hmr/register_exports/artifacts.snap | Changed registration call from module.exports to module in tests |
| crates/rolldown/tests/rolldown/issues/4129/artifacts.snap | Updated CommonJS module registration to use module rather than module.exports |
| crates/rolldown/src/runtime/runtime-extra-dev.js | Modified registerModule to accept the module object; updated logging and storage |
| crates/rolldown/src/module_finalizers/scope_hoisting/hmr.rs | Adjusted HMR finalization to register modules correctly for CommonJS cases |
| crates/rolldown/src/hmr/hmr_ast_finalizer.rs | Kept HMR AST finalizer in sync with the new module registration design |
Comments suppressed due to low confidence (5)
crates/rolldown/tests/rolldown/topics/hmr/register_exports/artifacts.snap:13
- The registration call now passes the full module object instead of module.exports. Please confirm that all test expectations and downstream consumers are updated accordingly.
__rolldown_runtime__.registerModule("cjs.js", module);
crates/rolldown/tests/rolldown/issues/4129/artifacts.snap:15
- The change from module.exports to module for registerModule should be verified to make sure it aligns with both test expectations and the runtime's usage of the module object.
__rolldown_runtime__.registerModule("lib.js", module);
crates/rolldown/src/runtime/runtime-extra-dev.js:91
- Changing the function signature to accept the module object directly is clear; ensure that all development build consumers are compatible with this updated registration pattern.
registerModule(id, module) {
crates/rolldown/src/module_finalizers/scope_hoisting/hmr.rs:48
- [nitpick] Ensure that the dual handling of CommonJS exports—with one branch creating an object expression for exports and another directly registering the module—is intentional and uniformly applied.
// { exports: namespace }
crates/rolldown/src/hmr/hmr_ast_finalizer.rs:88
- The update to pass the module object instead of module.exports helps in standardizing HMR registration; please verify that this change is consistently reflected in all HMR finalizer branches.
ast::Argument::Identifier(self.snippet.builder.alloc_identifier_reference(SPAN, "module"))
✅ Deploy Preview for rolldown-rs canceled.
|
hyf0
approved these changes
May 12, 2025
Contributor
Benchmarks Rust |
github-merge-queue Bot
pushed a commit
that referenced
this pull request
May 12, 2025
<!-- Thank you for contributing! -->
### Description
<!-- Please insert your description here and provide especially info
about the "what" this PR is solving -->
``` .js
rolldown_runtime.registerModule("cjs.js", module.exports);
module.exports = {
a: 1,
b: 1,
}
```
Fix the case, using the module object to register.
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.
Description
Fix the case, using the module object to register.