diff options
| author | David Sherret <dsherret@users.noreply.github.com> | 2024-03-07 20:16:32 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-03-07 20:16:32 -0500 |
| commit | 2dfc0aca7c6a04d54fe6f9a73be70fc4c591d552 (patch) | |
| tree | 58fb01c46364e4888097e7135b2f829f38ce990c /cli/util/path.rs | |
| parent | 2ed984ba3aa638c3f088ac1edc5c779c7d9195d1 (diff) | |
fix(publish): make include and exclude work (#22720)
1. Stops `deno publish` using some custom include/exclude behaviour from
other sub commands
2. Takes ancestor directories into account when resolving gitignore
3. Backards compatible change that adds ability to unexclude an exclude
by using a negated glob at a more specific level for all sub commands
(see https://github.com/denoland/deno_config/pull/44).
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::*; |
