Skip to content

Commit

Permalink
feat: allow for negative globs in globalDeps (#8190)
Browse files Browse the repository at this point in the history
### Description

Handle exclusions in `globalDeps` 

### Testing Instructions

Updated `global-deps.t` to test negative globs.
  • Loading branch information
chris-olszewski committed May 22, 2024
1 parent 812c49d commit 28643f5
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 5 deletions.
18 changes: 14 additions & 4 deletions crates/turborepo-lib/src/run/global_hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ use std::{
str::FromStr,
};

use either::Either;
use globwalk::{ValidatedGlob, WalkType};
use itertools::Itertools;
use thiserror::Error;
use tracing::debug;
use turbopath::{AbsoluteSystemPath, AbsoluteSystemPathBuf, RelativeUnixPathBuf};
Expand Down Expand Up @@ -116,7 +118,7 @@ fn collect_global_deps(
if global_file_dependencies.is_empty() {
return Ok(HashSet::new());
}
let raw_exclusions = match package_manager.get_workspace_globs(root_path) {
let workspace_exclusions = match package_manager.get_workspace_globs(root_path) {
Ok(globs) => globs.raw_exclusions,
// If we hit a missing workspaces error, we could be in single package mode
// so we should just use the default globs
Expand All @@ -128,13 +130,21 @@ fn collect_global_deps(
return Err(err.into());
}
};
let exclusions = raw_exclusions
let (raw_inclusions, raw_exclusions): (Vec<_>, Vec<_>) = global_file_dependencies
.iter()
.map(|e| ValidatedGlob::from_str(e))
.partition_map(|glob| match glob.strip_prefix('!') {
None => Either::Left(glob.as_str()),
Some(exclusion) => Either::Right(exclusion),
});
let exclusions = workspace_exclusions
.iter()
.map(|s| s.as_str())
.chain(raw_exclusions.iter().copied())
.map(ValidatedGlob::from_str)
.collect::<Result<Vec<_>, _>>()?;

#[cfg(not(windows))]
let inclusions = global_file_dependencies
let inclusions = raw_inclusions
.iter()
.map(|i| ValidatedGlob::from_str(i))
.collect::<Result<Vec<_>, _>>()?;
Expand Down
3 changes: 3 additions & 0 deletions turborepo-tests/integration/fixtures/global_deps/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# My Monorepo

Hello!
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"$schema": "https://turbo.build/schema.json",
"globalDependencies": ["global_deps/**"],
"globalDependencies": ["global_deps/**", "!global_deps/**/*.md"],
"globalEnv": ["SOME_ENV_VAR"],
"tasks": {
"build": {
Expand Down
11 changes: 11 additions & 0 deletions turborepo-tests/integration/tests/global-deps.t
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,14 @@ Run a build
Cached: 0 cached, 1 total
Time:\s*[\.0-9]+m?s (re)

$ echo "Submit a PR!" >> global_deps/CONTRIBUTING.md
$ ${TURBO} build -F my-app --output-logs=hash-only
\xe2\x80\xa2 Packages in scope: my-app (esc)
\xe2\x80\xa2 Running build in 1 packages (esc)
\xe2\x80\xa2 Remote caching disabled (esc)
my-app:build: cache hit, suppressing logs ded57f1945fa82be

Tasks: 1 successful, 1 total
Cached: 1 cached, 1 total
Time:\s*[\.0-9]+m?s >>> FULL TURBO (re)

0 comments on commit 28643f5

Please sign in to comment.