Skip to content

Commit 061a9b3

Browse files
committed
refactor(watch): rename TaskStart/TaskEnd to BundleStart/BundleEnd (#8463)
1 parent baf3430 commit 061a9b3

File tree

5 files changed

+25
-24
lines changed

5 files changed

+25
-24
lines changed

crates/rolldown_watcher/src/event.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ use tokio::sync::Mutex;
1010
pub enum WatchEvent {
1111
/// Watch run is starting (all tasks)
1212
Start,
13-
/// A single task is starting its build
14-
TaskStart(WatchStartEventData),
15-
/// A single task has finished its build
16-
TaskEnd(WatchEndEventData),
13+
/// A single bundle is starting its build
14+
BundleStart(BundleStartEventData),
15+
/// A single bundle has finished its build
16+
BundleEnd(BundleEndEventData),
1717
/// All tasks have finished
1818
End,
1919
/// An error occurred during bundling
@@ -24,8 +24,8 @@ impl WatchEvent {
2424
pub fn as_str(&self) -> &str {
2525
match self {
2626
WatchEvent::Start => "START",
27-
WatchEvent::TaskStart(_) => "BUNDLE_START",
28-
WatchEvent::TaskEnd(_) => "BUNDLE_END",
27+
WatchEvent::BundleStart(_) => "BUNDLE_START",
28+
WatchEvent::BundleEnd(_) => "BUNDLE_END",
2929
WatchEvent::End => "END",
3030
WatchEvent::Error(_) => "ERROR",
3131
}
@@ -38,24 +38,24 @@ impl Display for WatchEvent {
3838
}
3939
}
4040

41-
/// Data for task start event
41+
/// Data for bundle start event
4242
#[derive(Debug, Clone)]
43-
pub struct WatchStartEventData {
43+
pub struct BundleStartEventData {
4444
pub task_index: WatchTaskIdx,
4545
}
4646

47-
/// Data for task end event
47+
/// Data for bundle end event
4848
#[derive(Clone)]
49-
pub struct WatchEndEventData {
49+
pub struct BundleEndEventData {
5050
pub task_index: WatchTaskIdx,
5151
pub output: String,
5252
pub duration: u32,
5353
pub bundler: Arc<Mutex<Bundler>>,
5454
}
5555

56-
impl Debug for WatchEndEventData {
56+
impl Debug for BundleEndEventData {
5757
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
58-
f.debug_struct("WatchEndEventData")
58+
f.debug_struct("BundleEndEventData")
5959
.field("task_index", &self.task_index)
6060
.field("output", &self.output)
6161
.field("duration", &self.duration)

crates/rolldown_watcher/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ mod watch_coordinator;
66
mod watch_task;
77
mod watcher;
88

9-
pub use event::{WatchEndEventData, WatchErrorEventData, WatchEvent, WatchStartEventData};
9+
pub use event::{BundleEndEventData, BundleStartEventData, WatchErrorEventData, WatchEvent};
1010
pub use handler::WatcherEventHandler;
1111
pub use state::ChangeEntry;
1212
pub use watch_task::WatchTaskIdx;

crates/rolldown_watcher/src/watch_coordinator.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -95,12 +95,12 @@ impl<H: WatcherEventHandler> WatchCoordinator<H> {
9595

9696
for task_index in self.tasks.indices() {
9797
let task = &self.tasks[task_index];
98-
self.handler.on_event(WatchEvent::TaskStart(task.start_event_data(task_index))).await;
98+
self.handler.on_event(WatchEvent::BundleStart(task.start_event_data(task_index))).await;
9999

100100
let task = &mut self.tasks[task_index];
101101
match task.build(task_index).await {
102102
Ok(BuildOutcome::Success(data)) => {
103-
self.handler.on_event(WatchEvent::TaskEnd(data)).await;
103+
self.handler.on_event(WatchEvent::BundleEnd(data)).await;
104104
}
105105
Ok(BuildOutcome::Error(data)) => {
106106
self.handler.on_event(WatchEvent::Error(data)).await;
@@ -121,7 +121,7 @@ impl<H: WatcherEventHandler> WatchCoordinator<H> {
121121
/// 2. For each task and each changed file: task.call_watch_change
122122
/// 3. handler.on_restart
123123
/// 4. handler.on_event(Start)
124-
/// 5. For each task needing rebuild: TaskStart → build → TaskEnd/Error
124+
/// 5. For each task needing rebuild: BundleStart → build → BundleEnd/Error
125125
/// 6. handler.on_event(End)
126126
/// 7. drain_buffered_events
127127
async fn run_build_sequence(&mut self, changes: Vec<ChangeEntry>) {
@@ -149,12 +149,12 @@ impl<H: WatcherEventHandler> WatchCoordinator<H> {
149149
}
150150

151151
let task = &self.tasks[task_index];
152-
self.handler.on_event(WatchEvent::TaskStart(task.start_event_data(task_index))).await;
152+
self.handler.on_event(WatchEvent::BundleStart(task.start_event_data(task_index))).await;
153153

154154
let task = &mut self.tasks[task_index];
155155
match task.build(task_index).await {
156156
Ok(BuildOutcome::Success(data)) => {
157-
self.handler.on_event(WatchEvent::TaskEnd(data)).await;
157+
self.handler.on_event(WatchEvent::BundleEnd(data)).await;
158158
}
159159
Ok(BuildOutcome::Error(data)) => {
160160
self.handler.on_event(WatchEvent::Error(data)).await;

crates/rolldown_watcher/src/watch_task.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use std::sync::Arc;
99
use std::time::Instant;
1010
use tokio::sync::Mutex as TokioMutex;
1111

12-
use crate::event::{WatchEndEventData, WatchErrorEventData, WatchStartEventData};
12+
use crate::event::{BundleEndEventData, BundleStartEventData, WatchErrorEventData};
1313

1414
oxc_index::define_index_type! {
1515
pub struct WatchTaskIdx = u32;
@@ -87,7 +87,7 @@ impl WatchTask {
8787
self.needs_rebuild = false;
8888

8989
match result {
90-
Ok(_output) => Ok(BuildOutcome::Success(WatchEndEventData {
90+
Ok(_output) => Ok(BuildOutcome::Success(BundleEndEventData {
9191
task_index,
9292
output: self.options.cwd.join(&self.options.out_dir).to_string_lossy().into_owned(),
9393
duration,
@@ -106,8 +106,8 @@ impl WatchTask {
106106
}
107107

108108
/// Start event data for this task
109-
pub(crate) fn start_event_data(&self, task_index: WatchTaskIdx) -> WatchStartEventData {
110-
WatchStartEventData { task_index }
109+
pub(crate) fn start_event_data(&self, task_index: WatchTaskIdx) -> BundleStartEventData {
110+
BundleStartEventData { task_index }
111111
}
112112

113113
/// Update watched files by adding new ones to the fs watcher.
@@ -209,7 +209,7 @@ pub enum BuildOutcome {
209209
/// Build was skipped (no rebuild needed)
210210
Skipped,
211211
/// Build succeeded
212-
Success(WatchEndEventData),
212+
Success(BundleEndEventData),
213213
/// Build had errors (but didn't fail fatally)
214214
Error(WatchErrorEventData),
215215
}

meta/design/watch-mode.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ Watch mode monitors source files and automatically rebuilds when changes are det
88

99
- **JS API aligns with Rollup** — The TypeScript surface (events, options, plugin hooks, lifecycle ordering) should match Rollup's behavior unless there's a technical reason not to. Divergences are documented explicitly.
1010
- **Rust code follows Rust idioms** — The Rust core should feel native: ownership-driven, enum state machines, trait-based extensibility, no unnecessary `Arc`/`Mutex` beyond what the architecture requires.
11+
- **Consistent naming across the stack** — Rollup defines the canonical event/concept names (e.g. `BUNDLE_START`/`BUNDLE_END`). The Rust side should use the same terminology so there's a clean 1:1 mapping and no mental translation at the NAPI boundary.
1112

1213
## API Contract
1314

@@ -127,7 +128,7 @@ rolldown_watcher/
127128
├── watch_coordinator.rs // WatchCoordinator (actor + event loop)
128129
├── watch_task.rs // WatchTask (bundler + fs watcher) + WatchTaskIdx + BuildOutcome
129130
├── handler.rs // WatcherEventHandler async trait
130-
├── event.rs // WatchEvent, WatchStartEventData, WatchEndEventData, WatchErrorEventData
131+
├── event.rs // WatchEvent, BundleStartEventData, BundleEndEventData, WatchErrorEventData
131132
├── state.rs // WatcherState enum + transitions + ChangeEntry
132133
└── msg.rs // WatcherMsg enum (FsEvent, Close)
133134
```

0 commit comments

Comments
 (0)