-
Notifications
You must be signed in to change notification settings - Fork 539
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: support import.meta.ROLLUP_FILE_URL_(referenceId)
#3488
feat: support import.meta.ROLLUP_FILE_URL_(referenceId)
#3488
Conversation
let importer_dir = importer_chunk | ||
.absolute_preliminary_filename | ||
.as_ref() | ||
.unwrap() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should either add SAFETY
comments or expect
instead of unwrap
, attend to give a more friendly panic message.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Replaced unwrap
with expect
👍
FYI, I referenced the code from Chunk::import_path_for
, which computes relative chunk path. I'll try to refactor some repeated code separately later.
rolldown/crates/rolldown_common/src/chunk/mod.rs
Lines 88 to 92 in aad0c09
pub fn import_path_for(&self, importee: &Chunk) -> String { | |
let importer_dir = | |
self.absolute_preliminary_filename.as_ref().unwrap().as_path().parent().unwrap(); | |
let importee_filename = importee.absolute_preliminary_filename.as_ref().unwrap(); | |
let import_path = importee_filename.relative(importer_dir).as_path().expect_to_slash(); |
<!-- Thank you for contributing! --> ### Description Follow up to #3488. I forgot to test `emitFile({ type: "chunk" })` case and I just realized it's not working on hi-ogawa/vite-environment-examples#154. Currently, `FileEmitter::emitted_chunks` is not defined during scope hoisting finalizer, but it looks possible to define it earlier right after `generate_chunk_name_and_preliminary_filenames` instead of waiting until `instantiate_chunks`.
### Description Minor cleanup as I mentioned in #3488 (comment)
Description
Reviving #1928. I came across
import.meta.url.ROLLUP_FILE_URL_xxx
in one of my plugins (hi-ogawa/vite-plugins#673) and I think having the compat in rolldown is nice to have (though it's also possible to have a compat in rolldown-vite or user land level via a custom plugin'srenderChunk
replacing).Sapphi also mentioned that Astro uses this feature #819 (comment). I'm hoping the complexity required on rolldown side is low and it's worth the inclusion. Let me know what you think.
Example user-land plugin to replace "import.meta.ROLLUP_FILE_URL_xxx"
From hi-ogawa/vite-plugins#673