[WIP] Add new metadata API
Description
A handful of Vite plugins mutate arguments of plugin functions, primarily through renderChunk and generateBundle, to support the internal viteMetadata structure, which tracks asset/css information for chunks.
While this currently works in rollup, this won't work in rolldown, as function calls and their arguments/return are serialized/deserialized when going across the Rust <-> JS bridge. This is non-trivial to support, so it's best that we avoid this pattern all together.
As a replacement, I'm introducing a general metadata store through the MetadataManager, which can be accessed within plugins via the inheritMetadata plugin function. I generalized this approach so that it may be used for more data in the future, but right now it's only for chunks.
Additional context
I originally wanted to avoid the inheritMetadata plugin function by using configureServer, but this function isn't called for builds (where chunk metadata is primarily used). So I opted for going with a new plugin function, that's called from both build/server.
What is the purpose of this pull request?
- [ ] Bug fix
- [x] New Feature
- [ ] Documentation update
- [ ] Other
Before submitting the PR, please make sure you do the following
- [x] Read the Contributing Guidelines, especially the Pull Request Guidelines.
- [x] Check that there isn't already a PR that solves the problem the same way to avoid creating a duplicate.
- [x] Provide a description in this PR that addresses what the PR is solving, or reference the issue that it solves (e.g.
fixes #123). - [ ] Update the corresponding documentation if needed.
- [ ] Ideally, include relevant tests that fail without this PR but pass with it.
Run & review this pull request in StackBlitz Codeflow.
cc @yyx990803
@milesj do you have any updates for this PR, and is it still needed?
@bluwy This problem will need to be addressed at some point when we integrate rolldown, but I'm not sure this approach is the best. We can close this for now.