-
Notifications
You must be signed in to change notification settings - Fork 512
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: render chunk hook binding (#402)
- Loading branch information
Showing
21 changed files
with
383 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
use rolldown_common::EntryPointKind; | ||
use rustc_hash::FxHashMap; | ||
|
||
use crate::{bundler::stages::link_stage::LinkStageOutput, OutputOptions, RenderedModule}; | ||
|
||
use super::chunk::Chunk; | ||
|
||
#[derive(Debug, Clone)] | ||
pub struct PreRenderedChunk { | ||
// pub name: String, | ||
pub is_entry: bool, | ||
pub is_dynamic_entry: bool, | ||
pub facade_module_id: Option<String>, | ||
pub module_ids: Vec<String>, | ||
pub exports: Vec<String>, | ||
} | ||
|
||
#[derive(Debug, Clone)] | ||
pub struct RenderedChunk { | ||
// PreRenderedChunk | ||
pub is_entry: bool, | ||
pub is_dynamic_entry: bool, | ||
pub facade_module_id: Option<String>, | ||
pub module_ids: Vec<String>, | ||
pub exports: Vec<String>, | ||
// RenderedChunk | ||
pub file_name: String, | ||
pub modules: FxHashMap<String, RenderedModule>, | ||
} | ||
|
||
impl Chunk { | ||
pub fn get_pre_rendered_chunk_info( | ||
&self, | ||
graph: &LinkStageOutput, | ||
output_options: &OutputOptions, | ||
) -> PreRenderedChunk { | ||
PreRenderedChunk { | ||
is_entry: matches!(&self.entry_point, Some(e) if e.kind == EntryPointKind::UserDefined), | ||
is_dynamic_entry: matches!(&self.entry_point, Some(e) if e.kind == EntryPointKind::DynamicImport), | ||
facade_module_id: self | ||
.entry_point | ||
.as_ref() | ||
.map(|entry_point| graph.modules[entry_point.id].resource_id().expect_file().to_string()), | ||
module_ids: self | ||
.modules | ||
.iter() | ||
.map(|id| graph.modules[*id].resource_id().expect_file().to_string()) | ||
.collect(), | ||
exports: self.get_export_names(graph, output_options), | ||
} | ||
} | ||
|
||
pub fn get_rendered_chunk_info( | ||
&self, | ||
graph: &LinkStageOutput, | ||
output_options: &OutputOptions, | ||
render_modules: FxHashMap<String, RenderedModule>, | ||
) -> RenderedChunk { | ||
let pre_rendered_chunk = self.get_pre_rendered_chunk_info(graph, output_options); | ||
RenderedChunk { | ||
is_entry: pre_rendered_chunk.is_entry, | ||
is_dynamic_entry: pre_rendered_chunk.is_dynamic_entry, | ||
facade_module_id: pre_rendered_chunk.facade_module_id, | ||
module_ids: pre_rendered_chunk.module_ids, | ||
exports: pre_rendered_chunk.exports, | ||
file_name: self.file_name.clone().expect("should have file name"), | ||
modules: render_modules, | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,28 @@ | ||
use rolldown_utils::block_on_spawn_all; | ||
|
||
use crate::{ | ||
bundler::{chunk::ChunkId, plugin_driver::PluginDriver}, | ||
error::{collect_errors, BatchedErrors}, | ||
bundler::{chunk::render_chunk::RenderedChunk, plugin_driver::SharedPluginDriver}, | ||
error::{into_batched_result, BatchedErrors}, | ||
plugin::args::RenderChunkArgs, | ||
}; | ||
|
||
#[allow(clippy::unused_async)] | ||
pub async fn _render_chunks<'a>( | ||
plugin_driver: &PluginDriver, | ||
chunks: Vec<(ChunkId, String)>, | ||
) -> Result<Vec<(ChunkId, String)>, BatchedErrors> { | ||
let result = block_on_spawn_all(chunks.iter().map(|(chunk, content)| async move { | ||
match plugin_driver.render_chunk(RenderChunkArgs { code: content.to_string() }).await { | ||
Ok(value) => Ok((*chunk, value)), | ||
#[allow(clippy::future_not_send)] | ||
pub async fn render_chunks<'a>( | ||
plugin_driver: &SharedPluginDriver, | ||
chunks: impl Iterator<Item = (String, RenderedChunk)>, | ||
) -> Result<Vec<(String, RenderedChunk)>, BatchedErrors> { | ||
let result = block_on_spawn_all(chunks.map(|(content, rendered_chunk)| async move { | ||
match plugin_driver | ||
.render_chunk(RenderChunkArgs { | ||
code: content, | ||
chunk: unsafe { std::mem::transmute(&rendered_chunk) }, | ||
}) | ||
.await | ||
{ | ||
Ok(value) => Ok((value, rendered_chunk)), | ||
Err(e) => Err(e), | ||
} | ||
})); | ||
|
||
collect_errors(result) | ||
into_batched_result(result) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.