feat: import.meta.ROLLDOWN_FILE_URL_<referenceId>_<urlId> support to pass context to resolveFileUrl hook#10297
Conversation
How to use the Graphite Merge QueueAdd the label graphite: merge-when-ready 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. This stack of pull requests is managed by Graphite. Learn more about stacking. |
42cb429 to
d443874
Compare
c927fea to
45b086b
Compare
d443874 to
ce98ae7
Compare
45b086b to
e94d186
Compare
Merging this PR will not alter performance
Comparing Footnotes
|
hyfdev
left a comment
There was a problem hiding this comment.
The fixed-length split is sound: reference ids are always exactly 22 chars of base64url from assign_reference_id, and the new lockstep test in file_emitter.rs guards that invariant. Per-occurrence results keyed by (ModuleIdx, NodeId) mean the same file referenced with different urlIds resolves independently, and the ROLLUP_FILE_URL_ alias keeps Rollup semantics by never parsing a suffix.
Generating the urlId on the plugin side (rather than a Rolldown-side generateFileUrlId) covers the use cases described: the plugin controls both the reference spelling and the hook, so urlId conflicts stay within one plugin's namespace.
Left a few small notes on the docs and test coverage; nothing blocking.
e94d186 to
cacdf16
Compare
✅ Deploy Preview for rolldown-rs canceled.
|
598cbea to
68065e5
Compare
|
marked as experimental (may change in minors) |
Merge activity
|
…o pass context to `resolveFileUrl` hook (#10297) This PR adds a new feature to `import.meta.ROLLDOWN_FILE_URL_<referenceId>`. Currently, these file URL references does not have a way to differentiate each references when `resolveFileUrl` hook is called. But that is sometimes needed. For example, in Vite, there are three cases: - The wasm plugin emits the reference to the wasm binary. In SSR, this reference to the wasm binary should be rendered in a way that accesses as a relative path (as it's a file read). But in other plugins, the wasm binary should be rendered as the URL that can be accessed from the browser (this may sound strange, but it's the current behavior). So the `import.meta.ROLLDOWN_FILE_URL_<referenceId>` needs to be differentiated with type it is. - Vite has `?inline` query which forces the asset to be output as `data` URL. The same asset can be imported with the query in some places while it can also be imported without the query in other places. This means the same asset needs to be referenced differently depending on the reference. - Vite never inlines assets specified as the entrypoint. This information is tied to a single reference. [rendered docs](https://github.com/rolldown/rolldown/blob/07-15-feat_import.meta.rolldown_file_url__referenceid___urlid_support_to_pass_context_to_resolvefileurl_hook/docs/apis/plugin-api/file-urls.md#passing-a-urlid) In this PR, I made the `urlId` generated on the plugin side, but maybe that should be generated on the Rolldown side so that a conflict never happens. This can be done by adding `this.generateFileUrlId`. The API can also be expanded to store the metadata in the Rolldown side. Currently, The metadata lives on the plugin side, so the referenceId emit and the `resolveFileUrl` hook needs to be coupled. This works for Vite's case, but won't work in general. For now, I think it's ok to go without it. refs vitejs/vite#22962
68065e5 to
0d45611
Compare

This PR adds a new feature to
import.meta.ROLLDOWN_FILE_URL_<referenceId>.Currently, these file URL references does not have a way to differentiate each references when
resolveFileUrlhook is called. But that is sometimes needed. For example, in Vite, there are three cases:import.meta.ROLLDOWN_FILE_URL_<referenceId>needs to be differentiated with type it is.?inlinequery which forces the asset to be output asdataURL. The same asset can be imported with the query in some places while it can also be imported without the query in other places. This means the same asset needs to be referenced differently depending on the reference.rendered docs
In this PR, I made the
urlIdgenerated on the plugin side, but maybe that should be generated on the Rolldown side so that a conflict never happens. This can be done by addingthis.generateFileUrlId.The API can also be expanded to store the metadata in the Rolldown side. Currently, The metadata lives on the plugin side, so the referenceId emit and the
resolveFileUrlhook needs to be coupled. This works for Vite's case, but won't work in general. For now, I think it's ok to go without it.refs vitejs/vite#22962