From 3300fbd967c2a428705236503ac4559db30840b2 Mon Sep 17 00:00:00 2001 From: Jonathan Cammisuli Date: Wed, 20 Sep 2023 08:58:48 -0400 Subject: [PATCH] fix(core): handle negative star glob better (#19241) --- packages/nx/src/native/utils/glob.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/nx/src/native/utils/glob.rs b/packages/nx/src/native/utils/glob.rs index 93c37883cdd65..cb6edcf48bae5 100644 --- a/packages/nx/src/native/utils/glob.rs +++ b/packages/nx/src/native/utils/glob.rs @@ -128,7 +128,7 @@ fn convert_glob(glob: &str) -> anyhow::Result> { globs.push(format!( "!{}", SINGLE_PATTERN_REGEX - .replace(&glob, |caps: ®ex::Captures| { caps[1].to_string() }) + .replace(&glob, |caps: ®ex::Captures| { format!("{}*", &caps[1]) }) .replace('!', "") )); } else { @@ -197,7 +197,7 @@ mod test { #[test] fn convert_globs_single_negative() { let negative_single_dir = convert_glob("packages/!(package-a)*").unwrap(); - assert_eq!(negative_single_dir, ["packages/*", "!packages/package-a"]); + assert_eq!(negative_single_dir, ["packages/*", "!packages/package-a*"]); } #[test] @@ -318,6 +318,8 @@ mod test { assert!(glob_set.is_match("packages/package-c")); // no matches assert!(!glob_set.is_match("packages/package-a")); + assert!(!glob_set.is_match("packages/package-a-b")); + assert!(!glob_set.is_match("packages/package-a-b/nested")); assert!(!glob_set.is_match("packages/package-b/nested")); } }