Skip to content

Comments

feat: make closeBundle hook receive the last error#7278

Merged
shulaoda merged 2 commits intomainfrom
copilot/add-closebundle-hook-error
Jan 7, 2026
Merged

feat: make closeBundle hook receive the last error#7278
shulaoda merged 2 commits intomainfrom
copilot/add-closebundle-hook-error

Conversation

Copy link
Contributor

Copilot AI commented Dec 1, 2025

Implements rollup/rollup#5867 - the closeBundle hook now receives the error that caused the build to fail.

Changes

Rust core (rolldown_plugin):

  • Add HookCloseBundleArgs struct mirroring HookBuildEndArgs
  • Update Plugin::close_bundle and Pluginable::call_close_bundle signatures to accept optional error args

NAPI bindings:

  • Update JsPlugin to convert errors to BindingError[] format
  • Update TypeScript type: (ctx: BindingPluginContext, error?: BindingError[]) => MaybePromise<VoidNullable>

Call sites:

  • bundle.rs: Pass errors to close_bundle when scan stage fails
  • classic_bundler.rs, bundler.rs: Pass None on explicit close

TypeScript API:

  • Update FunctionPluginHooks.closeBundle signature to (this: PluginContext, error?: Error) => void

Usage

const plugin = {
  name: 'example',
  closeBundle(error) {
    if (error) console.warn('Build failed:', error.message);
  }
}
Original prompt

This section details on the original issue you should resolve

<issue_title>[Feature Request]: make closeBundle hook receive the last error</issue_title>
<issue_description>### What problem does this feature solve?

ref rollup/rollup#5867

What does the proposed API look like?

-</issue_description>

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


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

@graphite-app
Copy link
Contributor

graphite-app bot commented Dec 1, 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 Dec 1, 2025

Deploy Preview for rolldown-rs ready!

Name Link
🔨 Latest commit fb1229d
🔍 Latest deploy log https://app.netlify.com/projects/rolldown-rs/deploys/695e483d97ce880008b9956b
😎 Deploy Preview https://deploy-preview-7278--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] Add closeBundle hook to receive last error feat: make closeBundle hook receive the last error Dec 1, 2025
Copilot AI requested a review from shulaoda December 1, 2025 03:15
@shulaoda shulaoda force-pushed the copilot/add-closebundle-hook-error branch from 8a61208 to d09b742 Compare December 6, 2025 09:59
@github-actions
Copy link
Contributor

github-actions bot commented Dec 6, 2025

Benchmarks Rust

  • target: main(25ffe2a)
  • pr: copilot/add-closebundle-hook-error(fb1229d)
group                                                        pr                                     target
-----                                                        --                                     ------
bundle/bundle@multi-duplicated-top-level-symbol              1.04     67.3±1.63ms        ? ?/sec    1.00     64.5±1.41ms        ? ?/sec
bundle/bundle@multi-duplicated-top-level-symbol-sourcemap    1.04     73.9±1.63ms        ? ?/sec    1.00     70.8±1.31ms        ? ?/sec
bundle/bundle@rome_ts                                        1.02    108.0±2.00ms        ? ?/sec    1.00    106.1±1.62ms        ? ?/sec
bundle/bundle@rome_ts-sourcemap                              1.04    122.7±2.85ms        ? ?/sec    1.00    118.0±2.13ms        ? ?/sec
bundle/bundle@threejs                                        1.01     38.2±2.05ms        ? ?/sec    1.00     37.8±0.67ms        ? ?/sec
bundle/bundle@threejs-sourcemap                              1.02     43.1±0.79ms        ? ?/sec    1.00     42.5±0.53ms        ? ?/sec
bundle/bundle@threejs10x                                     1.01    386.4±3.51ms        ? ?/sec    1.00    383.3±3.90ms        ? ?/sec
bundle/bundle@threejs10x-sourcemap                           1.00    447.8±4.29ms        ? ?/sec    1.00    447.4±3.59ms        ? ?/sec
scan/scan@rome_ts                                            1.00     82.0±1.58ms        ? ?/sec    1.00     82.4±1.50ms        ? ?/sec
scan/scan@threejs                                            1.01     27.7±0.36ms        ? ?/sec    1.00     27.5±0.75ms        ? ?/sec
scan/scan@threejs10x                                         1.00    283.8±4.04ms        ? ?/sec    1.00    282.7±3.69ms        ? ?/sec

@shulaoda shulaoda force-pushed the copilot/add-closebundle-hook-error branch from d09b742 to c891407 Compare December 30, 2025 22:53
@shulaoda shulaoda force-pushed the copilot/add-closebundle-hook-error branch from 7a89df3 to e2409df Compare December 30, 2025 23:01
@shulaoda shulaoda marked this pull request as ready for review December 30, 2025 23:02
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 implements the closeBundle hook error parameter feature from Rollup (rollup/rollup#5867), allowing plugins to receive error information when a build fails.

Key changes:

  • Added error parameter to closeBundle hook signature across Rust, NAPI bindings, and TypeScript APIs
  • Error information is passed when scan stage failures occur
  • Maintains backward compatibility by making the error parameter optional

Reviewed changes

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

Show a summary per file
File Description
crates/rolldown_plugin/src/types/hook_close_bundle_args.rs New struct to hold error diagnostics and cwd for closeBundle hook
crates/rolldown_plugin/src/types/mod.rs Export new HookCloseBundleArgs type
crates/rolldown_plugin/src/plugin.rs Updated Plugin trait to accept optional HookCloseBundleArgs
crates/rolldown_plugin/src/pluginable.rs Updated Pluginable trait signatures for closeBundle
crates/rolldown_plugin/src/plugin_driver/output_hooks.rs Updated plugin driver to pass error args to closeBundle
crates/rolldown_plugin/src/lib.rs Added HookCloseBundleArgs to public exports
crates/rolldown_binding/src/options/plugin/js_plugin.rs Convert Rust errors to BindingError array for JavaScript plugins
crates/rolldown_binding/src/options/plugin/binding_plugin_options.rs Updated NAPI type signature to accept optional error array
crates/rolldown/src/bundle/bundle.rs Pass errors to closeBundle when scan stage fails
crates/rolldown/src/bundler/bundler.rs Pass None when explicitly closing (no error case)
crates/rolldown_binding/src/classic_bundler.rs Pass None when explicitly closing (no error case)
packages/rolldown/src/binding.d.cts Updated TypeScript type definition for closeBundle
packages/rolldown/src/plugin/index.ts Updated FunctionPluginHooks.closeBundle to accept optional Error
packages/rolldown/src/plugin/bindingify-output-hooks.ts Convert BindingError array to JavaScript Error when calling user hooks
packages/rolldown/tests/error/error.test.ts Added tests for closeBundle receiving errors on failure and undefined on success

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

@shulaoda shulaoda merged commit b381fe6 into main Jan 7, 2026
34 checks passed
@shulaoda shulaoda deleted the copilot/add-closebundle-hook-error branch January 7, 2026 11:58
This was referenced Jan 14, 2026
shulaoda added a commit that referenced this pull request Jan 14, 2026
## [1.0.0-beta.60] - 2026-01-14

### 💥 BREAKING CHANGES

- tsconfig: enable auto-discovery by default (#7817) by @shulaoda

### 🚀 Features

- distinguish transformer diagnostics from parse errors (#7872) by @shulaoda
- emit transformer warnings instead of ignoring them (#7850) by @shulaoda
- node: add `output.codeSplitting` option and deprecate `output.advancedChunks` (#7855) by @hyf0
- nativeMagicString reset (#7828) by @IWANABETHATGUY
- nativeMagicString lastChar (#7819) by @IWANABETHATGUY
- dev/lazy: inject lazy compilation runtime automatically (#7816) by @hyf0
- nativeMagicString snip (#7818) by @IWANABETHATGUY
- nativeMagicString construct with options (#7814) by @IWANABETHATGUY
- nativeMagicString clone (#7813) by @IWANABETHATGUY
- nativeMagicString `insert` (#7812) by @IWANABETHATGUY
- nativeMagicString `slice` (#7807) by @IWANABETHATGUY
- nativeMagicString trim methods (#7800) by @IWANABETHATGUY
- make closeBundle hook receive the last error (#7278) by @Copilot

### 🐛 Bug Fixes

- when package only contains export default, cjsDefault didn't resolve correctly (#7873) by @IWANABETHATGUY
- inline __name calls for default exports  (#7862) by @IWANABETHATGUY
- improve variable renaming to avoid unnecessary shadowing in nested scopes (#7859) by @IWANABETHATGUY
- use correct index when inserting keepNames statements during export default transformation (#7853) by @IWANABETHATGUY
- transform non-static dynamic imports when `dynamicImportInCjs` is `false` (#7823) by @shulaoda
- dev/lazy: should include imported and non-executed modules in the patch (#7815) by @hyf0
- set ExportsKind to Esm when json is none object literal  (#7808) by @IWANABETHATGUY
- nativeMagicString move api (#7796) by @IWANABETHATGUY
- remove unnecessary exports after merging into commong and user defined entry (#7789) by @IWANABETHATGUY
- use output.name instead of chunk.name in mixed export warning (#7788) by @Copilot

### 🚜 Refactor

- generalize ParseError to OxcError with dynamic EventKind (#7868) by @shulaoda
- rust: rename `advanced_chunks` to `manual_code_splitting` (#7856) by @hyf0
- string_wizard error hanlding (#7830) by @IWANABETHATGUY
- remove `experimental.disableLiveBindings` option (#7820) by @sapphi-red
- node/test: run fixture tests in concurrent (#7790) by @hyf0
- move ConfigExport and RolldownOptionsFunction types to define-config (#7799) by @shulaoda
- cli: validate config after resolving and improve error message (#7798) by @shulaoda

### 📚 Documentation

- rebrand (#7670) by @yyx990803
- fix incorrect default value for propertyReadSideEffects (#7847) by @Copilot
- remove options pages and redirect to reference pages (#7834) by @sapphi-red
- options: inline types to option property pages (#7831) by @sapphi-red
- options: port checks.pluginTimings content from options page to reference page (#7832) by @sapphi-red
- options: use `@linkcode` where possible (#7824) by @sapphi-red
- options: port content from options page to reference page (#7822) by @sapphi-red
- options: add descriptions for output options (#7821) by @sapphi-red
- options: add description for input options (#7802) by @sapphi-red
- options: add description for `checks.*` (#7801) by @sapphi-red
- apis: add hook graph (#7671) by @sapphi-red

### 🧪 Testing

- add all valid combination of chunk exports related test (#7851) by @IWANABETHATGUY
- enable MagicString test after api return type alignment (#7797) by @IWANABETHATGUY
- init magic-string test (#7794) by @IWANABETHATGUY

### ⚙️ Miscellaneous Tasks

- vite-tests: configure git user for rebase operation (#7875) by @shulaoda
- rolldown_binding: remove v3 native plugins (#7837) by @shulaoda
- rolldown_binding: allow crate-type as lib (#7866) by @Brooooooklyn
- README.md: adjust position and size of rolldown logo (#7861) by @hyf0
- deps: update test262 submodule for tests (#7857) by @sapphi-red
- deps: update oxc to v0.108.0 (#7845) by @renovate[bot]
- deps: update dependency oxlint to v1.39.0 (#7849) by @renovate[bot]
- deps: update dependency oxfmt to ^0.24.0 (#7844) by @renovate[bot]
- deps: update npm packages (#7841) by @renovate[bot]
- deps: update rust crates (#7839) by @renovate[bot]
- deps: update github-actions (#7840) by @renovate[bot]
- use workspace edition for all crates (#7829) by @IWANABETHATGUY
- deps: update dependency oxlint-tsgolint to v0.11.0 (#7827) by @renovate[bot]
- deps: update napi to v3.8.2 (#7810) by @renovate[bot]
- remove outdated snapshot files (#7806) by @shulaoda
- deps: update crate-ci/typos action to v1.42.0 (#7792) by @renovate[bot]

Co-authored-by: shulaoda <[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.

[Feature Request]: make closeBundle hook receive the last error

3 participants