Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Nov 10, 2025

chunk.imports in both the renderChunk and generateBundle hooks was returning original external module IDs instead of applying the output.paths transformation. Additionally, the generated code for dynamic imports and require calls was not applying the transformation. This diverged from Rollup behavior.

// With output.paths configured
output: {
  paths: { react: 'react/index.js' }
}

// Before: 
// - chunk.imports = ['react']
// - import('react') in generated code

// After:  
// - chunk.imports = ['react/index.js']
// - import('react/index.js') in generated code

Changes

  • Core fixes:

    • finalize_chunks.rs now calls ExternalModule::get_file_name(paths) instead of Module::id() when populating external imports in OutputChunk (for generateBundle hook)
    • mod.rs (chunk utils) now calls ExternalModule::get_file_name(paths) instead of Module::id() when populating external imports in RenderedChunk (for renderChunk hook)
    • module_finalizers/mod.rs now passes options.paths to get_import_path() for dynamic imports, require calls, and re-export statements in generated code
  • Test coverage: Added tests for both object and function forms of output.paths with assertions for both renderChunk and generateBundle hooks to verify chunk.imports reflects transformed paths

  • Rollup compatibility: Enabled 3 Rollup test cases that now pass (mixed-external-paths, paths, paths-relative). Moved 2 tests to snapshot differences section (paths-function has different variable naming, re-export-own has unrelated hasOwnProperty behavior difference)

  • Fixes [Bug]: bundle.imports of generateBundle hook missing output.paths modify #6916

Original prompt

This section details on the original issue you should resolve

<issue_title>[Bug]: bundle.imports of generateBundle hook missing output.paths modify</issue_title>
<issue_description>### Reproduction link or steps

This is the reproduce link, run pnpm build

Image

It's not the same with rollup.

What is expected?

Same with the rollup. the imports should use paths modify, output: [ 'react/index.js' ]

What is actually happening?

output original: [ 'react' ]

System Info

System:
    OS: Linux 5.0 undefined
    CPU: (8) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
    Memory: 0 Bytes / 0 Bytes
    Shell: 1.0 - /bin/jsh
  Binaries:
    Node: 20.19.1 - /usr/local/bin/node
    Yarn: 1.22.19 - /usr/local/bin/yarn
    npm: 10.8.2 - /usr/local/bin/npm
    pnpm: 8.15.6 - /usr/local/bin/pnpm
  npmPackages:
    @rolldown/browser:  1.0.0-beta.47

Any additional comments?

No response</issue_description>

Comments on the Issue (you are @copilot in this section)


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

@graphite-app
Copy link
Contributor

graphite-app bot commented Nov 10, 2025

How to use the Graphite Merge Queue

Add the label graphite: merge 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.

@netlify
Copy link

netlify bot commented Nov 10, 2025

Deploy Preview for rolldown-rs ready!

Name Link
🔨 Latest commit d895dab
🔍 Latest deploy log https://app.netlify.com/projects/rolldown-rs/deploys/6912f0213626080008d9fa79
😎 Deploy Preview https://deploy-preview-6923--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.

Copilot AI changed the title [WIP] Fix bundle.imports missing output.paths modify in generateBundle Fix: apply output.paths transformation to bundle.imports in generateBundle hook Nov 10, 2025
Copilot AI requested a review from IWANABETHATGUY November 10, 2025 17:32
@github-actions
Copy link
Contributor

github-actions bot commented Nov 11, 2025

Benchmarks Rust

  • target: main(e1bc3f7)
  • pr: copilot/fix-bundle-imports-output-paths(d895dab)
group                                                        pr                                     target
-----                                                        --                                     ------
bundle/bundle@multi-duplicated-top-level-symbol              1.02     65.9±1.74ms        ? ?/sec    1.00     64.5±1.50ms        ? ?/sec
bundle/bundle@multi-duplicated-top-level-symbol-sourcemap    1.01     72.3±1.39ms        ? ?/sec    1.00     71.3±1.12ms        ? ?/sec
bundle/bundle@rome_ts                                        1.00    107.6±1.44ms        ? ?/sec    1.01    108.2±1.93ms        ? ?/sec
bundle/bundle@rome_ts-sourcemap                              1.00    120.8±2.29ms        ? ?/sec    1.01    122.3±2.80ms        ? ?/sec
bundle/bundle@threejs                                        1.00     40.2±2.66ms        ? ?/sec    1.00     40.2±2.38ms        ? ?/sec
bundle/bundle@threejs-sourcemap                              1.00     42.9±0.90ms        ? ?/sec    1.00     43.1±0.77ms        ? ?/sec
bundle/bundle@threejs10x                                     1.00    392.5±4.15ms        ? ?/sec    1.01    395.6±4.19ms        ? ?/sec
bundle/bundle@threejs10x-sourcemap                           1.00    452.9±3.96ms        ? ?/sec    1.00    454.9±3.70ms        ? ?/sec
scan/scan@rome_ts                                            1.00     88.3±1.49ms        ? ?/sec    1.00     87.9±1.37ms        ? ?/sec
scan/scan@threejs                                            1.00     29.1±0.37ms        ? ?/sec    1.01     29.4±1.25ms        ? ?/sec
scan/scan@threejs10x                                         1.00    303.4±4.25ms        ? ?/sec    1.00    304.8±4.34ms        ? ?/sec

@IWANABETHATGUY IWANABETHATGUY force-pushed the copilot/fix-bundle-imports-output-paths branch from 08198a9 to bc8efb9 Compare November 11, 2025 02:49
@IWANABETHATGUY IWANABETHATGUY changed the title Fix: apply output.paths transformation to bundle.imports in generateBundle hook fix: apply output.paths transformation to bundle.imports in generateBundle hook Nov 11, 2025
@IWANABETHATGUY IWANABETHATGUY marked this pull request as ready for review November 11, 2025 03:28
Copy link
Member

@sapphi-red sapphi-red left a comment

Choose a reason for hiding this comment

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

Maybe we can also enable some of these tests?

### The `output.paths` is not supported
- rollup@function@re-export-own: avoid using export.hasOwnProperty
- rollup@function@mixed-external-paths: allows using the path option selectively
- rollup@form@paths-function: external paths (#754)@generates es
- rollup@form@paths-relative: external paths (#754)@generates es
- rollup@form@paths: external paths (#754)@generates es

Copy link
Contributor Author

Copilot AI commented Nov 11, 2025

Maybe we can also enable some of these tests?
https://github.com/rolldown/rolldown/blob/3d1985ab40923590b3ae9f626b2438d9543dc588/packages/rollup-tests/src/ignored-by-unsupported-features.md?plain=1#L...

Enabled all 5 Rollup tests for output.paths by removing them from the ignored features list. Commit: 67683fa

Copilot AI changed the title fix: apply output.paths transformation to bundle.imports in generateBundle hook fix: apply output.paths transformation to chunk.imports in renderChunk and generateBundle hooks Nov 11, 2025
@IWANABETHATGUY
Copy link
Member

@copilot, investigate why the test failed.

Copy link
Contributor Author

Copilot AI commented Nov 11, 2025

@copilot, investigate why the test failed.

Investigated and fixed the test failures:

Root cause: The output.paths transformation was only being applied to the chunk.imports metadata field, but not to the actual generated code for dynamic imports and require calls.

Fixes applied (commit 7292044):

  1. Updated dynamic import generation to use output.paths (import('foo')import('https://unpkg.com/foo'))
  2. Updated require call generation to use output.paths
  3. Updated re-export statements to use output.paths

Test results:

  • ✅ 3 Rollup tests now pass: mixed-external-paths, paths, paths-relative
  • ⚠️ 2 tests moved to "snapshot differences" section (fail for non-paths reasons):
    • paths-function: paths work correctly, but uses different variable names (foo$1 vs foo)
    • re-export-own: unrelated hasOwnProperty behavior difference

Copilot AI changed the title fix: apply output.paths transformation to chunk.imports in renderChunk and generateBundle hooks fix: apply output.paths transformation to chunk.imports and generated code Nov 11, 2025
Copilot AI and others added 6 commits November 11, 2025 13:40
Co-authored-by: IWANABETHATGUY <[email protected]>
- Fixed dynamic import paths transformation to use output.paths option
- Fixed require() calls to use output.paths option
- Fixed re-export statements to use output.paths option
- Updated ignored tests list: kept 2 tests that fail for non-paths reasons (variable naming and hasOwnProperty behavior)
- 3 paths-related Rollup tests now pass: mixed-external-paths, paths, paths-relative

Co-authored-by: IWANABETHATGUY <[email protected]>
@IWANABETHATGUY IWANABETHATGUY force-pushed the copilot/fix-bundle-imports-output-paths branch from 7292044 to 3fc69bb Compare November 11, 2025 05:40
@IWANABETHATGUY IWANABETHATGUY marked this pull request as draft November 11, 2025 06:16
@IWANABETHATGUY IWANABETHATGUY marked this pull request as ready for review November 11, 2025 07:37
@IWANABETHATGUY IWANABETHATGUY enabled auto-merge (squash) November 11, 2025 07:37
@IWANABETHATGUY IWANABETHATGUY merged commit 6da74d2 into main Nov 11, 2025
27 checks passed
@IWANABETHATGUY IWANABETHATGUY deleted the copilot/fix-bundle-imports-output-paths branch November 11, 2025 08:29
shulaoda pushed a commit that referenced this pull request Nov 12, 2025
## [1.0.0-beta.50] - 2025-11-12

### 🚀 Features

- rolldown: oxc_resolver v11.13.2 (#6956) by @Boshen
- rolldown: oxc v0.97.0 (#6940) by @Boshen

### 🐛 Bug Fixes

- handle error when creating output chunk directories (#6953) by @sapphi-red
- throw error if `experimental.hmr` is set for APIs other than `dev` (#6860) by @Copilot
- apply output.paths transformation to chunk.imports and generated code (#6923) by @Copilot

### 🚜 Refactor

- use `anyhow::Context::context` where applicable (#6952) by @sapphi-red
- dev: use actor design pattern and allow to recover from intial build error (#6936) by @hyf0

### 📚 Documentation

- add sitemap (#6929) by @mdong1909

### 🧪 Testing

- validate publishConfig.exports matches exports field (#6950) by @Copilot
- re-enable output/paths/function test (#6934) by @Copilot

### ⚙️ Miscellaneous Tasks

- rename `rolldown_watcher` to `rolldown_fs_watcher` (#6958) by @hyf0
- enable trust policy (#6948) by @iiio2
- deps: update napi (#6951) by @renovate[bot]
- deps: update dependency rolldown-plugin-dts to v0.17.6 (#6947) by @renovate[bot]
- deps: update npm packages (#6937) by @renovate[bot]
- deps: update dependency tsdown to v0.16.2 (#6933) by @renovate[bot]

### ❤️ New Contributors

* @mdong1909 made their first contribution in [#6929](#6929)

Co-authored-by: sapphi-red <[email protected]>
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.

[Bug]: bundle.imports of generateBundle hook missing output.paths modify

3 participants