-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(core): fix globbing in rust (#17803)
- Loading branch information
1 parent
a995940
commit 38101fd
Showing
2 changed files
with
48 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,44 @@ | ||
use globset::{Glob, GlobSet, GlobSetBuilder}; | ||
use globset::{GlobBuilder, GlobSet, GlobSetBuilder}; | ||
|
||
pub(crate) fn build_glob_set(globs: Vec<String>) -> anyhow::Result<GlobSet> { | ||
let mut glob_builder = GlobSetBuilder::new(); | ||
let mut glob_set_builder = GlobSetBuilder::new(); | ||
for glob in globs { | ||
glob_builder.add(Glob::new(&glob).map_err(anyhow::Error::from)?); | ||
let glob = GlobBuilder::new(&glob) | ||
.literal_separator(true) | ||
.build() | ||
.map_err(anyhow::Error::from)?; | ||
glob_set_builder.add(glob); | ||
} | ||
|
||
glob_builder.build().map_err(anyhow::Error::from) | ||
glob_set_builder.build().map_err(anyhow::Error::from) | ||
} | ||
|
||
#[cfg(test)] | ||
mod test { | ||
use super::*; | ||
|
||
#[test] | ||
fn should_detect_package_json() { | ||
let glob_set = build_glob_set(vec![String::from("packages/*/package.json")]).unwrap(); | ||
assert!(glob_set.is_match("packages/nx/package.json")) | ||
} | ||
|
||
#[test] | ||
fn should_not_detect_deeply_nested_package_json() { | ||
let glob_set = build_glob_set(vec![String::from("packages/*/package.json")]).unwrap(); | ||
assert!(!glob_set.is_match("packages/nx/test-files/package.json")) | ||
} | ||
|
||
#[test] | ||
fn should_detect_deeply_nested_package_json() { | ||
let glob_set = build_glob_set(vec![String::from("packages/**/package.json")]).unwrap(); | ||
assert!(glob_set.is_match("packages/nx/test-files/package.json")) | ||
} | ||
|
||
#[test] | ||
fn should_detect_node_modules() { | ||
let glob_set = build_glob_set(vec![String::from("**/node_modules")]).unwrap(); | ||
assert!(glob_set.is_match("node_modules")); | ||
assert!(glob_set.is_match("packages/nx/node_modules")); | ||
} | ||
} |
38101fd
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
nx-dev – ./
nx-five.vercel.app
nx-dev-nrwl.vercel.app
nx.dev
nx-dev-git-master-nrwl.vercel.app