Skip to content

Commit

Permalink
feat: add output chunk isDynamicEntry (#373)
Browse files Browse the repository at this point in the history
  • Loading branch information
underfin authored Nov 23, 2023
1 parent 4d44e56 commit 7f0e987
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 9 deletions.
1 change: 1 addition & 0 deletions crates/rolldown/src/bundler/bundle/output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ pub struct OutputChunk {
pub file_name: String,
pub code: String,
pub is_entry: bool,
pub is_dynamic_entry: bool,
pub facade_module_id: Option<String>,
pub modules: FxHashMap<String, RenderedModule>,
pub exports: Vec<String>,
Expand Down
1 change: 1 addition & 0 deletions crates/rolldown/src/bundler/stages/bundle_stage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ impl<'a> BundleStage<'a> {
file_name: c.file_name.clone().unwrap(),
code: content,
is_entry: matches!(&c.entry_point, Some(e) if e.kind == EntryPointKind::UserSpecified),
is_dynamic_entry: matches!(&c.entry_point, Some(e) if e.kind == EntryPointKind::DynamicImport),
facade_module_id: c.entry_point.as_ref().map(|entry_point| {
self.link_output.modules[entry_point.module_id].expect_normal().pretty_path.to_string()
}),
Expand Down
8 changes: 6 additions & 2 deletions crates/rolldown/tests/common/case.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,12 @@ impl Case {
.flat_map(|asset| match asset {
Output::Chunk(chunk) => {
vec![Cow::Owned(format!(
"- {}, is_entry {}, facade_module_id {:?}, exports {:?}",
chunk.file_name, chunk.is_entry, chunk.facade_module_id, chunk.exports
"- {}, is_entry {}, is_dynamic_entry {}, facade_module_id {:?}, exports {:?}",
chunk.file_name,
chunk.is_entry,
chunk.is_dynamic_entry,
chunk.facade_module_id,
chunk.exports
))]
}
Output::Asset(_) => vec![],
Expand Down
8 changes: 4 additions & 4 deletions crates/rolldown/tests/fixtures/code_splitting/artifacts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import('./dynamic_js.mjs')

## Output Stats

- 3.mjs, is_entry false, facade_module_id None, exports []
- dynamic_js.mjs, is_entry false, facade_module_id Some("dynamic.js"), exports []
- main1.mjs, is_entry true, facade_module_id Some("main1.js"), exports []
- main2.mjs, is_entry true, facade_module_id Some("main2.js"), exports []
- 3.mjs, is_entry false, is_dynamic_entry false, facade_module_id None, exports []
- dynamic_js.mjs, is_entry false, is_dynamic_entry true, facade_module_id Some("dynamic.js"), exports []
- main1.mjs, is_entry true, is_dynamic_entry false, facade_module_id Some("main1.js"), exports []
- main2.mjs, is_entry true, is_dynamic_entry false, facade_module_id Some("main2.js"), exports []
1 change: 1 addition & 0 deletions crates/rolldown_binding/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ export interface OutputChunk {
code: string
fileName: string
isEntry: boolean
isDynamicEntry: boolean
facadeModuleId?: string
modules: Record<string, RenderedModule>
exports: Array<string>
Expand Down
2 changes: 2 additions & 0 deletions crates/rolldown_binding/src/output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ pub struct OutputChunk {
pub code: String,
pub file_name: String,
pub is_entry: bool,
pub is_dynamic_entry: bool,
pub facade_module_id: Option<String>,
pub modules: HashMap<String, RenderedModule>,
pub exports: Vec<String>,
Expand All @@ -48,6 +49,7 @@ impl From<Box<rolldown::OutputChunk>> for OutputChunk {
code: chunk.code,
file_name: chunk.file_name,
is_entry: chunk.is_entry,
is_dynamic_entry: chunk.is_dynamic_entry,
facade_module_id: chunk.facade_module_id,
modules: chunk.modules.into_iter().map(|(key, value)| (key, value.into())).collect(),
exports: chunk.exports,
Expand Down
4 changes: 1 addition & 3 deletions packages/node/src/utils/transform-to-rollup-output.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ function transformToRollupOutputChunk(chunk: OutputChunk): RollupOutputChunk {
exports: chunk.exports,
isEntry: chunk.isEntry,
facadeModuleId: chunk.facadeModuleId || null,
isDynamicEntry: chunk.isDynamicEntry,
get dynamicImports() {
return unimplemented()
},
Expand All @@ -33,9 +34,6 @@ function transformToRollupOutputChunk(chunk: OutputChunk): RollupOutputChunk {
get map() {
return unimplemented()
},
get isDynamicEntry() {
return unimplemented()
},
get isImplicitEntry() {
return unimplemented()
},
Expand Down

0 comments on commit 7f0e987

Please sign in to comment.