diff --git a/crates/turborepo-lib/src/run/watch.rs b/crates/turborepo-lib/src/run/watch.rs index b50d8ed41dbe9..624a72363be3f 100644 --- a/crates/turborepo-lib/src/run/watch.rs +++ b/crates/turborepo-lib/src/run/watch.rs @@ -182,8 +182,24 @@ impl WatchClient { let notify_event = notify_run.clone(); let event_fut = async { + let mut first_rediscover = true; while let Some(event) = events.next().await { let event = event?; + + // Skip the first RediscoverPackages event which is sent immediately by the + // daemon when we connect. The file watcher will send the real + // one. + if first_rediscover { + if matches!( + event.event, + Some(proto::package_change_event::Event::RediscoverPackages(_)) + ) { + first_rediscover = false; + continue; + } + first_rediscover = false; + } + Self::handle_change_event(&changed_packages, event.event.unwrap())?; notify_event.notify_one(); } @@ -200,10 +216,11 @@ impl WatchClient { // if notify exits, then continue per usual // if persist exits, then we break out of loop with a select! { - _ = notify_run.notified() => {}, + biased; _ = persistent => { break; } + _ = notify_run.notified() => {}, } } else { notify_run.notified().await; diff --git a/turborepo-tests/integration/tests/watch/persistent-exit.t b/turborepo-tests/integration/tests/watch/persistent-exit.t index ced498004d20c..d6f25bdd95ca2 100644 --- a/turborepo-tests/integration/tests/watch/persistent-exit.t +++ b/turborepo-tests/integration/tests/watch/persistent-exit.t @@ -19,19 +19,7 @@ Disabling daemon so this matches behavior when running test on CI web:dev: npm ERR! in workspace: web web:dev: npm ERR! at location: .* (re) web:dev: ERROR: command finished with error: command .*npm(?:\.cmd)? run dev exited \(1\) (re) - web#dev: command .*npm(?:\.cmd)? run dev exited \(1\) (re) - web:dev: cache bypass, force executing bfb830bdb7d49cb8 - web:dev: - web:dev: > dev - web:dev: > echo server crashed && exit 1 - web:dev: - web:dev: server crashed - web:dev: npm ERR! Lifecycle script `dev` failed with error: - web:dev: npm ERR! Error: command failed - web:dev: npm ERR! in workspace: web - web:dev: npm ERR! at location: .* (re) - web:dev: ERROR: command finished with error: command .*npm(?:\.cmd)? run dev exited \(1\) (re) web#dev: command .*npm(?:\.cmd)? run dev exited \(1\) (re) x persistent tasks exited unexpectedly - [1] + [1] \ No newline at end of file