Skip to content

Commit d57ce13

Browse files
wan9chicodex
andauthored
refactor(glob): use vite_glob for fspy negatives (#476)
## Motivation Centralize the simple fspy negative-glob path checks on `vite_glob` instead of compiling and matching `wax::Glob` directly in `vite_task`. ## Changes - Store fspy negative filters as `vite_glob::path::PathGlobSet`. - Use `PathGlobSet::is_match` for post-run input/output filtering. - Remove the local `matches_any_glob` helper. Co-authored-by: GPT-5 Codex <codex@openai.com>
1 parent 734d36b commit d57ce13

2 files changed

Lines changed: 14 additions & 29 deletions

File tree

crates/vite_task/src/session/execute/cache_update.rs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ pub(super) async fn update_cache(
196196
fn observe_fspy(
197197
outcome: &ChildOutcome,
198198
metadata: &CacheMetadata,
199-
fspy: Option<&super::FspyTracking>,
199+
fspy: Option<&super::FspyTracking<'_>>,
200200
ignored_input_rels: &FxHashSet<RelativePathBuf>,
201201
ignored_output_rels: &FxHashSet<RelativePathBuf>,
202202
workspace_root: &AbsolutePath,
@@ -217,7 +217,7 @@ fn observe_fspy(
217217
.path_reads
218218
.iter()
219219
.filter(|(path, _)| {
220-
!matches_any_glob(path, &fspy.input_negative_globs)
220+
!fspy.input_negative_globs.is_match(path.as_str())
221221
&& !is_ignored(path, ignored_input_rels)
222222
})
223223
.map(|(path, read)| (path.clone(), *read))
@@ -235,7 +235,7 @@ fn observe_fspy(
235235
.path_writes
236236
.iter()
237237
.filter(|path| {
238-
!matches_any_glob(path, &fspy.output_negative_globs)
238+
!fspy.output_negative_globs.is_match(path.as_str())
239239
&& !is_ignored(path, ignored_output_rels)
240240
})
241241
.cloned()
@@ -295,12 +295,6 @@ fn is_ignored(path: &RelativePathBuf, ignored: &FxHashSet<RelativePathBuf>) -> b
295295
ignored.contains(path) || ignored.iter().any(|ig| path.strip_prefix(ig).is_some())
296296
}
297297

298-
fn matches_any_glob(path: &RelativePathBuf, globs: &[wax::Glob<'static>]) -> bool {
299-
use wax::Program as _;
300-
301-
globs.iter().any(|glob| glob.is_match(path.as_str()))
302-
}
303-
304298
/// Select tool-reported env records to embed in the post-run fingerprint.
305299
/// Names that the user already declared as fingerprinted are skipped because
306300
/// their values are already in the spawn fingerprint.

crates/vite_task/src/session/execute/mod.rs

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ use std::{
1919

2020
use futures_util::future::LocalBoxFuture;
2121
use tokio_util::sync::CancellationToken;
22+
use vite_glob::path::PathGlobSet;
2223
use vite_path::{AbsolutePath, RelativePathBuf};
2324
use vite_task_ipc_shared::NODE_CLIENT_PATH_ENV_NAME;
2425
use vite_task_plan::{SpawnExecution, cache_metadata::CacheMetadata};
@@ -92,7 +93,7 @@ struct CacheState<'a> {
9293
/// available, and fspy path tracing is attached only when auto input or
9394
/// output inference needs it. Parts are borrowed in place during the
9495
/// wait/join; the struct is never moved out.
95-
tracking: Tracking,
96+
tracking: Tracking<'a>,
9697
}
9798

9899
/// The IPC server's driver future: resolves with the recorded reports after
@@ -101,15 +102,15 @@ type IpcDriver = LocalBoxFuture<'static, Result<Recorder, vite_task_server::Erro
101102

102103
/// fspy path-tracking state, present only when a cached task needs automatic
103104
/// input or output inference.
104-
struct FspyTracking {
105-
input_negative_globs: Vec<wax::Glob<'static>>,
106-
output_negative_globs: Vec<wax::Glob<'static>>,
105+
struct FspyTracking<'a> {
106+
input_negative_globs: PathGlobSet<'a>,
107+
output_negative_globs: PathGlobSet<'a>,
107108
}
108109

109110
/// Per-task runner-aware tracking: IPC server handle plus optional fspy state.
110111
/// Lifetime-tied to a single `execute_spawn` call.
111-
struct Tracking {
112-
fspy: Option<FspyTracking>,
112+
struct Tracking<'a> {
113+
fspy: Option<FspyTracking<'a>>,
113114
ipc_envs: Vec<(&'static OsStr, OsString)>,
114115
ipc_server_fut: IpcDriver,
115116
stop_accepting: StopAccepting,
@@ -168,20 +169,10 @@ impl<'a> ExecutionMode<'a> {
168169
let fspy = if metadata.input_config.includes_auto || metadata.output_config.includes_auto {
169170
// Resolve negative globs for fspy path filtering (already
170171
// workspace-root-relative).
171-
let input_negative_globs = metadata
172-
.input_config
173-
.negative_globs
174-
.iter()
175-
.map(|p| Ok(wax::Glob::new(p.as_str())?.into_owned()))
176-
.collect::<anyhow::Result<Vec<_>>>()
177-
.map_err(ExecutionError::PostRunFingerprint)?;
178-
let output_negative_globs = metadata
179-
.output_config
180-
.negative_globs
181-
.iter()
182-
.map(|p| Ok(wax::Glob::new(p.as_str())?.into_owned()))
183-
.collect::<anyhow::Result<Vec<_>>>()
184-
.map_err(ExecutionError::PostRunFingerprint)?;
172+
let input_negative_globs = PathGlobSet::new(&metadata.input_config.negative_globs)
173+
.map_err(|err| ExecutionError::PostRunFingerprint(err.into()))?;
174+
let output_negative_globs = PathGlobSet::new(&metadata.output_config.negative_globs)
175+
.map_err(|err| ExecutionError::PostRunFingerprint(err.into()))?;
185176
Some(FspyTracking { input_negative_globs, output_negative_globs })
186177
} else {
187178
None

0 commit comments

Comments
 (0)