diff options
Diffstat (limited to 'cli/util/path.rs')
-rw-r--r-- | cli/util/path.rs | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/cli/util/path.rs b/cli/util/path.rs index 496b37c5e..fed74cb06 100644 --- a/cli/util/path.rs +++ b/cli/util/path.rs @@ -6,6 +6,9 @@ use std::path::PathBuf; use deno_ast::MediaType; use deno_ast::ModuleSpecifier; +use deno_config::glob::PathGlobMatch; +use deno_config::glob::PathOrPattern; +use deno_config::glob::PathOrPatternSet; use deno_core::error::uri_error; use deno_core::error::AnyError; @@ -244,6 +247,38 @@ pub fn root_url_to_safe_local_dirname(root: &ModuleSpecifier) -> PathBuf { result } +/// Slightly different behaviour than the default matching +/// where an exact path needs to be matched to be opted-in +/// rather than just a partial directory match. +/// +/// This is used by the test and bench filtering. +pub fn matches_pattern_or_exact_path( + path_or_pattern_set: &PathOrPatternSet, + path: &Path, +) -> bool { + for p in path_or_pattern_set.inner().iter().rev() { + match p { + PathOrPattern::Path(p) => { + if p == path { + return true; + } + } + PathOrPattern::NegatedPath(p) => { + if path.starts_with(p) { + return false; + } + } + PathOrPattern::RemoteUrl(_) => {} + PathOrPattern::Pattern(p) => match p.matches_path(path) { + PathGlobMatch::Matched => return true, + PathGlobMatch::MatchedNegated => return false, + PathGlobMatch::NotMatched => {} + }, + } + } + false +} + #[cfg(test)] mod test { use super::*; |