rolldown_watcher/
event.rs1use crate::watch_task::WatchTaskIdx;
2use rolldown::BundleHandle;
3use rolldown_error::BuildDiagnostic;
4use std::fmt::{Debug, Display};
5use std::path::PathBuf;
6use std::sync::Arc;
7
8#[derive(Debug, Clone)]
10pub enum WatchEvent {
11 Start,
13 BundleStart(BundleStartEventData),
15 BundleEnd(BundleEndEventData),
17 End,
19 Error(WatchErrorEventData),
21}
22
23impl WatchEvent {
24 pub fn as_str(&self) -> &str {
25 match self {
26 WatchEvent::Start => "START",
27 WatchEvent::BundleStart(_) => "BUNDLE_START",
28 WatchEvent::BundleEnd(_) => "BUNDLE_END",
29 WatchEvent::End => "END",
30 WatchEvent::Error(_) => "ERROR",
31 }
32 }
33}
34
35impl Display for WatchEvent {
36 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
37 write!(f, "{}", self.as_str())
38 }
39}
40
41#[derive(Debug, Clone)]
43pub struct BundleStartEventData {
44 pub task_index: WatchTaskIdx,
45}
46
47#[derive(Clone)]
49pub struct BundleEndEventData {
50 pub task_index: WatchTaskIdx,
51 pub output: String,
52 pub duration: u32,
53 pub bundle_handle: BundleHandle,
54}
55
56impl Debug for BundleEndEventData {
57 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
58 f.debug_struct("BundleEndEventData")
59 .field("task_index", &self.task_index)
60 .field("output", &self.output)
61 .field("duration", &self.duration)
62 .finish_non_exhaustive()
63 }
64}
65
66#[derive(Clone)]
68pub struct WatchErrorEventData {
69 pub task_index: WatchTaskIdx,
70 pub diagnostics: Arc<[BuildDiagnostic]>,
73 pub cwd: PathBuf,
74 pub bundle_handle: BundleHandle,
75}
76
77impl Debug for WatchErrorEventData {
78 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
79 f.debug_struct("WatchErrorEventData")
80 .field("task_index", &self.task_index)
81 .field("diagnostics", &self.diagnostics)
82 .field("cwd", &self.cwd)
83 .finish_non_exhaustive()
84 }
85}