Skip to content

Commit

Permalink
fix: runtime module should always be the first to be executed (#116)
Browse files Browse the repository at this point in the history
  • Loading branch information
hyf0 authored Oct 28, 2023
1 parent 0c1e164 commit 883168f
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion crates/rolldown/src/bundler/graph/graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ impl Graph {

pub fn sort_modules(&mut self) {
let mut stack = self.entries.iter().map(|(_, m)| Action::Enter(*m)).rev().collect::<Vec<_>>();

// The runtime module should always be the first module to be executed
stack.push(Action::Enter(self.runtime.id));
let mut entered_ids: FxHashSet<ModuleId> = FxHashSet::default();
entered_ids.shrink_to(self.modules.len());
let mut sorted_modules = Vec::with_capacity(self.modules.len());
Expand Down Expand Up @@ -67,6 +68,11 @@ impl Graph {
}
}
self.sorted_modules = sorted_modules;
debug_assert_eq!(
self.sorted_modules.first().copied(),
Some(self.runtime.id),
"runtime module should always be the first module in the sorted modules"
);
}

pub fn link(&mut self) {
Expand Down

0 comments on commit 883168f

Please sign in to comment.