diff --git a/crates/turborepo-lib/src/run/global_hash.rs b/crates/turborepo-lib/src/run/global_hash.rs index aa8d44431c2ca..b5529e1104dcd 100644 --- a/crates/turborepo-lib/src/run/global_hash.rs +++ b/crates/turborepo-lib/src/run/global_hash.rs @@ -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}; @@ -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 @@ -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::, _>>()?; #[cfg(not(windows))] - let inclusions = global_file_dependencies + let inclusions = raw_inclusions .iter() .map(|i| ValidatedGlob::from_str(i)) .collect::, _>>()?; diff --git a/turborepo-tests/integration/fixtures/global_deps/README.md b/turborepo-tests/integration/fixtures/global_deps/README.md new file mode 100644 index 0000000000000..8b07e5a1b1e03 --- /dev/null +++ b/turborepo-tests/integration/fixtures/global_deps/README.md @@ -0,0 +1,3 @@ +# My Monorepo + +Hello! diff --git a/turborepo-tests/integration/fixtures/global_deps/turbo.json b/turborepo-tests/integration/fixtures/global_deps/turbo.json index 94c68c1be65a4..b809448be70bf 100644 --- a/turborepo-tests/integration/fixtures/global_deps/turbo.json +++ b/turborepo-tests/integration/fixtures/global_deps/turbo.json @@ -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": { diff --git a/turborepo-tests/integration/tests/global-deps.t b/turborepo-tests/integration/tests/global-deps.t index bcda1fe66e165..d621740629779 100644 --- a/turborepo-tests/integration/tests/global-deps.t +++ b/turborepo-tests/integration/tests/global-deps.t @@ -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) +