Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 325c04c

Browse files
committed
fix: test
1 parent 25e25f9 commit 325c04c

6 files changed

Lines changed: 36 additions & 25 deletions

File tree

crates/rolldown/src/bundler/chunk/chunk.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use oxc::span::Atom;
2-
use rolldown_common::{ModuleId, NamedImport, Specifier, SymbolRef};
2+
use rolldown_common::{EntryPoint, ModuleId, NamedImport, Specifier, SymbolRef};
33
use rustc_hash::FxHashMap;
44
use string_wizard::{Joiner, JoinerOptions};
55

@@ -26,7 +26,7 @@ pub struct CrossChunkImportItem {
2626

2727
#[derive(Debug, Default)]
2828
pub struct Chunk {
29-
pub entry_module: Option<ModuleId>,
29+
pub entry_point: Option<EntryPoint>,
3030
pub modules: Vec<ModuleId>,
3131
pub name: Option<String>,
3232
pub file_name: Option<String>,
@@ -41,15 +41,15 @@ pub struct Chunk {
4141
impl Chunk {
4242
pub fn new(
4343
name: Option<String>,
44-
entry_module: Option<ModuleId>,
44+
entry_point: Option<EntryPoint>,
4545
bits: BitSet,
4646
modules: Vec<ModuleId>,
4747
) -> Self {
48-
Self { entry_module, modules, name, bits, ..Self::default() }
48+
Self { entry_point, modules, name, bits, ..Self::default() }
4949
}
5050

5151
pub fn render_file_name(&mut self, output_options: &OutputOptions) {
52-
let pat = if self.entry_module.is_some() {
52+
let pat = if self.entry_point.is_some() {
5353
&output_options.entry_file_names
5454
} else {
5555
&output_options.chunk_file_names

crates/rolldown/src/bundler/chunk/render_chunk_exports.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ impl Chunk {
1212
graph: &LinkStageOutput,
1313
output_options: &OutputOptions,
1414
) -> Option<MagicString<'static>> {
15-
if let Some(entry) = self.entry_module {
16-
let linking_info = &graph.linking_infos[entry];
15+
if let Some(entry) = &self.entry_point {
16+
let linking_info = &graph.linking_infos[entry.module_id];
1717
if matches!(linking_info.wrap_kind, WrapKind::Cjs) {
1818
match output_options.format {
1919
OutputFormat::Esm => {
@@ -22,7 +22,7 @@ impl Chunk {
2222
panic!(
2323
"Cannot find canonical name for wrap ref {:?} of {:?}",
2424
linking_info.wrapper_ref.unwrap(),
25-
graph.modules[entry].resource_id()
25+
graph.modules[entry.module_id].resource_id()
2626
)
2727
});
2828
return Some(MagicString::new(format!("export default {wrap_ref_name}();\n")));
@@ -63,7 +63,7 @@ impl Chunk {
6363
}
6464

6565
fn get_export_items(&self, graph: &LinkStageOutput) -> Vec<(Atom, SymbolRef)> {
66-
self.entry_module.map_or_else(
66+
self.entry_point.as_ref().map_or_else(
6767
|| {
6868
let mut tmp = self
6969
.exports_to_other_chunks
@@ -75,8 +75,8 @@ impl Chunk {
7575

7676
tmp
7777
},
78-
|entry_module_id| {
79-
let linking_info = &graph.linking_infos[entry_module_id];
78+
|entry_point| {
79+
let linking_info = &graph.linking_infos[entry_point.module_id];
8080
linking_info
8181
.sorted_exports()
8282
.map(|(name, export)| (name.clone(), export.symbol_ref))
@@ -90,8 +90,8 @@ impl Chunk {
9090
graph: &LinkStageOutput,
9191
output_options: &OutputOptions,
9292
) -> Vec<String> {
93-
if let Some(entry) = self.entry_module {
94-
let linking_info = &graph.linking_infos[entry];
93+
if let Some(entry_point) = &self.entry_point {
94+
let linking_info = &graph.linking_infos[entry_point.module_id];
9595
if matches!(linking_info.wrap_kind, WrapKind::Cjs) {
9696
match output_options.format {
9797
OutputFormat::Esm => {

crates/rolldown/src/bundler/module_loader/module_loader.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
use std::sync::Arc;
22

33
use index_vec::IndexVec;
4-
use rolldown_common::{EntryPoint, FilePath, ImportKind, ImportRecordId, ModuleId, ResourceId};
4+
use rolldown_common::{
5+
EntryPoint, EntryPointKind, FilePath, ImportKind, ImportRecordId, ModuleId, ResourceId,
6+
};
57
use rolldown_error::BuildError;
68
use rolldown_fs::FileSystem;
79
use rustc_hash::{FxHashMap, FxHashSet};
@@ -136,6 +138,7 @@ impl<T: FileSystem + 'static + Default> ModuleLoader<T> {
136138
.map(|(name, info)| EntryPoint {
137139
name: name.clone(),
138140
module_id: self.try_spawn_new_task(info, true),
141+
kind: EntryPointKind::UserSpecified,
139142
})
140143
.collect::<Vec<_>>();
141144

@@ -168,6 +171,7 @@ impl<T: FileSystem + 'static + Default> ModuleLoader<T> {
168171
dynamic_entries.insert(EntryPoint {
169172
name: Some(info.path.unique(&self.input_options.cwd)),
170173
module_id: id,
174+
kind: EntryPointKind::DynamicImport,
171175
});
172176
}
173177
raw_rec.into_import_record(id)

crates/rolldown/src/bundler/stages/bundle_stage.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use crate::{
1616
InputOptions, Output, OutputFormat,
1717
};
1818
use index_vec::{index_vec, IndexVec};
19-
use rolldown_common::{ExportsKind, ImportKind, ModuleId, NamedImport, SymbolRef};
19+
use rolldown_common::{EntryPointKind, ExportsKind, ImportKind, ModuleId, NamedImport, SymbolRef};
2020
use rustc_hash::{FxHashMap, FxHashSet};
2121

2222
pub struct BundleStage<'a> {
@@ -63,10 +63,10 @@ impl<'a> BundleStage<'a> {
6363
Output::Chunk(Box::new(OutputChunk {
6464
file_name: c.file_name.clone().unwrap(),
6565
code: content,
66-
is_entry: c.entry_module.is_some(),
67-
facade_module_id: c
68-
.entry_module
69-
.map(|id| self.link_output.modules[id].expect_normal().pretty_path.to_string()),
66+
is_entry: matches!(&c.entry_point, Some(e) if e.kind == EntryPointKind::UserSpecified),
67+
facade_module_id: c.entry_point.as_ref().map(|entry_point| {
68+
self.link_output.modules[entry_point.module_id].expect_normal().pretty_path.to_string()
69+
}),
7070
modules: rendered_modules,
7171
exports: c.get_export_names(self.link_output, self.output_options),
7272
}))
@@ -163,8 +163,8 @@ impl<'a> BundleStage<'a> {
163163
}
164164
}
165165

166-
if let Some(entry_module) = chunk.entry_module {
167-
let entry_module = &self.link_output.modules[entry_module];
166+
if let Some(entry_point) = &chunk.entry_point {
167+
let entry_module = &self.link_output.modules[entry_point.module_id];
168168
let Module::Normal(entry_module) = entry_module else {
169169
return;
170170
};
@@ -203,7 +203,7 @@ impl<'a> BundleStage<'a> {
203203
}
204204
}
205205

206-
if chunk.entry_module.is_none() {
206+
if chunk.entry_point.is_none() {
207207
continue;
208208
}
209209
// If this is an entry point, make sure we import all chunks belonging to
@@ -273,7 +273,7 @@ impl<'a> BundleStage<'a> {
273273
bits.set_bit(count);
274274
let chunk = chunks.push(Chunk::new(
275275
entry_point.name.clone(),
276-
Some(entry_point.module_id),
276+
Some(entry_point.clone()),
277277
bits.clone(),
278278
vec![],
279279
));
Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
11
use crate::ModuleId;
22

3-
#[derive(Debug, Hash, PartialEq, Eq)]
3+
#[derive(Debug, Hash, PartialEq, Eq, Clone)]
44
pub struct EntryPoint {
55
pub name: Option<String>,
66
pub module_id: ModuleId,
7+
pub kind: EntryPointKind,
8+
}
9+
10+
#[derive(Debug, Hash, PartialEq, Eq, Clone)]
11+
pub enum EntryPointKind {
12+
UserSpecified,
13+
DynamicImport,
714
}

crates/rolldown_common/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ mod stmt_info;
1212
mod symbol_ref;
1313
mod wrap_kind;
1414
pub use crate::{
15-
entry_point::EntryPoint,
15+
entry_point::{EntryPoint, EntryPointKind},
1616
exports_kind::ExportsKind,
1717
file_path::{representative_name, FilePath},
1818
import_record::{ImportKind, ImportRecord, ImportRecordId, RawImportRecord},

0 commit comments

Comments
 (0)