Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Changelog

- **Changed** Cache misses caused by a tracked env var now name the env var inline, for example `cache miss: env 'NODE_ENV' changed`, instead of the generic `envs changed` message ([#438](https://github.com/voidzero-dev/vite-task/pull/438))
- **Fixed** The task cache is now stored in a per-schema-version subdirectory (e.g. `node_modules/.vite/task-cache/v13/`), so switching between branches that pin different Vite+ versions no longer fails with `Unrecognized database version`. Each version keeps its own cache directory; a cache from a different version is ignored rather than aborting the run ([#433](https://github.com/voidzero-dev/vite-task/pull/433))
- **Added** A task's `env` and `untrackedEnv` glob patterns now support `!` negation: a `!`-prefixed pattern excludes matching variables (e.g. `["VITE_*", "!VITE_SECRET"]` tracks every `VITE_*` except `VITE_SECRET`) ([#425](https://github.com/voidzero-dev/vite-task/pull/425))
- **Fixed** `package.json` and `pnpm-workspace.yaml` files with a UTF-8 BOM no longer fail to parse ([#424](https://github.com/voidzero-dev/vite-task/pull/424))
Expand Down
53 changes: 43 additions & 10 deletions crates/vite_task/src/session/cache/display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,34 @@ pub fn detect_spawn_fingerprint_changes(
changes
}

/// Names of the env vars involved in a set of spawn-fingerprint changes, in the
/// order detected. Only env changes are collected; untracked-env and non-env
/// changes are skipped.
fn env_change_names(changes: &[SpawnFingerprintChange]) -> Vec<&Str> {
changes
.iter()
.filter_map(|change| match change {
SpawnFingerprintChange::Env(mismatch) => Some(mismatch.name()),
_ => None,
})
.collect()
}

/// Inline cache-miss reason naming the env var(s) that changed, e.g.
/// `env 'NODE_ENV' changed` or `envs 'A', 'B' changed`. Falls back to the
/// generic `envs changed` when no names are available.
fn format_env_changed_inline(names: &[&Str]) -> Str {
match names {
[] => Str::from("envs changed"),
[name] => vite_str::format!("env '{name}' changed"),
names => {
let quoted: Vec<Str> = names.iter().map(|name| vite_str::format!("'{name}'")).collect();
let joined = quoted.iter().map(Str::as_str).collect::<Vec<_>>().join(", ");
vite_str::format!("envs {joined} changed")
}
}
}

/// Format cache status for inline display (during Start event).
///
/// Returns `Some(formatted_string)` for Hit, Miss with reason, and Disabled, None for `NotFound`.
Expand All @@ -145,22 +173,27 @@ pub fn format_cache_status_inline(cache_status: &CacheStatus) -> Option<Str> {
FingerprintMismatch::SpawnFingerprint { old, new } => {
let changes = detect_spawn_fingerprint_changes(old, new);
match changes.first() {
Some(SpawnFingerprintChange::Env(_)) => "envs changed",
Some(SpawnFingerprintChange::Env(_)) => {
format_env_changed_inline(&env_change_names(&changes))
}
Some(
SpawnFingerprintChange::UntrackedEnvAdded { .. }
| SpawnFingerprintChange::UntrackedEnvRemoved { .. },
) => "untracked env config changed",
Some(SpawnFingerprintChange::ProgramChanged) => "program changed",
Some(SpawnFingerprintChange::ArgsChanged) => "args changed",
Some(SpawnFingerprintChange::CwdChanged) => "working directory changed",
None => "configuration changed",
) => Str::from("untracked env config changed"),
Some(SpawnFingerprintChange::ProgramChanged) => {
Str::from("program changed")
}
Some(SpawnFingerprintChange::ArgsChanged) => Str::from("args changed"),
Some(SpawnFingerprintChange::CwdChanged) => {
Str::from("working directory changed")
}
None => Str::from("configuration changed"),
}
}
FingerprintMismatch::InputConfig => "input configuration changed",
FingerprintMismatch::OutputConfig => "output configuration changed",
FingerprintMismatch::InputConfig => Str::from("input configuration changed"),
FingerprintMismatch::OutputConfig => Str::from("output configuration changed"),
FingerprintMismatch::InputChanged { kind, path } => {
let desc = format_input_change_str(*kind, path.as_str());
return Some(vite_str::format!("○ cache miss: {desc}, executing"));
format_input_change_str(*kind, path.as_str())
}
};
Some(vite_str::format!("○ cache miss: {reason}, executing"))
Expand Down
12 changes: 12 additions & 0 deletions crates/vite_task/src/session/cache/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,18 @@ pub enum EnvMismatch {
Changed { name: Str, old_value: Str, new_value: Str },
}

impl EnvMismatch {
/// The name of the env var that diverged.
#[must_use]
pub const fn name(&self) -> &Str {
match self {
Self::Added { name, .. } | Self::Removed { name, .. } | Self::Changed { name, .. } => {
name
}
}
}
}

impl Display for EnvMismatch {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ initial content
cache miss: env added

```
$ vtt print-file test.txt ○ cache miss: envs changed, executing
$ vtt print-file test.txt ○ cache miss: env 'MY_ENV' changed, executing
initial content
```
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ initial content
cache miss: env removed

```
$ vtt print-file test.txt ○ cache miss: envs changed, executing
$ vtt print-file test.txt ○ cache miss: env 'MY_ENV' changed, executing
initial content
```
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ initial content
cache miss: env value changed

```
$ vtt print-file test.txt ○ cache miss: envs changed, executing
$ vtt print-file test.txt ○ cache miss: env 'MY_ENV' changed, executing
initial content
```
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ $ vtt print-env FOO
cache miss, different env

```
$ vtt print-env FOO ○ cache miss: envs changed, executing
$ vtt print-env FOO ○ cache miss: env 'FOO' changed, executing
2
```

Expand Down
Loading