Skip to content

Commit e563d20

Browse files
feat(turborepo): log reason why all packages were considered changed (#8872)
The ultimate goal for me is to figure out why I'm seeing _all_ packages invalidated when running with `--filter='[sha]'` . In a lot of cases, we return a sigil for `PackageChanges::All`. I'm not sure how to bubble this up with higher fidelity information in a good way, so this PR settles for a more granular "reason" why all packages changed and includes it in debug logging. This should help a little bit with debugging. --------- Co-authored-by: Chris Olszewski <[email protected]>
1 parent 86c89a9 commit e563d20

File tree

6 files changed

+70
-41
lines changed

6 files changed

+70
-41
lines changed

crates/turborepo-lib/src/global_deps_package_change_mapper.rs

+7-2
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,9 @@ mod tests {
6363
use tempfile::tempdir;
6464
use turbopath::{AbsoluteSystemPath, AnchoredSystemPathBuf};
6565
use turborepo_repository::{
66-
change_mapper::{ChangeMapper, DefaultPackageChangeMapper, PackageChanges},
66+
change_mapper::{
67+
AllPackageChangeReason, ChangeMapper, DefaultPackageChangeMapper, PackageChanges,
68+
},
6769
discovery,
6870
discovery::PackageDiscovery,
6971
package_graph::{PackageGraphBuilder, WorkspacePackage},
@@ -117,7 +119,10 @@ mod tests {
117119

118120
// We should return All because we don't have global deps and
119121
// therefore must be conservative about changes
120-
assert_eq!(package_changes, PackageChanges::All);
122+
assert_eq!(
123+
package_changes,
124+
PackageChanges::All(AllPackageChangeReason::NonPackageFileChanged)
125+
);
121126

122127
let turbo_package_detector =
123128
GlobalDepsPackageChangeMapper::new(&pkg_graph, std::iter::empty::<&str>())?;

crates/turborepo-lib/src/package_changes_watcher.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ impl Subscriber {
348348
tracing::warn!("changed_packages: {:?}", changed_packages);
349349

350350
match changed_packages {
351-
Ok(PackageChanges::All) => {
351+
Ok(PackageChanges::All(_)) => {
352352
// We tell the client that we need to rediscover the packages, i.e.
353353
// all bets are off, just re-run everything
354354
let _ = self

crates/turborepo-lib/src/run/scope/change_detector.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,8 @@ impl<'a> GitChangeDetector for ScopeChangeDetector<'a> {
100100
.change_mapper
101101
.changed_packages(changed_files, lockfile_contents)?
102102
{
103-
PackageChanges::All => {
104-
debug!("all packages changed");
103+
PackageChanges::All(reason) => {
104+
debug!("all packages changed: {:?}", reason);
105105
Ok(self
106106
.pkg_graph
107107
.packages()

crates/turborepo-repository/src/change_mapper/mod.rs

+54-33
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,18 @@ pub enum LockfileChange {
2323
WithContent(Vec<u8>),
2424
}
2525

26+
#[derive(Debug, PartialEq, Eq)]
27+
pub enum AllPackageChangeReason {
28+
DefaultGlobalFileChanged,
29+
LockfileChangeDetectionFailed,
30+
LockfileChangedWithoutDetails,
31+
RootInternalDepChanged,
32+
NonPackageFileChanged,
33+
}
34+
2635
#[derive(Debug, PartialEq, Eq)]
2736
pub enum PackageChanges {
28-
All,
37+
All(AllPackageChangeReason),
2938
Some(HashSet<WorkspacePackage>),
3039
}
3140

@@ -62,39 +71,50 @@ impl<'a, PD: PackageChangeMapper> ChangeMapper<'a, PD> {
6271
) -> Result<PackageChanges, ChangeMapError> {
6372
if Self::default_global_file_changed(&changed_files) {
6473
debug!("global file changed");
65-
return Ok(PackageChanges::All);
74+
return Ok(PackageChanges::All(
75+
AllPackageChangeReason::DefaultGlobalFileChanged,
76+
));
6677
}
6778

6879
// get filtered files and add the packages that contain them
6980
let filtered_changed_files = self.filter_ignored_files(changed_files.iter())?;
70-
let PackageChanges::Some(mut changed_pkgs) =
71-
self.get_changed_packages(filtered_changed_files.into_iter())
72-
else {
73-
return Ok(PackageChanges::All);
74-
};
75-
76-
match lockfile_change {
77-
Some(LockfileChange::WithContent(content)) => {
78-
// if we run into issues, don't error, just assume all packages have changed
79-
let Ok(lockfile_changes) = self.get_changed_packages_from_lockfile(content) else {
80-
debug!("unable to determine lockfile changes, assuming all packages changed");
81-
return Ok(PackageChanges::All);
82-
};
83-
84-
debug!(
85-
"found {} packages changed by lockfile",
86-
lockfile_changes.len()
87-
);
88-
changed_pkgs.extend(lockfile_changes);
89-
90-
Ok(PackageChanges::Some(changed_pkgs))
91-
}
92-
// We don't have the actual contents, so just invalidate everything
93-
Some(LockfileChange::Empty) => {
94-
debug!("no previous lockfile available, assuming all packages changed");
95-
Ok(PackageChanges::All)
81+
82+
match self.get_changed_packages(filtered_changed_files.into_iter()) {
83+
PackageChanges::All(reason) => Ok(PackageChanges::All(reason)),
84+
85+
PackageChanges::Some(mut changed_pkgs) => {
86+
match lockfile_change {
87+
Some(LockfileChange::WithContent(content)) => {
88+
// if we run into issues, don't error, just assume all packages have changed
89+
let Ok(lockfile_changes) = self.get_changed_packages_from_lockfile(content)
90+
else {
91+
debug!(
92+
"unable to determine lockfile changes, assuming all packages \
93+
changed"
94+
);
95+
return Ok(PackageChanges::All(
96+
AllPackageChangeReason::LockfileChangeDetectionFailed,
97+
));
98+
};
99+
debug!(
100+
"found {} packages changed by lockfile",
101+
lockfile_changes.len()
102+
);
103+
changed_pkgs.extend(lockfile_changes);
104+
105+
Ok(PackageChanges::Some(changed_pkgs))
106+
}
107+
108+
// We don't have the actual contents, so just invalidate everything
109+
Some(LockfileChange::Empty) => {
110+
debug!("no previous lockfile available, assuming all packages changed");
111+
Ok(PackageChanges::All(
112+
AllPackageChangeReason::LockfileChangedWithoutDetails,
113+
))
114+
}
115+
None => Ok(PackageChanges::Some(changed_pkgs)),
116+
}
96117
}
97-
None => Ok(PackageChanges::Some(changed_pkgs)),
98118
}
99119
}
100120

@@ -120,18 +140,19 @@ impl<'a, PD: PackageChangeMapper> ChangeMapper<'a, PD> {
120140
// Internal root dependency changed so global hash has changed
121141
PackageMapping::Package(pkg) if root_internal_deps.contains(&pkg) => {
122142
debug!(
123-
"root internal dependency \"{}\" changed due to: {file:?}",
143+
"{} changes root internal dependency: \"{}\"",
144+
file.to_string(),
124145
pkg.name
125146
);
126-
return PackageChanges::All;
147+
return PackageChanges::All(AllPackageChangeReason::RootInternalDepChanged);
127148
}
128149
PackageMapping::Package(pkg) => {
129-
debug!("package {pkg:?} changed due to {file:?}");
150+
debug!("{} changes \"{}\"", file.to_string(), pkg.name);
130151
changed_packages.insert(pkg);
131152
}
132153
PackageMapping::All => {
133154
debug!("all packages changed due to {file:?}");
134-
return PackageChanges::All;
155+
return PackageChanges::All(AllPackageChangeReason::NonPackageFileChanged);
135156
}
136157
PackageMapping::None => {}
137158
}

crates/turborepo-repository/src/change_mapper/package.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ mod tests {
120120

121121
use super::{DefaultPackageChangeMapper, GlobalDepsPackageChangeMapper};
122122
use crate::{
123-
change_mapper::{ChangeMapper, PackageChanges},
123+
change_mapper::{AllPackageChangeReason, ChangeMapper, PackageChanges},
124124
discovery,
125125
discovery::PackageDiscovery,
126126
package_graph::{PackageGraphBuilder, WorkspacePackage},
@@ -172,7 +172,10 @@ mod tests {
172172

173173
// We should return All because we don't have global deps and
174174
// therefore must be conservative about changes
175-
assert_eq!(package_changes, PackageChanges::All);
175+
assert_eq!(
176+
package_changes,
177+
PackageChanges::All(AllPackageChangeReason::NonPackageFileChanged)
178+
);
176179

177180
let turbo_package_detector =
178181
GlobalDepsPackageChangeMapper::new(&pkg_graph, std::iter::empty::<&str>())?;

packages/turbo-repository/rust/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ impl Workspace {
211211
};
212212

213213
let packages = match package_changes {
214-
PackageChanges::All => self
214+
PackageChanges::All(_) => self
215215
.graph
216216
.packages()
217217
.map(|(name, info)| WorkspacePackage {

0 commit comments

Comments
 (0)