Skip to content

Comments

refactor(hmr): using __esModule to mark esm module exports#4445

Merged
underfin merged 2 commits intomainfrom
05-08-refactor_hmr_using___esmodule_to_mark_esm_module_exports
May 8, 2025
Merged

refactor(hmr): using __esModule to mark esm module exports#4445
underfin merged 2 commits intomainfrom
05-08-refactor_hmr_using___esmodule_to_mark_esm_module_exports

Conversation

@underfin
Copy link
Contributor

@underfin underfin commented May 8, 2025

Description

Here should follow the babel semantics to mark esm module exports. it will make sure our module exports is compat to other bundlers, eg module federation moduels.

Copy link
Contributor Author

underfin commented May 8, 2025

This stack of pull requests is managed by Graphite. Learn more about stacking.

@netlify
Copy link

netlify bot commented May 8, 2025

Deploy Preview for rolldown-rs canceled.

Name Link
🔨 Latest commit a273030
🔍 Latest deploy log https://app.netlify.com/sites/rolldown-rs/deploys/681c800e7c402a0008c79263

@underfin underfin marked this pull request as ready for review May 8, 2025 09:12
Copilot AI review requested due to automatic review settings May 8, 2025 09:12
@underfin underfin enabled auto-merge May 8, 2025 09:12
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This pull request refactors the HMR module registration to use the __esModule flag to mark ESM exports, ensuring consistency with Babel semantics for module federation and improved interoperation with other bundlers.

  • Updated snapshot files to reflect changes in module filename hashes and __esModule flags.
  • Removed the meta parameter from the registerModule function and added a new canonical_exports_len method in linking_metadata.
  • Updated HMR-related module finalizers to include __esModule property when building export objects.

Reviewed Changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
crates/rolldown/tests/snapshots/integration_rolldown__filename_with_hash.snap Updated filename hash in snapshot to accommodate refactored module exports.
crates/rolldown/tests/rolldown/topics/hmr/register_exports/artifacts.snap Adjusted module export registration by adding __esModule flag.
crates/rolldown/tests/rolldown/issues/4129/artifacts.snap Updated module registration for lib.js and main.js to include __esModule flag.
crates/rolldown/src/types/linking_metadata.rs Added a helper method to compute the length of canonical exports.
crates/rolldown/src/runtime/runtime-extra-dev.js Removed the meta parameter from registerModule to simplify module export handling.
crates/rolldown/src/module_finalizers/scope_hoisting/hmr.rs Updated object builder with reserved capacity and appended __esModule flag.
crates/rolldown/src/hmr/hmr_ast_finalizer.rs Adjusted export object construction to include __esModule flag.
Comments suppressed due to low confidence (1)

crates/rolldown/src/runtime/runtime-extra-dev.js:91

  • The meta parameter has been removed from registerModule, which eliminates the separate handling for CommonJS modules. Please update the function documentation and ensure tests cover both ESM and CJS scenarios, confirming that this behavior is intentional.
registerModule(id, esmExportGettersOrCjsExports) {

@github-actions
Copy link
Contributor

github-actions bot commented May 8, 2025

Benchmarks Rust

  • target: main(7e5b6d5)
  • pr: 05-08-refactor_hmr_using___esmodule_to_mark_esm_module_exports(a273030)
group                                                               pr                                     target
-----                                                               --                                     ------
bundle/bundle@multi-duplicated-top-level-symbol                     1.00     76.7±1.75ms        ? ?/sec    1.09     83.7±3.98ms        ? ?/sec
bundle/bundle@multi-duplicated-top-level-symbol-minify              1.00     97.9±1.10ms        ? ?/sec    1.03    101.2±2.10ms        ? ?/sec
bundle/bundle@multi-duplicated-top-level-symbol-minify-sourcemap    1.01    112.0±1.38ms        ? ?/sec    1.00    110.4±1.60ms        ? ?/sec
bundle/bundle@multi-duplicated-top-level-symbol-sourcemap           1.00     87.3±1.82ms        ? ?/sec    1.08     93.9±3.74ms        ? ?/sec
bundle/bundle@rome-ts                                               1.02    121.4±1.63ms        ? ?/sec    1.00    119.5±2.16ms        ? ?/sec
bundle/bundle@rome-ts-minify                                        1.00    196.0±2.50ms        ? ?/sec    1.08    210.8±7.79ms        ? ?/sec
bundle/bundle@rome-ts-minify-sourcemap                              1.00    230.7±2.67ms        ? ?/sec    1.05   241.1±13.10ms        ? ?/sec
bundle/bundle@rome-ts-sourcemap                                     1.02    134.0±1.13ms        ? ?/sec    1.00    132.0±1.37ms        ? ?/sec
bundle/bundle@threejs                                               1.10     45.4±1.65ms        ? ?/sec    1.00     41.3±2.22ms        ? ?/sec
bundle/bundle@threejs-minify                                        1.01     84.8±1.77ms        ? ?/sec    1.00     83.7±0.70ms        ? ?/sec
bundle/bundle@threejs-minify-sourcemap                              1.00    101.5±3.55ms        ? ?/sec    1.03    104.7±2.08ms        ? ?/sec
bundle/bundle@threejs-sourcemap                                     1.02     48.5±0.71ms        ? ?/sec    1.00     47.3±0.19ms        ? ?/sec
bundle/bundle@threejs10x                                            1.00    428.5±5.50ms        ? ?/sec    1.00    427.6±4.69ms        ? ?/sec
bundle/bundle@threejs10x-minify                                     1.00   1052.4±4.32ms        ? ?/sec    1.01  1058.9±13.83ms        ? ?/sec
bundle/bundle@threejs10x-minify-sourcemap                           1.01   1240.2±4.98ms        ? ?/sec    1.00   1230.7±7.67ms        ? ?/sec
bundle/bundle@threejs10x-sourcemap                                  1.00    504.6±8.21ms        ? ?/sec    1.01    507.4±7.71ms        ? ?/sec
remapping/remapping                                                 1.00     25.1±0.29ms        ? ?/sec    1.01     25.3±0.14ms        ? ?/sec
remapping/render-chunk-remapping                                    1.14     71.9±6.15ms        ? ?/sec    1.00     63.1±0.27ms        ? ?/sec
scan/scan@rome-ts                                                   1.03     94.9±2.94ms        ? ?/sec    1.00     92.4±1.36ms        ? ?/sec
scan/scan@threejs                                                   1.01     31.5±1.69ms        ? ?/sec    1.00     31.1±1.26ms        ? ?/sec
scan/scan@threejs10x                                                1.01    316.0±6.25ms        ? ?/sec    1.00    313.8±2.83ms        ? ?/sec

@underfin underfin added this pull request to the merge queue May 8, 2025
@underfin underfin removed this pull request from the merge queue due to a manual request May 8, 2025
@underfin underfin added this pull request to the merge queue May 8, 2025
@underfin underfin removed this pull request from the merge queue due to a manual request May 8, 2025
@underfin underfin added this pull request to the merge queue May 8, 2025
Merged via the queue into main with commit 5f36b1d May 8, 2025
30 checks passed
@underfin underfin deleted the 05-08-refactor_hmr_using___esmodule_to_mark_esm_module_exports branch May 8, 2025 11:16
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.

2 participants