Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(turborepo): use transitive closure of filtered packages in watch mode #8161

Merged
merged 1 commit into from
May 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion crates/turborepo-lib/src/run/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use turbopath::AbsoluteSystemPathBuf;
use turborepo_api_client::{APIAuth, APIClient};
use turborepo_ci::Vendor;
use turborepo_env::EnvironmentVariableMap;
use turborepo_repository::package_graph::{PackageGraph, PackageName};
use turborepo_repository::package_graph::{PackageGraph, PackageName, PackageNode};
use turborepo_scm::SCM;
use turborepo_telemetry::events::generic::GenericEventBuilder;
use turborepo_ui::{cprint, cprintln, tui, tui::AppSender, BOLD_GREY, GREY, UI};
Expand Down Expand Up @@ -118,6 +118,24 @@ impl Run {
new_run
}

// Produces the transitive closure of the filtered packages,
// i.e. the packages relevant for this run.
pub fn get_relevant_packages(&self) -> HashSet<PackageName> {
let packages: Vec<_> = self
.filtered_pkgs
.iter()
.map(|pkg| PackageNode::Workspace(pkg.clone()))
.collect();
self.pkg_dep_graph
.transitive_closure(&packages)
.into_iter()
.filter_map(|node| match node {
PackageNode::Root => None,
PackageNode::Workspace(pkg) => Some(pkg.clone()),
})
.collect()
}

pub fn has_experimental_ui(&self) -> bool {
self.experimental_ui
}
Expand Down
11 changes: 9 additions & 2 deletions crates/turborepo-lib/src/run/watch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ use crate::{
DaemonConnector, DaemonPaths,
};

#[derive(Debug)]
enum ChangedPackages {
All,
Some(HashSet<PackageName>),
Expand All @@ -45,6 +46,7 @@ impl ChangedPackages {

pub struct WatchClient {
run: Run,
watched_packages: HashSet<PackageName>,
persistent_tasks_handle: Option<JoinHandle<Result<i32, run::Error>>>,
connector: DaemonConnector,
base: CommandBase,
Expand Down Expand Up @@ -114,6 +116,8 @@ impl WatchClient {
.build(&handler, telemetry.clone())
.await?;

let watched_packages = run.get_relevant_packages();

let (sender, handle) = run.start_experimental_ui().unzip();

let connector = DaemonConnector {
Expand All @@ -125,6 +129,7 @@ impl WatchClient {
Ok(Self {
base,
run,
watched_packages,
connector,
handler,
telemetry,
Expand Down Expand Up @@ -228,8 +233,8 @@ impl WatchClient {
let packages = packages
.into_iter()
.filter(|pkg| {
// If not in the filtered pkgs, ignore
self.run.filtered_pkgs.contains(pkg)
// If not in the watched packages set, ignore
self.watched_packages.contains(pkg)
})
.collect();

Expand Down Expand Up @@ -297,6 +302,8 @@ impl WatchClient {
.build(&self.handler, self.telemetry.clone())
.await?;

self.watched_packages = self.run.get_relevant_packages();

if let Some(sender) = &self.ui_sender {
let task_names = self.run.engine.tasks_with_command(&self.run.pkg_dep_graph);
sender
Expand Down
Loading