Skip to content

Commit

Permalink
fix(Turborepo): Fix as_inputs to include ! (#8119)
Browse files Browse the repository at this point in the history
### Description

- `GlobSet::as_inputs` now prefixes exclusions with `!` so they are
properly parsed

### Testing Instructions

Added new hash watching test with exclusions in the inputs.

Fixes #8112

---------

Co-authored-by: Greg Soltis <Greg Soltis>
  • Loading branch information
gsoltis committed May 9, 2024
1 parent 021f9a0 commit be6c39f
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 1 deletion.
3 changes: 2 additions & 1 deletion crates/turborepo-filewatch/src/globwatcher.rs
Expand Up @@ -24,13 +24,14 @@ type Hash = String;
pub struct GlobSet {
include: HashMap<String, wax::Glob<'static>>,
exclude: Any<'static>,
// Note that these globs do not include the leading '!' character
exclude_raw: BTreeSet<String>,
}

impl GlobSet {
pub fn as_inputs(&self) -> Vec<String> {
let mut inputs: Vec<String> = self.include.keys().cloned().collect();
inputs.extend(self.exclude_raw.iter().cloned());
inputs.extend(self.exclude_raw.iter().map(|s| format!("!{}", s)));
inputs
}

Expand Down
76 changes: 76 additions & 0 deletions crates/turborepo-filewatch/src/hash_watcher.rs
Expand Up @@ -1285,4 +1285,80 @@ mod tests {
)
.await;
}

#[tokio::test]
#[tracing_test::traced_test]
async fn test_negative_inputs() {
let (_tmp, _repo, repo_root) = setup_fixture();

let watcher = FileSystemWatcher::new_with_default_cookie_dir(&repo_root).unwrap();

let recv = watcher.watch();
let cookie_writer = CookieWriter::new(
watcher.cookie_dir(),
Duration::from_millis(100),
recv.clone(),
);

let scm = SCM::new(&repo_root);
assert!(!scm.is_manual());
let package_watcher = PackageWatcher::new(repo_root.clone(), recv, cookie_writer).unwrap();
let package_discovery = package_watcher.watch_discovery();
let hash_watcher =
HashWatcher::new(repo_root.clone(), package_discovery, watcher.watch(), scm);

let foo_path = repo_root.join_components(&["packages", "foo"]);
let dist_path = foo_path.join_component("dist");
dist_path
.join_component("some-dist-file")
.create_with_contents("dist file")
.unwrap();
dist_path
.join_component("extra-file")
.create_with_contents("extra file")
.unwrap();
let foo_inputs = GlobSet::from_raw_unfiltered(vec![
"!dist/extra-file".to_string(),
"**/*-file".to_string(),
])
.unwrap();
let foo_spec = HashSpec {
package_path: repo_root.anchor(&foo_path).unwrap(),
inputs: InputGlobs::Specific(foo_inputs),
};

retry_get_hash(
&hash_watcher,
foo_spec.clone(),
Duration::from_secs(2),
make_expected(vec![
("foo-file", "9317666a2e7b729b740c706ab79724952c97bde4"),
("package.json", "395351bdd7167f351af3396d3225ebe97a7a4d13"),
(
"dist/some-dist-file",
"21aa527e5ea52d11bf53f493df0dbe6d659b6a30",
),
]),
)
.await;

dist_path
.join_component("some-dist-file")
.create_with_contents("new dist file contents")
.unwrap();
retry_get_hash(
&hash_watcher,
foo_spec.clone(),
Duration::from_secs(2),
make_expected(vec![
("foo-file", "9317666a2e7b729b740c706ab79724952c97bde4"),
("package.json", "395351bdd7167f351af3396d3225ebe97a7a4d13"),
(
"dist/some-dist-file",
"03d4fc427f0bccc1ca7053fc889fa73e54a402fa",
),
]),
)
.await;
}
}

0 comments on commit be6c39f

Please sign in to comment.