Skip to content

Commit 713bf28

Browse files
claudebranchseer
authored andcommitted
refactor: resolve glob patterns to workspace-root-relative at task graph stage
Move glob pattern resolution from execution time to task graph construction, making all glob patterns workspace-root-relative. This eliminates AnchoredGlob usage, removes glob_base from CacheMetadata/CacheEntryKey, and simplifies the execution pipeline. Key changes: - Add resolve_glob_to_workspace_relative() in vite_task_graph config - Remove glob_base field from CacheMetadata and CacheEntryKey - Update glob_inputs to work with workspace-root-relative patterns - Update spawn.rs negative glob filtering with path cleaning - Bump cache DB version from 9 to 10 - Remove vite_glob dependency from vite_task - Remove plan file https://claude.ai/code/session_01PR9yhnScRoVoHUcviV47u5
1 parent 9291a76 commit 713bf28

38 files changed

Lines changed: 374 additions & 389 deletions

File tree

Cargo.lock

Lines changed: 3 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/vite_task/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ thiserror = { workspace = true }
3434
tokio = { workspace = true, features = ["rt-multi-thread", "io-std", "io-util", "macros", "sync"] }
3535
tracing = { workspace = true }
3636
twox-hash = { workspace = true }
37-
vite_glob = { workspace = true }
3837
vite_path = { workspace = true }
3938
vite_select = { workspace = true }
4039
vite_str = { workspace = true }

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

Lines changed: 14 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -37,39 +37,16 @@ pub struct CacheEntryKey {
3737
/// The spawn fingerprint (command, args, cwd, envs)
3838
pub spawn_fingerprint: SpawnFingerprint,
3939
/// Resolved input configuration that affects cache behavior.
40+
/// Glob patterns are workspace-root-relative.
4041
pub input_config: ResolvedInputConfig,
41-
/// Base directory for glob patterns, relative to workspace root.
42-
/// This is where the task is defined (package path).
43-
pub glob_base: RelativePathBuf,
4442
}
4543

4644
impl CacheEntryKey {
47-
#[expect(
48-
clippy::disallowed_macros,
49-
reason = "anyhow::anyhow! internally uses std::format! for error messages"
50-
)]
51-
fn from_metadata(
52-
cache_metadata: &CacheMetadata,
53-
workspace_root: &AbsolutePath,
54-
) -> anyhow::Result<Self> {
55-
// Convert absolute glob_base to relative for cache key
56-
let glob_base = cache_metadata
57-
.glob_base
58-
.strip_prefix(workspace_root)
59-
.map_err(|e| anyhow::anyhow!("failed to strip prefix from glob_base: {e}"))?
60-
.ok_or_else(|| {
61-
anyhow::anyhow!(
62-
"glob_base {:?} is not inside workspace {:?}",
63-
cache_metadata.glob_base,
64-
workspace_root
65-
)
66-
})?;
67-
68-
Ok(Self {
45+
fn from_metadata(cache_metadata: &CacheMetadata) -> Self {
46+
Self {
6947
spawn_fingerprint: cache_metadata.spawn_fingerprint.clone(),
7048
input_config: cache_metadata.input_config.clone(),
71-
glob_base,
72-
})
49+
}
7350
}
7451
}
7552

@@ -116,7 +93,7 @@ pub enum FingerprintMismatch {
11693
/// The fingerprint of the current execution
11794
new: SpawnFingerprint,
11895
},
119-
/// Found a previous cache entry key for the same task, but `input_config` or `glob_base` differs.
96+
/// Found a previous cache entry key for the same task, but `input_config` differs.
12097
InputConfig,
12198
/// Found the cache entry with the same spawn fingerprint, but an explicit globbed input changed
12299
GlobbedInput { path: RelativePathBuf },
@@ -172,16 +149,16 @@ impl ExecutionCache {
172149
"CREATE TABLE task_fingerprints (key BLOB PRIMARY KEY, value BLOB);",
173150
(),
174151
)?;
175-
conn.execute("PRAGMA user_version = 9", ())?;
152+
conn.execute("PRAGMA user_version = 10", ())?;
176153
}
177-
1..=8 => {
154+
1..=9 => {
178155
// old internal db version. reset
179156
conn.set_db_config(DbConfig::SQLITE_DBCONFIG_RESET_DATABASE, true)?;
180157
conn.execute("VACUUM", ())?;
181158
conn.set_db_config(DbConfig::SQLITE_DBCONFIG_RESET_DATABASE, false)?;
182159
}
183-
9 => break, // current version
184-
10.. => {
160+
10 => break, // current version
161+
11.. => {
185162
return Err(anyhow::anyhow!("Unrecognized database version: {user_version}"));
186163
}
187164
}
@@ -208,9 +185,9 @@ impl ExecutionCache {
208185
let spawn_fingerprint = &cache_metadata.spawn_fingerprint;
209186
let execution_cache_key = &cache_metadata.execution_cache_key;
210187

211-
let cache_key = CacheEntryKey::from_metadata(cache_metadata, workspace_root)?;
188+
let cache_key = CacheEntryKey::from_metadata(cache_metadata);
212189

213-
// Try to find the cache entry by key (spawn fingerprint + input config + glob base)
190+
// Try to find the cache entry by key (spawn fingerprint + input config)
214191
if let Some(cache_value) = self.get_by_cache_key(&cache_key).await? {
215192
// Validate explicit globbed inputs against the stored values
216193
if let Some(mismatch) =
@@ -239,11 +216,8 @@ impl ExecutionCache {
239216
self.get_cache_key_by_execution_key(execution_cache_key).await?
240217
{
241218
// Destructure to ensure we handle all fields when new ones are added
242-
let CacheEntryKey {
243-
spawn_fingerprint: old_spawn_fingerprint,
244-
input_config: _,
245-
glob_base: _,
246-
} = old_cache_key;
219+
let CacheEntryKey { spawn_fingerprint: old_spawn_fingerprint, input_config: _ } =
220+
old_cache_key;
247221
let mismatch = if old_spawn_fingerprint == *spawn_fingerprint {
248222
// spawn fingerprint is the same but input_config or glob_base changed
249223
FingerprintMismatch::InputConfig
@@ -264,12 +238,11 @@ impl ExecutionCache {
264238
pub async fn update(
265239
&self,
266240
cache_metadata: &CacheMetadata,
267-
workspace_root: &AbsolutePath,
268241
cache_value: CacheEntryValue,
269242
) -> anyhow::Result<()> {
270243
let execution_cache_key = &cache_metadata.execution_cache_key;
271244

272-
let cache_key = CacheEntryKey::from_metadata(cache_metadata, workspace_root)?;
245+
let cache_key = CacheEntryKey::from_metadata(cache_metadata);
273246

274247
self.upsert_cache_entry(&cache_key, &cache_value).await?;
275248
self.upsert_task_fingerprint(execution_cache_key, &cache_key).await?;

0 commit comments

Comments
 (0)