Skip to content

feat(5858): make closeBundle hook receive the last error#5867

Merged
lukastaegert merged 11 commits intorollup:masterfrom
GauBen:feat-5858
Mar 7, 2025
Merged

feat(5858): make closeBundle hook receive the last error#5867
lukastaegert merged 11 commits intorollup:masterfrom
GauBen:feat-5858

Conversation

@GauBen
Copy link
Copy Markdown
Contributor

@GauBen GauBen commented Mar 1, 2025

Hello!

This PR contains:

  • bugfix
  • feature
  • refactor
  • documentation
  • other

Are tests included?

  • yes (bugfixes and features will not be merged without tests)
  • no

Breaking Changes?

  • yes (breaking changes will not be merged unless absolutely necessary)
  • no

List any relevant issue numbers:

Description

The closeBundle hook now receives the last error:

const plugin = {
  name: 'example',
  closeBundle(error) {
    if (error) console.warn('Oh no :(')
  }
}

If an error is thrown in buildEnd, closeBundle will receive this error:

const plugin = {
  name: 'example',
  buildEnd(error) {
    throw new Error('build end')
  },
  closeBundle(error) {
    // error comes from buildEnd
  }
}

In case the build fails and buildEnd also fails, closeBundle will receive a compound error created out of both previous errors.

@vercel
Copy link
Copy Markdown

vercel Bot commented Mar 1, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
rollup ✅ Ready (Inspect) Visit Preview 💬 Add feedback Mar 4, 2025 7:57am

@codecov
Copy link
Copy Markdown

codecov Bot commented Mar 1, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 98.54%. Comparing base (caa406e) to head (e328f03).
Report is 4 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #5867   +/-   ##
=======================================
  Coverage   98.54%   98.54%           
=======================================
  Files         269      269           
  Lines        8545     8550    +5     
  Branches     1467     1467           
=======================================
+ Hits         8421     8426    +5     
  Misses         92       92           
  Partials       32       32           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Copy Markdown
Member

@lukastaegert lukastaegert left a comment

Choose a reason for hiding this comment

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

This is really nice, especially the tests. One question, what do you think?

Comment thread src/rollup/rollup.ts
Comment thread src/rollup/rollup.ts Outdated
Comment thread src/rollup/rollup.ts Outdated
Comment thread docs/plugin-development/index.md Outdated
Comment thread src/rollup/rollup.ts Outdated
Comment thread docs/plugin-development/index.md Outdated
@lukastaegert lukastaegert added this pull request to the merge queue Mar 7, 2025
Merged via the queue into rollup:master with commit d29a457 Mar 7, 2025
@GauBen
Copy link
Copy Markdown
Contributor Author

GauBen commented Mar 7, 2025

Thanks for the review!

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Mar 8, 2025

This PR has been released as part of rollup@4.35.0. You can test it via npm install rollup.

Copilot AI added a commit to rolldown/rolldown that referenced this pull request Dec 1, 2025
Co-authored-by: shulaoda <165626830+shulaoda@users.noreply.github.com>
shulaoda added a commit to rolldown/rolldown that referenced this pull request Dec 6, 2025
Co-authored-by: shulaoda <165626830+shulaoda@users.noreply.github.com>
shulaoda added a commit to rolldown/rolldown that referenced this pull request Dec 30, 2025
Co-authored-by: shulaoda <165626830+shulaoda@users.noreply.github.com>
shulaoda added a commit to rolldown/rolldown that referenced this pull request Jan 7, 2026
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

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

<!-- START COPILOT CODING AGENT SUFFIX -->



<details>

<summary>Original prompt</summary>

> 
> ----
> 
> *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)
> 
> <comments>
> </comments>
> 


</details>

- Fixes #4364

<!-- START COPILOT CODING AGENT TIPS -->
---

💬 We'd love your input! Share your thoughts on Copilot coding agent in
our [2 minute survey](https://gh.io/copilot-coding-agent-survey).

Co-authored-by: shulaoda <165626830+shulaoda@users.noreply.github.com>
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.

Forward error to closeBundle hook, if any

2 participants