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(filter): dependencies filter should match transitive deps #7886

Merged
merged 1 commit into from
Apr 2, 2024
Merged
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
29 changes: 19 additions & 10 deletions crates/turborepo-lib/src/run/scope/filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -281,10 +281,10 @@ impl<'a, T: GitChangeDetector> FilterResolver<'a, T> {
let node = package_graph::PackageNode::Workspace(package.clone());

if selector.include_dependencies {
let dependencies = self.pkg_graph.immediate_dependencies(&node);
let dependencies = self.pkg_graph.dependencies(&node);
let dependencies = dependencies
.iter()
.flatten()
.filter(|node| !matches!(node, package_graph::PackageNode::Root))
.map(|i| i.as_package_name().to_owned())
.collect::<Vec<_>>();

Expand All @@ -303,11 +303,11 @@ impl<'a, T: GitChangeDetector> FilterResolver<'a, T> {
package_graph::PackageNode::Workspace(dependent.to_owned());

let dependent_dependencies =
self.pkg_graph.immediate_dependencies(&dependent_node);
self.pkg_graph.dependencies(&dependent_node);

let dependent_dependencies = dependent_dependencies
.iter()
.flatten()
.filter(|node| !matches!(node, package_graph::PackageNode::Root))
.map(|i| i.as_package_name().to_owned())
.collect::<HashSet<_>>();

Expand Down Expand Up @@ -401,7 +401,7 @@ impl<'a, T: GitChangeDetector> FilterResolver<'a, T> {
}

let workspace_node = package_graph::PackageNode::Workspace(package.clone());
let dependencies = self.pkg_graph.immediate_dependencies(&workspace_node);
let dependencies = self.pkg_graph.dependencies(&workspace_node);

for changed_package in &changed_packages {
if !selector.exclude_self && package.eq(changed_package) {
Expand All @@ -412,11 +412,7 @@ impl<'a, T: GitChangeDetector> FilterResolver<'a, T> {
let changed_node =
package_graph::PackageNode::Workspace(changed_package.to_owned());

if dependencies
.as_ref()
.map(|d| d.contains(&changed_node))
.unwrap_or_default()
{
if dependencies.contains(&changed_node) {
roots.insert(package.clone());
matched.insert(package);
break;
Expand Down Expand Up @@ -779,6 +775,19 @@ mod test {
&["project-1", "project-2", "project-4"] ;
"select package with dependencies"
)]
#[test_case(
vec![
TargetSelector {
exclude_self: false,
include_dependencies: true,
name_pattern: "project-0".to_string(),
..Default::default()
}
],
None,
&["project-0", "project-1", "project-2", "project-4", "project-5"] ;
"select package with transitive dependencies"
)]
#[test_case(
vec![
TargetSelector {
Expand Down
Loading