Skip to content

feat: support output.dynamicImportInCjs option#7677

Merged
shulaoda merged 1 commit intomainfrom
12-28-feat_add_dynamicimportincjs_option
Dec 29, 2025
Merged

feat: support output.dynamicImportInCjs option#7677
shulaoda merged 1 commit intomainfrom
12-28-feat_add_dynamicimportincjs_option

Conversation

@shulaoda
Copy link
Member

@shulaoda shulaoda commented Dec 28, 2025

closes #6511

Wait #7655 to be resolved

Copy link
Member Author


How to use the Graphite Merge Queue

Add the label graphite: merge-when-ready to this PR to add it to the merge queue.

You must have a Graphite account in order to use the merge queue. Sign up using this link.

An organization admin has enabled the Graphite Merge Queue in this repository.

Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue.

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

@shulaoda shulaoda changed the title feat: add dynamicImportInCjs option feat: add output.dynamicImportInCjs option Dec 28, 2025
@netlify
Copy link

netlify bot commented Dec 28, 2025

Deploy Preview for rolldown-rs ready!

Name Link
🔨 Latest commit 7adaf48
🔍 Latest deploy log https://app.netlify.com/projects/rolldown-rs/deploys/69531172440e5c000807b04d
😎 Deploy Preview https://deploy-preview-7677--rolldown-rs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@shulaoda shulaoda force-pushed the 12-28-feat_add_dynamicimportincjs_option branch 2 times, most recently from 64cf34b to c017834 Compare December 29, 2025 07:53
@shulaoda shulaoda marked this pull request as ready for review December 29, 2025 08:01
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 PR adds a new output.dynamicImportInCjs option to control how dynamic imports of external modules are handled when outputting to CommonJS format.

  • Adds dynamicImportInCjs boolean option (default: true) to preserve current behavior
  • When set to false, converts external module dynamic imports from native import() to Promise.resolve().then(() => __toESM(require()))
  • Updates all TypeScript/Rust infrastructure to support the new option

Reviewed changes

Copilot reviewed 22 out of 22 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
packages/rolldown/tests/cli/snapshots/cli-e2e.test.ts.snap Adds CLI flag for the new option
packages/rolldown/src/utils/validator.ts Adds schema validation for dynamicImportInCjs option
packages/rolldown/src/utils/bindingify-output-options.ts Passes the option to Rust binding
packages/rolldown/src/options/output-options.ts Adds TypeScript interface definition
packages/rolldown/src/options/normalized-output-options.ts Adds normalized option getter
packages/rolldown/src/binding.d.cts Updates TypeScript bindings with new option
crates/rolldown_testing_config/src/config_variant.rs Adds option to test configuration
crates/rolldown_testing/_config.schema.json Updates JSON schema for test configs
crates/rolldown_common/src/inner_bundler_options/types/normalized_bundler_options.rs Adds field with default value of true
crates/rolldown_common/src/inner_bundler_options/mod.rs Adds option to bundler options struct
crates/rolldown_binding/src/utils/normalize_binding_options.rs Normalizes option from JavaScript
crates/rolldown_binding/src/types/binding_normalized_options.rs Exposes option getter to JavaScript
crates/rolldown_binding/src/options/binding_output_options/mod.rs Adds option to binding output options
crates/rolldown/tests/snapshots/integration_rolldown__filename_with_hash.snap Updates hash snapshot with new test
crates/rolldown/tests/rolldown/cjs_compat/dynamic_import_in_cjs/main.js Test input with three dynamic import scenarios
crates/rolldown/tests/rolldown/cjs_compat/dynamic_import_in_cjs/internal.js Internal ESM module for testing
crates/rolldown/tests/rolldown/cjs_compat/dynamic_import_in_cjs/internal-cjs.js Internal CJS module for testing
crates/rolldown/tests/rolldown/cjs_compat/dynamic_import_in_cjs/artifacts.snap Expected output showing require-based polyfills
crates/rolldown/tests/rolldown/cjs_compat/dynamic_import_in_cjs/_config.json Test config with dynamicImportInCjs: false
crates/rolldown/src/utils/prepare_build_context.rs Sets default value to true when normalizing
crates/rolldown/src/stages/link_stage/reference_needed_symbols.rs References __toESM helper when option is false
crates/rolldown/src/module_finalizers/mod.rs Implements conversion logic for external module dynamic imports

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@shulaoda shulaoda changed the title feat: add output.dynamicImportInCjs option feat: support output.dynamicImportInCjs option Dec 29, 2025
@github-actions
Copy link
Contributor

github-actions bot commented Dec 29, 2025

Benchmarks Rust

  • target: main(ccec059)
  • pr: 12-28-feat_add_dynamicimportincjs_option(7adaf48)
group                                                        pr                                     target
-----                                                        --                                     ------
bundle/bundle@multi-duplicated-top-level-symbol              1.00     61.7±1.40ms        ? ?/sec    1.04     63.9±1.80ms        ? ?/sec
bundle/bundle@multi-duplicated-top-level-symbol-sourcemap    1.00     68.6±1.74ms        ? ?/sec    1.03     70.5±1.72ms        ? ?/sec
bundle/bundle@rome_ts                                        1.00    105.8±2.31ms        ? ?/sec    1.01    107.2±1.64ms        ? ?/sec
bundle/bundle@rome_ts-sourcemap                              1.00    117.0±1.72ms        ? ?/sec    1.02    119.5±1.64ms        ? ?/sec
bundle/bundle@threejs                                        1.01     39.4±2.30ms        ? ?/sec    1.00     39.2±0.73ms        ? ?/sec
bundle/bundle@threejs-sourcemap                              1.00     42.4±0.77ms        ? ?/sec    1.01     42.7±0.58ms        ? ?/sec
bundle/bundle@threejs10x                                     1.00    387.6±4.89ms        ? ?/sec    1.02    395.2±7.45ms        ? ?/sec
bundle/bundle@threejs10x-sourcemap                           1.00    447.0±3.79ms        ? ?/sec    1.02    454.1±4.28ms        ? ?/sec
scan/scan@rome_ts                                            1.00     83.9±1.62ms        ? ?/sec    1.02     85.8±1.74ms        ? ?/sec
scan/scan@threejs                                            1.00     29.0±1.77ms        ? ?/sec    1.00     28.9±1.73ms        ? ?/sec
scan/scan@threejs10x                                         1.00    293.4±4.73ms        ? ?/sec    1.02    300.2±4.13ms        ? ?/sec

@shulaoda shulaoda force-pushed the 12-28-feat_add_dynamicimportincjs_option branch from c017834 to 7adaf48 Compare December 29, 2025 23:40
@shulaoda shulaoda merged commit 567fd28 into main Dec 29, 2025
34 checks passed
@shulaoda shulaoda deleted the 12-28-feat_add_dynamicimportincjs_option branch December 29, 2025 23:55
IWANABETHATGUY pushed a commit that referenced this pull request Dec 30, 2025
This was referenced Dec 31, 2025
shulaoda added a commit that referenced this pull request Dec 31, 2025
## [1.0.0-beta.58] - 2025-12-31

### 💥 BREAKING CHANGES

- experimental/devtools: rename InputOptions#debug to InputOptions#devtools (#7686) by @Copilot

### 🚀 Features

- implement target feature check in `should_transform_js` for raw options (#7697) by @shulaoda
- support `output.dynamicImportInCjs` option (#7677) by @shulaoda
- types: expose `ChecksOptions` type (#7653) by @sapphi-red

### 🐛 Bug Fixes

- export runtime helpers for cross-chunk access (#7658) by @shulaoda
- cjs namespace merging regression (#7665) by @IWANABETHATGUY
- replace panic with proper error handling for hash placeholder generation (#7661) by @shulaoda
- remove the blank line between shebang and postBanner (#7643) by @btea
- rolldown_plugin_vite_reporter: apply padding before ANSI coloring for proper size column alignment (#7649) by @shulaoda

### 🚜 Refactor

- rust: use `StableModuleId` as the map key if possible (#7718) by @hyf0
- rust: return `StableModuleId` instead of `&str` from `Module#stable_id()` (#7717) by @hyf0
- rust: return correct stable id of external module from `Module#stable_id()` (#7716) by @hyf0
- rust: introduce `StableModuleId` type (#7715) by @hyf0
- rust: reduce unnecessary `id.as_arc_str().clone().into()` (#7714) by @hyf0
- rust: remove `ModuleId#resource_id` and use `as_arc_str` directly (#7710) by @hyf0
- rust: remove unused `Module#id_clone` (#7709) by @hyf0
- rust: remove `Module#id_as_str` and use `Module#id` directly (#7708) by @hyf0
- consolidate namespace call analysis into import analyzer (#7657) by @IWANABETHATGUY
- rust: make `ExternalModule#id` have the type `ModuleId` (#7707) by @hyf0
- rust: rename `Module#id` to `Module#id_as_str` (#7706) by @hyf0
- rust: use `ModuleId` instead of raw `ArcStr` for `ScanStageCache` (#7701) by @hyf0
- simplify error propagation in cache merge (#7702) by @shulaoda
- use `ModuleId` as the type of `ResolvedId#id` (#7694) by @hyf0
- types: rename `resolved_request_info.rs` to `resolved_id.rs` and move its contents (#7687) by @hyf0
- devtools: emit data to `<CWD>/node_modules/.rolldown` (#7692) by @hyf0
- use `InvalidOption` for hash placeholder generation errors (#7674) by @shulaoda
- rolldown_error: remove dependency on rolldown_utils (#7672) by @shulaoda
- use nodejs-built-in-modules v1.0.0 directly in callsites (#7667) by @Boshen

### 📚 Documentation

- migrate input options content from options to auto gen docs (#7663) by @mdong1909
- create reference index page (#7659) by @mdong1909
- tweak auto-generated reference output (#7654) by @sapphi-red
- initialize auto-gen docs (#7252) by @mdong1909

### ⚙️ Miscellaneous Tasks

- deps: update napi (#7705) by @renovate[bot]
- pin Node.js version to 24.12.0 LTS in .node-version file (#7713) by @Copilot
- update esbuild test reasons (#7703) by @sapphi-red
- deps: update crate-ci/typos action to v1.40.1 (#7696) by @renovate[bot]
- deps: update oxc to v0.106.0 (#7512) by @renovate[bot]
- js: replace dprint with oxfmt (#7214) by @Boshen
- deps: update dependency oxlint to v1.36.0 (#7691) by @renovate[bot]
- deps: update github-actions (#7679) by @renovate[bot]
- deps: update npm packages (#7680) by @renovate[bot]
- deps: update rust crates (#7678) by @renovate[bot]
- deps: update oxc resolver to v11.16.2 (#7668) by @renovate[bot]
- add API reference files to knip entry points (#7669) by @Copilot
- deps: update notify (#7651) by @sapphi-red
- add `homepage` field to package.json (#7648) by @trivikr
- deps: update oxc resolver to v11.16.1 (#7647) by @renovate[bot]
- deps: update rolldown-plugin-dts to 0.20.0 (#7645) by @shulaoda

Co-authored-by: shulaoda <165626830+shulaoda@users.noreply.github.com>
graphite-app bot pushed a commit that referenced this pull request Jan 7, 2026
…ults (#7776)

Follow-up to #7677

It seems these are not passing yet.

NOTE: I had to use `--no-verify` to workaround oxc-project/oxc#17729
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Dynamic imports not transformed to require calls when format is cjs

3 participants