Skip to content

Conversation

@yoannmoinet
Copy link
Member

What and why?

Not all bundlers report the same buildEnd or even writeBundle hooks.

  • rollup will call writeBundle as many times as there are outputs.
  • esbuild has a pretty inacurate buildEnd.
  • ...

How?

Implement a more accurate trueEnd hook.

Had to make both syncTrueEnd and asyncTrueEnd because if your hook handler is asynchronous it can't execute at the same time as if it was synchronous, depending on the bundler...

I added these details in the documentation:

It may execute sooner than `syncTrueEnd` in some contexts:

- `esbuild` will call `asyncTrueEnd` before `syncTrueEnd`.
    - We use `build.onDispose`, for the latest hook possible in the build. The issue is, it's synchronous only. So we have to use `build.onEnd` for the asynchronous `asyncTrueEnd`, but it's called well before `build.onDispose`.
- `webpack 4` will only call `syncTrueEnd` if the build has an error. All good otherwise.

In short, it's best to use syncTrueEnd if you can.

@yoannmoinet yoannmoinet marked this pull request as ready for review May 19, 2025 08:35
#### [📝 Full documentation ➡️](/packages/plugins/injection#readme)


### True End
Copy link
Collaborator

Choose a reason for hiding this comment

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

I find the name a bit weird (but I don't have a better suggestion :/)

what about onFullBuild?

Copy link
Member Author

Choose a reason for hiding this comment

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

I find onFullBuild a bit misleading too, for instance in rollup the concept of buildEnd happens before the writeBundle, as-in, rollup (and vite) separate both the build from the write process.

Can you elaborate on what you find weird with "true end"?
Maybe we could go with just end?

Copy link
Collaborator

Choose a reason for hiding this comment

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

"true" doesn't really have a definition. And it sounds a bit more like something you'd say when speaking to someone vs something defined in a spec / technical document

Copy link
Member Author

@yoannmoinet yoannmoinet May 19, 2025

Choose a reason for hiding this comment

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

After some discussion offline, it's difficult to find a term that would really define this hook, cross bundler, so for now, until we get better consensus, we'll stick with true-end.

@yoannmoinet yoannmoinet enabled auto-merge May 19, 2025 12:38
@yoannmoinet yoannmoinet merged commit 73606f6 into master May 19, 2025
4 checks passed
@yoannmoinet yoannmoinet deleted the yoann/true-end-plugin branch May 19, 2025 12:40
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.

3 participants