Skip to content

Commit

Permalink
fix: buildEnd hook should handle buildStart hook error (#3117)
Browse files Browse the repository at this point in the history
<!-- Thank you for contributing! -->

### Description

<!-- Please insert your description here and provide especially info
about the "what" this PR is solving -->
  • Loading branch information
underfin authored Dec 11, 2024
1 parent d303f26 commit 1ae46b7
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 11 deletions.
2 changes: 0 additions & 2 deletions crates/rolldown/src/bundler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,6 @@ impl Bundler {
}

pub async fn scan(&mut self) -> BuildResult<ScanStageOutput> {
self.plugin_driver.build_start(&self.options).await?;

let scan_stage_output = match ScanStage::new(
Arc::clone(&self.options),
Arc::clone(&self.plugin_driver),
Expand Down
2 changes: 2 additions & 0 deletions crates/rolldown/src/stages/scan_stage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ impl ScanStage {
return Err(anyhow::format_err!("You must supply options.input to rolldown").into());
}

self.plugin_driver.build_start(&self.options).await?;

let module_loader = ModuleLoader::new(
Arc::clone(&self.options),
Arc::clone(&self.plugin_driver),
Expand Down
8 changes: 4 additions & 4 deletions packages/rolldown/tests/plugin/plugin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,15 @@ describe('Plugin buildEnd hook', async () => {
test('call buildEnd hook with error', async () => {
const buildEndFn = vi.fn()
const error = await buildWithPlugin({
load() {
throw new Error('load error')
buildStart() {
throw new Error('buildStart error')
},
buildEnd: (error) => {
buildEndFn()
expect(error!.message).toContain('load error')
expect(error!.message).toContain('buildStart error')
},
})
expect(error!.message).toContain('load error')
expect(error!.message).toContain('buildStart error')
expect(buildEndFn).toHaveBeenCalledTimes(1)
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
### The `rollup.rollup` api is not compatible with rollup, the build is start at `bundle.generate` or `bundle.write`, so the input plugin hooks is not called
- rollup@hooks@supports buildStart and buildEnd hooks
- rollup@hooks@supports warnings in buildStart and buildEnd hooks
- rollup@hooks@passes errors to the buildEnd hook

### The `NormalziedOptions` at hooks is not compatible with rollup
- rollup@function@options-hook: allows to read and modify options in the options hook
Expand Down
1 change: 0 additions & 1 deletion packages/rollup-tests/src/ignored-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ const ignoreTests = [
"rollup@hooks@allows to enforce sequential plugin hook order in watch mode",

"rollup@hooks@keeps emitted ids stable between runs",// emit empty asset
"rollup@hooks@passes errors to the buildEnd hook", // should call buildEnd hook if error
"rollup@hooks@supports renderError hook", // should call renderError hook if error
"rollup@hooks@assigns chunk IDs before creating outputBundle chunks", // The `renderChunk` is called at parallel, collect chunk info to array is unstable. https://github.com/rolldown/rolldown/issues/2364
]
Expand Down
4 changes: 2 additions & 2 deletions packages/rollup-tests/src/status.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"failed": 0,
"skipFailed": 0,
"ignored": 18,
"ignored(unsupported features)": 413,
"ignored": 17,
"ignored(unsupported features)": 414,
"ignored(treeshaking)": 286,
"ignored(behavior passed, snapshot different)": 120,
"passed": 710
Expand Down
4 changes: 2 additions & 2 deletions packages/rollup-tests/src/status.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
|----| ---- |
| failed | 0 |
| skipFailed | 0 |
| ignored | 18 |
| ignored(unsupported features) | 413 |
| ignored | 17 |
| ignored(unsupported features) | 414 |
| ignored(treeshaking) | 286 |
| ignored(behavior passed, snapshot different) | 120 |
| passed | 710 |

0 comments on commit 1ae46b7

Please sign in to comment.