Skip to content

Commit

Permalink
feat: add OutputChunk is_entry and facade_module_id (#230)
Browse files Browse the repository at this point in the history
  • Loading branch information
underfin authored Nov 13, 2023
1 parent dd4ced3 commit 8fcfda3
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 12 deletions.
2 changes: 2 additions & 0 deletions crates/rolldown/src/bundler/bundle/asset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@
pub struct OutputChunk {
pub file_name: String,
pub code: String,
pub is_entry: bool,
pub facade_module_id: Option<String>,
}
9 changes: 8 additions & 1 deletion crates/rolldown/src/bundler/bundle/bundle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,14 @@ impl<'a> Bundle<'a> {
.map(|(_chunk_id, c)| {
let content = c.render(self.graph, &chunk_graph, self.output_options).unwrap();

OutputChunk { file_name: c.file_name.clone().unwrap(), code: content }
OutputChunk {
file_name: c.file_name.clone().unwrap(),
code: content,
is_entry: c.entry_module.is_some(),
facade_module_id: c
.entry_module
.map(|id| self.graph.modules[id].expect_normal().resource_id.prettify().to_string()),
}
})
.collect::<Vec<_>>();

Expand Down
2 changes: 1 addition & 1 deletion crates/rolldown/src/bundler/module/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ impl Module {
}
}

pub fn _expect_normal(&self) -> &NormalModule {
pub fn expect_normal(&self) -> &NormalModule {
match self {
Self::Normal(m) => m,
Self::External(_) => unreachable!(),
Expand Down
2 changes: 2 additions & 0 deletions crates/rolldown_binding/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ export interface OutputOptions {
export interface OutputChunk {
code: string
fileName: string
isEntry: boolean
facadeModuleId?: string
}
export class Bundler {
constructor(inputOpts: InputOptions)
Expand Down
10 changes: 2 additions & 8 deletions crates/rolldown_binding/src/bundler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,7 @@ impl Bundler {
}
};

let output_chunks = outputs
.into_iter()
.map(|asset| OutputChunk { code: asset.code, file_name: asset.file_name })
.collect::<Vec<_>>();
let output_chunks = outputs.into_iter().map(Into::into).collect::<Vec<_>>();
Ok(output_chunks)
}

Expand All @@ -95,10 +92,7 @@ impl Bundler {
}
};

let output_chunks = outputs
.into_iter()
.map(|asset| OutputChunk { code: asset.code, file_name: asset.file_name })
.collect::<Vec<_>>();
let output_chunks = outputs.into_iter().map(Into::into).collect::<Vec<_>>();
Ok(output_chunks)
}
}
13 changes: 13 additions & 0 deletions crates/rolldown_binding/src/output_chunk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,17 @@ use serde::Deserialize;
pub struct OutputChunk {
pub code: String,
pub file_name: String,
pub is_entry: bool,
pub facade_module_id: Option<String>,
}

impl From<rolldown::OutputChunk> for OutputChunk {
fn from(chunk: rolldown::OutputChunk) -> Self {
Self {
code: chunk.code,
file_name: chunk.file_name,
is_entry: chunk.is_entry,
facade_module_id: chunk.facade_module_id,
}
}
}
4 changes: 2 additions & 2 deletions packages/core/src/utils/transform-to-rollup-output.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ function transformToRollupOutputChunk(chunk: OutputChunk): RollupOutputChunk {
return unimplemented()
},
get facadeModuleId() {
return unimplemented()
return chunk.facadeModuleId || null
},
get isDynamicEntry() {
return unimplemented()
},
get isEntry() {
return unimplemented()
return chunk.isEntry
},
get isImplicitEntry() {
return unimplemented()
Expand Down

0 comments on commit 8fcfda3

Please sign in to comment.