mirror of
https://github.com/denoland/deno.git
synced 2024-12-21 23:04:45 -05:00
feat(watch): log which file changed on HMR or watch change (#25801)
Closes #25504
This commit is contained in:
parent
768c5ea2bb
commit
abf06eb87f
8 changed files with 20 additions and 13 deletions
|
@ -486,6 +486,7 @@ pub async fn run_benchmarks_with_watch(
|
|||
),
|
||||
move |flags, watcher_communicator, changed_paths| {
|
||||
let bench_flags = bench_flags.clone();
|
||||
watcher_communicator.show_path_changed(changed_paths.clone());
|
||||
Ok(async move {
|
||||
let factory = CliFactory::from_flags_for_watcher(
|
||||
flags,
|
||||
|
|
|
@ -83,6 +83,7 @@ pub async fn format(
|
|||
file_watcher::PrintConfig::new("Fmt", !watch_flags.no_clear_screen),
|
||||
move |flags, watcher_communicator, changed_paths| {
|
||||
let fmt_flags = fmt_flags.clone();
|
||||
watcher_communicator.show_path_changed(changed_paths.clone());
|
||||
Ok(async move {
|
||||
let factory = CliFactory::from_flags(flags);
|
||||
let cli_options = factory.cli_options()?;
|
||||
|
|
|
@ -80,6 +80,7 @@ pub async fn lint(
|
|||
file_watcher::PrintConfig::new("Lint", !watch_flags.no_clear_screen),
|
||||
move |flags, watcher_communicator, changed_paths| {
|
||||
let lint_flags = lint_flags.clone();
|
||||
watcher_communicator.show_path_changed(changed_paths.clone());
|
||||
Ok(async move {
|
||||
let factory = CliFactory::from_flags(flags);
|
||||
let cli_options = factory.cli_options()?;
|
||||
|
|
|
@ -124,7 +124,8 @@ async fn run_with_watch(
|
|||
!watch_flags.no_clear_screen,
|
||||
),
|
||||
WatcherRestartMode::Automatic,
|
||||
move |flags, watcher_communicator, _changed_paths| {
|
||||
move |flags, watcher_communicator, changed_paths| {
|
||||
watcher_communicator.show_path_changed(changed_paths.clone());
|
||||
Ok(async move {
|
||||
let factory = CliFactory::from_flags_for_watcher(
|
||||
flags,
|
||||
|
|
|
@ -151,7 +151,8 @@ async fn serve_with_watch(
|
|||
!watch_flags.no_clear_screen,
|
||||
),
|
||||
WatcherRestartMode::Automatic,
|
||||
move |flags, watcher_communicator, _changed_paths| {
|
||||
move |flags, watcher_communicator, changed_paths| {
|
||||
watcher_communicator.show_path_changed(changed_paths.clone());
|
||||
Ok(async move {
|
||||
let factory = CliFactory::from_flags_for_watcher(
|
||||
flags,
|
||||
|
|
|
@ -1661,6 +1661,7 @@ pub async fn run_tests_with_watch(
|
|||
),
|
||||
move |flags, watcher_communicator, changed_paths| {
|
||||
let test_flags = test_flags.clone();
|
||||
watcher_communicator.show_path_changed(changed_paths.clone());
|
||||
Ok(async move {
|
||||
let factory = CliFactory::from_flags_for_watcher(
|
||||
flags,
|
||||
|
|
|
@ -127,19 +127,12 @@ impl PrintConfig {
|
|||
}
|
||||
}
|
||||
|
||||
fn create_print_after_restart_fn(
|
||||
banner: &'static str,
|
||||
clear_screen: bool,
|
||||
) -> impl Fn() {
|
||||
fn create_print_after_restart_fn(clear_screen: bool) -> impl Fn() {
|
||||
move || {
|
||||
#[allow(clippy::print_stderr)]
|
||||
if clear_screen && std::io::stderr().is_terminal() {
|
||||
eprint!("{}", CLEAR_SCREEN);
|
||||
}
|
||||
info!(
|
||||
"{} File change detected! Restarting!",
|
||||
colors::intense_blue(banner),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -187,7 +180,15 @@ impl WatcherCommunicator {
|
|||
}
|
||||
|
||||
pub fn print(&self, msg: String) {
|
||||
log::info!("{} {}", self.banner, msg);
|
||||
log::info!("{} {}", self.banner, colors::gray(msg));
|
||||
}
|
||||
|
||||
pub fn show_path_changed(&self, changed_paths: Option<Vec<PathBuf>>) {
|
||||
if let Some(paths) = changed_paths {
|
||||
self.print(
|
||||
format!("Restarting! File change detected: {:?}", paths[0]).to_string(),
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -263,7 +264,7 @@ where
|
|||
clear_screen,
|
||||
} = print_config;
|
||||
|
||||
let print_after_restart = create_print_after_restart_fn(banner, clear_screen);
|
||||
let print_after_restart = create_print_after_restart_fn(clear_screen);
|
||||
let watcher_communicator = Arc::new(WatcherCommunicator {
|
||||
paths_to_watch_tx: paths_to_watch_tx.clone(),
|
||||
changed_paths_rx: changed_paths_rx.resubscribe(),
|
||||
|
|
|
@ -55,7 +55,7 @@ where
|
|||
let mut str = String::new();
|
||||
while let Some(t) = next_line(stderr_lines).await {
|
||||
let t = util::strip_ansi_codes(&t);
|
||||
if t.starts_with("Watcher File change detected") {
|
||||
if t.starts_with("Watcher Restarting! File change detected") {
|
||||
continue;
|
||||
}
|
||||
if t.starts_with("Watcher") {
|
||||
|
|
Loading…
Reference in a new issue