Skip to content

Commit 9263ec2

Browse files
branchseerclaude
andcommitted
feat(vite_glob): add walk module with common-ancestor rerooting
Walk positive globs using wax, rerooting negative globs onto a common ancestor so wax can prune entire directory subtrees via `.not()`. This handles all prefix relationship cases (equal, ancestor, descendant, unrelated) correctly. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 453e44e commit 9263ec2

6 files changed

Lines changed: 705 additions & 0 deletions

File tree

Cargo.lock

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/vite_glob/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,13 @@ rust-version.workspace = true
99

1010
[dependencies]
1111
path-clean = { workspace = true }
12+
rustc-hash = { workspace = true }
1213
thiserror = { workspace = true }
1314
vite_path = { workspace = true }
1415
wax = { workspace = true }
1516

1617
[dev-dependencies]
18+
tempfile = { workspace = true }
1719
vite_str = { workspace = true }
1820

1921
[lints]

crates/vite_glob/src/anchored.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,18 @@ impl AnchoredGlob {
4747
Ok(Self { prefix, variant: variant.map(Glob::into_owned) })
4848
}
4949

50+
/// The invariant prefix directory of this glob.
51+
#[must_use]
52+
pub(crate) fn prefix(&self) -> &AbsolutePath {
53+
&self.prefix
54+
}
55+
56+
/// The variant (dynamic) portion of this glob, if any.
57+
#[must_use]
58+
pub(crate) const fn variant(&self) -> Option<&Glob<'static>> {
59+
self.variant.as_ref()
60+
}
61+
5062
/// Check if an absolute path matches this anchored glob.
5163
#[must_use]
5264
pub fn is_match(&self, path: &AbsolutePath) -> bool {

crates/vite_glob/src/error.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,6 @@
22
pub enum Error {
33
#[error(transparent)]
44
WaxBuild(#[from] wax::BuildError),
5+
#[error(transparent)]
6+
Walk(#[from] wax::walk::WalkError),
57
}

crates/vite_glob/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
mod anchored;
22
mod error;
3+
pub mod walk;
34

45
#[expect(clippy::disallowed_types, reason = "wax::Glob::is_match requires std::path::Path")]
56
use std::path::Path;

0 commit comments

Comments
 (0)