Skip to content

fix(hmr): register cjs module exports#4511

Merged
underfin merged 1 commit into
mainfrom
fix-hmr-module-exports-cjs
May 12, 2025
Merged

fix(hmr): register cjs module exports#4511
underfin merged 1 commit into
mainfrom
fix-hmr-module-exports-cjs

Conversation

@underfin

Copy link
Copy Markdown
Contributor

Description

rolldown_runtime.registerModule("cjs.js", module.exports);
module.exports = {
  a: 1,
  b: 1,
}

Fix the case, using the module object to register.

Copilot AI review requested due to automatic review settings May 12, 2025 07:26
@underfin underfin enabled auto-merge May 12, 2025 07:27

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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"))

@netlify

netlify Bot commented May 12, 2025

Copy link
Copy Markdown

Deploy Preview for rolldown-rs canceled.

Name Link
🔨 Latest commit b006bb2
🔍 Latest deploy log https://app.netlify.com/sites/rolldown-rs/deploys/6821a2bfb4d10f000826a1e9

@underfin underfin added this pull request to the merge queue May 12, 2025
@github-actions

Copy link
Copy Markdown
Contributor

Benchmarks Rust

group                                                               pr                                     target
-----                                                               --                                     ------
bundle/bundle@multi-duplicated-top-level-symbol                     1.00     76.3±2.46ms        ? ?/sec    1.01     77.1±2.40ms        ? ?/sec
bundle/bundle@multi-duplicated-top-level-symbol-minify              1.06    101.6±3.85ms        ? ?/sec    1.00     95.9±1.54ms        ? ?/sec
bundle/bundle@multi-duplicated-top-level-symbol-minify-sourcemap    1.01    110.7±1.47ms        ? ?/sec    1.00    109.7±1.46ms        ? ?/sec
bundle/bundle@multi-duplicated-top-level-symbol-sourcemap           1.00     86.9±2.17ms        ? ?/sec    1.00     87.1±1.41ms        ? ?/sec
bundle/bundle@rome-ts                                               1.00    119.5±1.96ms        ? ?/sec    1.00    119.5±2.18ms        ? ?/sec
bundle/bundle@rome-ts-minify                                        1.00    199.0±6.33ms        ? ?/sec    1.03    205.4±8.82ms        ? ?/sec
bundle/bundle@rome-ts-minify-sourcemap                              1.00    230.7±4.95ms        ? ?/sec    1.06   244.4±11.07ms        ? ?/sec
bundle/bundle@rome-ts-sourcemap                                     1.00    133.9±2.06ms        ? ?/sec    1.00    133.3±2.70ms        ? ?/sec
bundle/bundle@threejs                                               1.00     39.8±0.53ms        ? ?/sec    1.00     39.7±0.50ms        ? ?/sec
bundle/bundle@threejs-minify                                        1.00     83.0±0.44ms        ? ?/sec    1.00     82.7±0.97ms        ? ?/sec
bundle/bundle@threejs-minify-sourcemap                              1.01     99.0±0.67ms        ? ?/sec    1.00     97.9±1.13ms        ? ?/sec
bundle/bundle@threejs-sourcemap                                     1.02     47.4±1.09ms        ? ?/sec    1.00     46.6±0.25ms        ? ?/sec
bundle/bundle@threejs10x                                            1.01    428.0±6.84ms        ? ?/sec    1.00    424.7±6.85ms        ? ?/sec
bundle/bundle@threejs10x-minify                                     1.01  1047.2±25.16ms        ? ?/sec    1.00   1035.5±5.75ms        ? ?/sec
bundle/bundle@threejs10x-minify-sourcemap                           1.01   1220.2±6.40ms        ? ?/sec    1.00   1206.6±7.25ms        ? ?/sec
bundle/bundle@threejs10x-sourcemap                                  1.00    493.6±3.35ms        ? ?/sec    1.00    491.5±5.63ms        ? ?/sec
remapping/remapping                                                 1.03     27.1±1.35ms        ? ?/sec    1.00     26.3±0.33ms        ? ?/sec
remapping/render-chunk-remapping                                    1.00     64.6±0.66ms        ? ?/sec    1.08     69.7±5.42ms        ? ?/sec
scan/scan@rome-ts                                                   1.00     90.1±0.96ms        ? ?/sec    1.04     93.6±2.15ms        ? ?/sec
scan/scan@threejs                                                   1.00     30.3±0.42ms        ? ?/sec    1.03     31.0±0.86ms        ? ?/sec
scan/scan@threejs10x                                                1.00    311.4±4.34ms        ? ?/sec    1.00    310.6±3.70ms        ? ?/sec

Merged via the queue into main with commit 66f4623 May 12, 2025
35 checks passed
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.
@underfin underfin deleted the fix-hmr-module-exports-cjs branch May 12, 2025 07:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants