mirror of
https://github.com/pesde-pkg/pesde.git
synced 2025-01-19 05:18:05 +00:00
fix: switch to wax for better globs
This commit is contained in:
parent
b6a4d39c51
commit
2c003c62aa
6 changed files with 102 additions and 50 deletions
72
Cargo.lock
generated
72
Cargo.lock
generated
|
@ -864,6 +864,26 @@ dependencies = [
|
||||||
"windows-sys 0.52.0",
|
"windows-sys 0.52.0",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "const_format"
|
||||||
|
version = "0.2.33"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "50c655d81ff1114fb0dcdea9225ea9f0cc712a6f8d189378e82bdf62a473a64b"
|
||||||
|
dependencies = [
|
||||||
|
"const_format_proc_macros",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "const_format_proc_macros"
|
||||||
|
version = "0.2.33"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "eff1a44b93f47b1bac19a27932f5c591e43d1ba357ee4f61526c8a25603f0eb1"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"unicode-xid",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "constant_time_eq"
|
name = "constant_time_eq"
|
||||||
version = "0.3.1"
|
version = "0.3.1"
|
||||||
|
@ -2375,20 +2395,6 @@ dependencies = [
|
||||||
"thiserror 1.0.69",
|
"thiserror 1.0.69",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "globset"
|
|
||||||
version = "0.4.15"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "15f1ce686646e7f1e19bf7d5533fe443a45dbfb990e00629110797578b42fb19"
|
|
||||||
dependencies = [
|
|
||||||
"aho-corasick",
|
|
||||||
"bstr",
|
|
||||||
"log",
|
|
||||||
"regex-automata",
|
|
||||||
"regex-syntax",
|
|
||||||
"serde",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "governor"
|
name = "governor"
|
||||||
version = "0.7.0"
|
version = "0.7.0"
|
||||||
|
@ -2989,6 +2995,15 @@ version = "1.70.1"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "7943c866cc5cd64cbc25b2e01621d07fa8eb2a1a23160ee81ce38704e97b8ecf"
|
checksum = "7943c866cc5cd64cbc25b2e01621d07fa8eb2a1a23160ee81ce38704e97b8ecf"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "itertools"
|
||||||
|
version = "0.11.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "b1c173a5686ce8bfa551b3563d0c2170bf24ca44da99c7ca4bfdab5418c3fe57"
|
||||||
|
dependencies = [
|
||||||
|
"either",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "itertools"
|
name = "itertools"
|
||||||
version = "0.12.1"
|
version = "0.12.1"
|
||||||
|
@ -3662,7 +3677,6 @@ dependencies = [
|
||||||
"futures",
|
"futures",
|
||||||
"git2",
|
"git2",
|
||||||
"gix",
|
"gix",
|
||||||
"globset",
|
|
||||||
"indicatif",
|
"indicatif",
|
||||||
"indicatif-log-bridge",
|
"indicatif-log-bridge",
|
||||||
"inquire",
|
"inquire",
|
||||||
|
@ -3686,6 +3700,7 @@ dependencies = [
|
||||||
"toml",
|
"toml",
|
||||||
"toml_edit",
|
"toml_edit",
|
||||||
"url",
|
"url",
|
||||||
|
"wax",
|
||||||
"winreg",
|
"winreg",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -3792,6 +3807,15 @@ dependencies = [
|
||||||
"windows-sys 0.59.0",
|
"windows-sys 0.59.0",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "pori"
|
||||||
|
version = "0.0.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "a4a63d338dec139f56dacc692ca63ad35a6be6a797442479b55acd611d79e906"
|
||||||
|
dependencies = [
|
||||||
|
"nom",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "portable-atomic"
|
name = "portable-atomic"
|
||||||
version = "1.9.0"
|
version = "1.9.0"
|
||||||
|
@ -4814,7 +4838,7 @@ dependencies = [
|
||||||
"fnv",
|
"fnv",
|
||||||
"fs4",
|
"fs4",
|
||||||
"htmlescape",
|
"htmlescape",
|
||||||
"itertools",
|
"itertools 0.12.1",
|
||||||
"levenshtein_automata",
|
"levenshtein_automata",
|
||||||
"log",
|
"log",
|
||||||
"lru",
|
"lru",
|
||||||
|
@ -4863,7 +4887,7 @@ checksum = "12722224ffbe346c7fec3275c699e508fd0d4710e629e933d5736ec524a1f44e"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"downcast-rs",
|
"downcast-rs",
|
||||||
"fastdivide",
|
"fastdivide",
|
||||||
"itertools",
|
"itertools 0.12.1",
|
||||||
"serde",
|
"serde",
|
||||||
"tantivy-bitpacker",
|
"tantivy-bitpacker",
|
||||||
"tantivy-common",
|
"tantivy-common",
|
||||||
|
@ -5488,6 +5512,20 @@ version = "0.2.95"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "65fc09f10666a9f147042251e0dda9c18f166ff7de300607007e96bdebc1068d"
|
checksum = "65fc09f10666a9f147042251e0dda9c18f166ff7de300607007e96bdebc1068d"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "wax"
|
||||||
|
version = "0.6.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "8d12a78aa0bab22d2f26ed1a96df7ab58e8a93506a3e20adb47c51a93b4e1357"
|
||||||
|
dependencies = [
|
||||||
|
"const_format",
|
||||||
|
"itertools 0.11.0",
|
||||||
|
"nom",
|
||||||
|
"pori",
|
||||||
|
"regex",
|
||||||
|
"thiserror 1.0.69",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "web-sys"
|
name = "web-sys"
|
||||||
version = "0.3.72"
|
version = "0.3.72"
|
||||||
|
|
|
@ -65,7 +65,7 @@ url = { version = "2.5.3", features = ["serde"] }
|
||||||
chrono = { version = "0.4.38", features = ["serde"] }
|
chrono = { version = "0.4.38", features = ["serde"] }
|
||||||
sha2 = "0.10.8"
|
sha2 = "0.10.8"
|
||||||
tempfile = "3.14.0"
|
tempfile = "3.14.0"
|
||||||
globset = { version = "0.4.15", features = ["serde1"] }
|
wax = { version = "0.6.0", default-features = false }
|
||||||
fs-err = { version = "3.0.0", features = ["tokio"] }
|
fs-err = { version = "3.0.0", features = ["tokio"] }
|
||||||
|
|
||||||
# TODO: remove this when gitoxide adds support for: committing, pushing, adding
|
# TODO: remove this when gitoxide adds support for: committing, pushing, adding
|
||||||
|
|
|
@ -119,9 +119,13 @@ impl PublishCommand {
|
||||||
_ => None,
|
_ => None,
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut paths = matching_globs(project.package_dir(), manifest.includes.clone(), true)
|
let mut paths = matching_globs(
|
||||||
.await
|
project.package_dir(),
|
||||||
.context("failed to get included files")?;
|
manifest.includes.iter().map(|s| s.as_str()),
|
||||||
|
true,
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
.context("failed to get included files")?;
|
||||||
|
|
||||||
if paths.insert(PathBuf::from(MANIFEST_FILE_NAME)) {
|
if paths.insert(PathBuf::from(MANIFEST_FILE_NAME)) {
|
||||||
println!(
|
println!(
|
||||||
|
|
54
src/lib.rs
54
src/lib.rs
|
@ -16,6 +16,7 @@ use std::{
|
||||||
collections::{HashMap, HashSet},
|
collections::{HashMap, HashSet},
|
||||||
path::{Path, PathBuf},
|
path::{Path, PathBuf},
|
||||||
};
|
};
|
||||||
|
use wax::Pattern;
|
||||||
|
|
||||||
/// Downloading packages
|
/// Downloading packages
|
||||||
pub mod download;
|
pub mod download;
|
||||||
|
@ -192,7 +193,12 @@ impl Project {
|
||||||
errors::WorkspaceMembersError::ManifestDeser(dir.to_path_buf(), Box::new(e))
|
errors::WorkspaceMembersError::ManifestDeser(dir.to_path_buf(), Box::new(e))
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
let members = matching_globs(dir, manifest.workspace_members, false).await?;
|
let members = matching_globs(
|
||||||
|
dir,
|
||||||
|
manifest.workspace_members.iter().map(|s| s.as_str()),
|
||||||
|
false,
|
||||||
|
)
|
||||||
|
.await?;
|
||||||
|
|
||||||
Ok(stream! {
|
Ok(stream! {
|
||||||
for path in members {
|
for path in members {
|
||||||
|
@ -210,40 +216,40 @@ impl Project {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Gets all matching paths in a directory
|
/// Gets all matching paths in a directory
|
||||||
pub async fn matching_globs<P: AsRef<Path>>(
|
pub async fn matching_globs<'a, P: AsRef<Path>, I: IntoIterator<Item = &'a str>>(
|
||||||
dir: P,
|
dir: P,
|
||||||
members: Vec<globset::Glob>,
|
globs: I,
|
||||||
relative: bool,
|
relative: bool,
|
||||||
) -> Result<HashSet<PathBuf>, errors::MatchingGlobsError> {
|
) -> Result<HashSet<PathBuf>, errors::MatchingGlobsError> {
|
||||||
let mut positive_globset = globset::GlobSetBuilder::new();
|
let (negative_globs, positive_globs): (Vec<&str>, Vec<&str>) =
|
||||||
let mut negative_globset = globset::GlobSetBuilder::new();
|
globs.into_iter().partition(|glob| glob.starts_with('!'));
|
||||||
|
|
||||||
for pattern in members {
|
let negative_globs = wax::any(
|
||||||
match pattern.glob().strip_prefix('!') {
|
negative_globs
|
||||||
Some(pattern) => negative_globset.add(globset::Glob::new(pattern)?),
|
.into_iter()
|
||||||
None => positive_globset.add(pattern),
|
.map(|glob| wax::Glob::new(&glob[1..]))
|
||||||
};
|
.collect::<Result<Vec<_>, _>>()?,
|
||||||
}
|
)?;
|
||||||
|
let positive_globs = wax::any(
|
||||||
|
positive_globs
|
||||||
|
.into_iter()
|
||||||
|
.map(wax::Glob::new)
|
||||||
|
.collect::<Result<Vec<_>, _>>()?,
|
||||||
|
)?;
|
||||||
|
|
||||||
let positive_globset = positive_globset.build()?;
|
let mut read_dirs = vec![fs::read_dir(dir.as_ref().to_path_buf()).await?];
|
||||||
let negative_globset = negative_globset.build()?;
|
|
||||||
|
|
||||||
let mut read_dirs = vec![fs::read_dir(dir.as_ref().to_path_buf())];
|
|
||||||
let mut paths = HashSet::new();
|
let mut paths = HashSet::new();
|
||||||
|
|
||||||
while let Some(read_dir) = read_dirs.pop() {
|
while let Some(mut read_dir) = read_dirs.pop() {
|
||||||
let mut read_dir = read_dir.await?;
|
|
||||||
while let Some(entry) = read_dir.next_entry().await? {
|
while let Some(entry) = read_dir.next_entry().await? {
|
||||||
let path = entry.path();
|
let path = entry.path();
|
||||||
if entry.file_type().await?.is_dir() {
|
if entry.file_type().await?.is_dir() {
|
||||||
read_dirs.push(fs::read_dir(path));
|
read_dirs.push(fs::read_dir(&path).await?);
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let relative_path = path.strip_prefix(dir.as_ref()).unwrap();
|
let relative_path = path.strip_prefix(dir.as_ref()).unwrap();
|
||||||
|
|
||||||
if positive_globset.is_match(relative_path) && !negative_globset.is_match(relative_path)
|
if positive_globs.is_match(relative_path) && !negative_globs.is_match(relative_path) {
|
||||||
{
|
|
||||||
paths.insert(if relative {
|
paths.insert(if relative {
|
||||||
relative_path.to_path_buf()
|
relative_path.to_path_buf()
|
||||||
} else {
|
} else {
|
||||||
|
@ -349,8 +355,8 @@ pub mod errors {
|
||||||
#[error("error interacting with the filesystem")]
|
#[error("error interacting with the filesystem")]
|
||||||
Io(#[from] std::io::Error),
|
Io(#[from] std::io::Error),
|
||||||
|
|
||||||
/// An error occurred while globbing
|
/// An error occurred while building a glob
|
||||||
#[error("error globbing")]
|
#[error("error building glob")]
|
||||||
Globbing(#[from] globset::Error),
|
BuildGlob(#[from] wax::BuildError),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
10
src/main.rs
10
src/main.rs
|
@ -133,9 +133,13 @@ async fn run() -> anyhow::Result<()> {
|
||||||
return Ok(HashSet::new());
|
return Ok(HashSet::new());
|
||||||
}
|
}
|
||||||
|
|
||||||
matching_globs(path, manifest.workspace_members, false)
|
matching_globs(
|
||||||
.await
|
path,
|
||||||
.context("failed to get workspace members")
|
manifest.workspace_members.iter().map(|s| s.as_str()),
|
||||||
|
false,
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
.context("failed to get workspace members")
|
||||||
}
|
}
|
||||||
|
|
||||||
while let Some(path) = current_path {
|
while let Some(path) = current_path {
|
||||||
|
|
|
@ -61,7 +61,7 @@ pub struct Manifest {
|
||||||
pub overrides: BTreeMap<OverrideKey, DependencySpecifiers>,
|
pub overrides: BTreeMap<OverrideKey, DependencySpecifiers>,
|
||||||
/// The files to include in the package
|
/// The files to include in the package
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
pub includes: Vec<globset::Glob>,
|
pub includes: Vec<String>,
|
||||||
/// The patches to apply to packages
|
/// The patches to apply to packages
|
||||||
#[cfg(feature = "patches")]
|
#[cfg(feature = "patches")]
|
||||||
#[serde(default, skip_serializing)]
|
#[serde(default, skip_serializing)]
|
||||||
|
@ -74,7 +74,7 @@ pub struct Manifest {
|
||||||
pub pesde_version: Option<Version>,
|
pub pesde_version: Option<Version>,
|
||||||
/// A list of globs pointing to workspace members' directories
|
/// A list of globs pointing to workspace members' directories
|
||||||
#[serde(default, skip_serializing_if = "Vec::is_empty")]
|
#[serde(default, skip_serializing_if = "Vec::is_empty")]
|
||||||
pub workspace_members: Vec<globset::Glob>,
|
pub workspace_members: Vec<String>,
|
||||||
/// The Roblox place of this project
|
/// The Roblox place of this project
|
||||||
#[serde(default, skip_serializing)]
|
#[serde(default, skip_serializing)]
|
||||||
pub place: BTreeMap<target::RobloxPlaceKind, String>,
|
pub place: BTreeMap<target::RobloxPlaceKind, String>,
|
||||||
|
|
Loading…
Reference in a new issue