use crate::watch_task::WatchTaskIdx;
use rolldown::BundleHandle;
use rolldown_error::BuildDiagnostic;
use std::fmt::{Debug, Display};
use std::path::PathBuf;
use std::sync::Arc;
#[derive(Debug, Clone)]
pub enum WatchEvent {
Start,
BundleStart(BundleStartEventData),
BundleEnd(BundleEndEventData),
End,
Error(WatchErrorEventData),
}
impl WatchEvent {
pub fn as_str(&self) -> &str {
match self {
WatchEvent::Start => "START",
WatchEvent::BundleStart(_) => "BUNDLE_START",
WatchEvent::BundleEnd(_) => "BUNDLE_END",
WatchEvent::End => "END",
WatchEvent::Error(_) => "ERROR",
}
}
}
impl Display for WatchEvent {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
write!(f, "{}", self.as_str())
}
}
#[derive(Debug, Clone)]
pub struct BundleStartEventData {
pub task_index: WatchTaskIdx,
}
#[derive(Clone)]
pub struct BundleEndEventData {
pub task_index: WatchTaskIdx,
pub output: String,
pub duration: u32,
pub bundle_handle: BundleHandle,
}
impl Debug for BundleEndEventData {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("BundleEndEventData")
.field("task_index", &self.task_index)
.field("output", &self.output)
.field("duration", &self.duration)
.finish_non_exhaustive()
}
}
#[derive(Clone)]
pub struct WatchErrorEventData {
pub task_index: WatchTaskIdx,
pub diagnostics: Arc<[BuildDiagnostic]>,
pub cwd: PathBuf,
pub bundle_handle: BundleHandle,
}
impl Debug for WatchErrorEventData {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("WatchErrorEventData")
.field("task_index", &self.task_index)
.field("diagnostics", &self.diagnostics)
.field("cwd", &self.cwd)
.finish_non_exhaustive()
}
}