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
2 changes: 1 addition & 1 deletion crates/vite_task/src/session/reporter/labeled.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ struct SharedReporterState {
///
/// ## Compact Summary (default)
/// - Single task + not cache hit → no summary at all
/// - Single task + cache hit → thin line + "[vp run] cache hit, {duration} saved."
/// - Single task + cache hit → thin line + "vp run: cache hit, {duration} saved."
/// - Multi-task → thin line + one-liner with stats
///
/// ## Full Summary (`--verbose`)
Expand Down
26 changes: 19 additions & 7 deletions crates/vite_task/src/session/reporter/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -227,13 +227,25 @@ fn format_command_with_cache_status(
format_cache_status_inline(cache_status).map_or_else(
|| vite_str::format!("{}\n", command_str.style(COMMAND_STYLE)),
|inline_status| {
// Apply styling based on cache status type
let styled_status = match cache_status {
CacheStatus::Hit { .. } => inline_status.style(Style::new().green().dimmed()),
CacheStatus::Miss(_) => inline_status.style(CACHE_MISS_STYLE.dimmed()),
CacheStatus::Disabled(_) => inline_status.style(Style::new().bright_black()),
};
vite_str::format!("{} {}\n", command_str.style(COMMAND_STYLE), styled_status)
let styled_status = inline_status.split_once(' ').map_or_else(
|| inline_status.style(Style::new().bright_black()).to_string(),
|(symbol, text)| {
let (symbol_style, text_style) = match cache_status {
CacheStatus::Hit { .. } => {
(Style::new().green(), Style::new().bright_black())
}
CacheStatus::Miss(_) => (CACHE_MISS_STYLE, Style::new().bright_black()),
CacheStatus::Disabled(_) => {
(Style::new().black(), Style::new().bright_black())
}
};

vite_str::format!("{} {}", symbol.style(symbol_style), text.style(text_style))
.to_string()
},
);

vite_str::format!("{} {styled_status}\n", command_str.style(COMMAND_STYLE))
},
)
}
Expand Down
48 changes: 32 additions & 16 deletions crates/vite_task/src/session/reporter/summary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,20 @@ fn duration_to_ms(d: Duration) -> u64 {
d.as_millis().min(u128::from(u64::MAX)) as u64
}

fn format_summary_duration(d: Duration) -> Str {
let formatted = vite_str::format!("{d:.2?}");

for (suffix, unit) in
[(".00ms", "ms"), (".00s", "s"), (".00us", "us"), (".00µs", "µs"), (".00ns", "ns")]
{
if let Some(prefix) = formatted.as_str().strip_suffix(suffix) {
return vite_str::format!("{prefix}{unit}");
}
}

formatted
}

impl LastRunSummary {
// ── Persistence ──────────────────────────────────────────────────────

Expand Down Expand Up @@ -404,7 +418,8 @@ impl TaskResult {
match self {
Self::CacheHit { saved_duration_ms } => {
let d = Duration::from_millis(*saved_duration_ms);
vite_str::format!("→ Cache hit - output replayed - {d:.2?} saved")
let formatted_duration = format_summary_duration(d);
vite_str::format!("→ Cache hit - output replayed - {formatted_duration} saved")
}
Self::InProcess => Str::from("→ Cache disabled for built-in command"),
Self::Spawned { cache_status, .. } => match cache_status {
Expand Down Expand Up @@ -559,10 +574,11 @@ pub fn format_full_summary(summary: &LastRunSummary) -> Vec<u8> {
);

if stats.total_saved > Duration::ZERO {
let formatted_total_saved = format_summary_duration(stats.total_saved);
let _ = write!(
buf,
", {:.2?} saved in total",
stats.total_saved.style(Style::new().green().bold())
", {} saved in total",
formatted_total_saved.style(Style::new().green().bold())
);
}
let _ = writeln!(buf);
Expand Down Expand Up @@ -647,8 +663,8 @@ pub fn format_full_summary(summary: &LastRunSummary) -> Vec<u8> {
///
/// Rules:
/// - Single task + not cache hit → empty (no summary at all)
/// - Single task + cache hit → thin line + "[vp run] cache hit, {duration} saved."
/// - Multi-task → thin line + "[vp run] {hits}/{total} cache hit ({rate}%), {duration} saved."
/// - Single task + cache hit → thin line + "vp run: cache hit, {duration} saved."
/// - Multi-task → thin line + "vp run: {hits}/{total} cache hit ({rate}%), {duration} saved."
/// with optional failure count and `--verbose` hint.
pub fn format_compact_summary(summary: &LastRunSummary) -> Vec<u8> {
let stats = SummaryStats::compute(&summary.tasks);
Expand All @@ -667,11 +683,12 @@ pub fn format_compact_summary(summary: &LastRunSummary) -> Vec<u8> {

if is_single_task {
// Single task cache hit
let formatted_total_saved = format_summary_duration(stats.total_saved);
let _ = writeln!(
buf,
"{} cache hit, {:.2?} saved.",
"[vp run]".style(Style::new().bright_black()),
stats.total_saved.style(Style::new().green().bold()),
"{} cache hit, {} saved.",
"vp run:".style(Style::new().blue().bold()),
formatted_total_saved.style(Style::new().green().bold()),
);
} else {
// Multi-task
Expand All @@ -692,14 +709,15 @@ pub fn format_compact_summary(summary: &LastRunSummary) -> Vec<u8> {
let _ = write!(
buf,
"{} {hits}/{total} cache hit ({rate}%)",
"[vp run]".style(Style::new().bright_black()),
"vp run:".style(Style::new().blue().bold()),
);

if stats.total_saved > Duration::ZERO {
let formatted_total_saved = format_summary_duration(stats.total_saved);
let _ = write!(
buf,
", {:.2?} saved",
stats.total_saved.style(Style::new().green().bold()),
", {} saved",
formatted_total_saved.style(Style::new().green().bold()),
);
}

Expand All @@ -708,11 +726,9 @@ pub fn format_compact_summary(summary: &LastRunSummary) -> Vec<u8> {
let _ = write!(buf, ", {} failed", n.style(Style::new().red()));
}

let _ = write!(
buf,
". {}",
"(Run `vp run --last-details` for full details)".style(Style::new().bright_black()),
);
let _ = write!(buf, ". {}", "(Run ".style(Style::new().bright_black()));
let _ = write!(buf, "{}", "`vp run --last-details`".style(COMMAND_STYLE));
let _ = write!(buf, "{}", " for full details)".style(Style::new().bright_black()));
let _ = writeln!(buf);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ $ print hello ✓ cache hit, replaying
hello

---
[vp run] cache hit, <duration> saved.
vp run: cache hit, <duration> saved.
> json-edit package.json '_.scripts.script2 = "print world"' # change script2

> vp run script2 # cache miss
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ Found 2 warnings and 0 errors.
Finished in <duration> on 2 files with 90 rules using <n> threads.

---
[vp run] cache hit, <duration> saved.
vp run: cache hit, <duration> saved.
> echo 'console.log(1);' > folder2/a.js # modify folder2

> cd folder1 && vp run lint # cache hit
Expand Down Expand Up @@ -71,4 +71,4 @@ Found 1 warning and 0 errors.
Finished in <duration> on 2 files with 90 rules using <n> threads.

---
[vp run] cache hit, <duration> saved.
vp run: cache hit, <duration> saved.
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ $ print-file test.txt ✓ cache hit, replaying
test content

---
[vp run] cache hit, <duration> saved.
vp run: cache hit, <duration> saved.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ $ print bar
bar

---
[vp run] 0/2 cache hit (0%). (Run `vp run --last-details` for full details)
vp run: 0/2 cache hit (0%). (Run `vp run --last-details` for full details)
> json-edit package.json '_.scripts.task = "print baz && print bar"' # change first subtask

> vp run task # first: cache miss, second: cache hit
Expand All @@ -21,12 +21,12 @@ $ print bar ✓ cache hit, replaying
bar

---
[vp run] 1/2 cache hit (50%), <duration> saved. (Run `vp run --last-details` for full details)
vp run: 1/2 cache hit (50%), <duration> saved. (Run `vp run --last-details` for full details)
> json-edit package.json '_.scripts.task = "print bar"' # remove first subtask

> vp run task # cache hit
$ print bar ✓ cache hit, replaying
bar

---
[vp run] cache hit, <duration> saved.
vp run: cache hit, <duration> saved.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ $ print-file test.txt ✓ cache hit, replaying
test content

---
[vp run] cache hit, <duration> saved.
vp run: cache hit, <duration> saved.
> vp cache clean

> vp run cached-task # cache miss after clean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ $ node read_node_fs.js
$ node read_node_fs.js ✓ cache hit, replaying

---
[vp run] cache hit, <duration> saved.
vp run: cache hit, <duration> saved.
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ expression: e2e_outputs
~/packages/pkg-b$ node -e "process.exit(7)"

---
[vp run] 0/2 cache hit (0%), 2 failed. (Run `vp run --last-details` for full details)
vp run: 0/2 cache hit (0%), 2 failed. (Run `vp run --last-details` for full details)
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ $ print-file src/root.ts ✓ cache hit, replaying
export const root = 'initial';

---
[vp run] cache hit, <duration> saved.
vp run: cache hit, <duration> saved.
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ $ print-file src/root.ts ✓ cache hit, replaying
export const root = 'initial';

---
[vp run] cache hit, <duration> saved.
vp run: cache hit, <duration> saved.
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ export const sub = 'initial';
export const sub = 'initial';

---
[vp run] cache hit, <duration> saved.
vp run: cache hit, <duration> saved.
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ export const sub = 'initial';
export const sub = 'initial';

---
[vp run] cache hit, <duration> saved.
vp run: cache hit, <duration> saved.
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ $ print a ✓ cache hit, replaying
a

---
[vp run] cache hit, <duration> saved.
vp run: cache hit, <duration> saved.
> vp run say b # cache hit
$ print b ✓ cache hit, replaying
b

---
[vp run] cache hit, <duration> saved.
vp run: cache hit, <duration> saved.
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ $ print-env FOO ✓ cache hit, replaying
1

---
[vp run] cache hit, <duration> saved.
vp run: cache hit, <duration> saved.
> FOO=2 vp run hello # cache hit
$ print-env FOO ✓ cache hit, replaying
2

---
[vp run] cache hit, <duration> saved.
vp run: cache hit, <duration> saved.
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ $ print-file src/main.ts ✓ cache hit, replaying
export const main = 'initial';

---
[vp run] cache hit, <duration> saved.
vp run: cache hit, <duration> saved.
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ export const main = 'initial';
// initial output

---
[vp run] cache hit, <duration> saved.
vp run: cache hit, <duration> saved.
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ $ print-file src/main.ts ✓ cache hit, replaying
export const main = 'initial';

---
[vp run] cache hit, <duration> saved.
vp run: cache hit, <duration> saved.
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ $ print-file src/main.ts ✓ cache hit, replaying
export const main = 'initial';

---
[vp run] cache hit, <duration> saved.
vp run: cache hit, <duration> saved.
> rm -rf src

> vp run folder-input
$ print-file src/main.ts ✓ cache hit, replaying
export const main = 'initial';

---
[vp run] cache hit, <duration> saved.
vp run: cache hit, <duration> saved.
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ $ print-file src/main.ts ✓ cache hit, replaying
export const main = 'initial';

---
[vp run] cache hit, <duration> saved.
vp run: cache hit, <duration> saved.
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ $ print-file src/main.ts ✓ cache hit, replaying
export const main = 'initial';

---
[vp run] cache hit, <duration> saved.
vp run: cache hit, <duration> saved.
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ export const main = 'initial';
export const utils = 'initial';

---
[vp run] cache hit, <duration> saved.
vp run: cache hit, <duration> saved.
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ $ print-file src/main.ts ✓ cache hit, replaying
export const main = 'initial';

---
[vp run] cache hit, <duration> saved.
vp run: cache hit, <duration> saved.
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ $ print-file src/main.ts ✓ cache hit, replaying
export const main = 'initial';

---
[vp run] cache hit, <duration> saved.
vp run: cache hit, <duration> saved.
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ $ print-file src/main.ts ✓ cache hit, replaying
export const main = 'initial';

---
[vp run] cache hit, <duration> saved.
vp run: cache hit, <duration> saved.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export const lib = 'initial';
export const lib = 'initial';

---
[vp run] cache hit, <duration> saved.
vp run: cache hit, <duration> saved.
> replace-file-content packages/[lib]/src/main.ts initial modified

> vp run [lib]#build
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ export const shared = 'initial';
// initial output

---
[vp run] cache hit, <duration> saved.
vp run: cache hit, <duration> saved.
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ export const shared = 'initial';
export const shared = 'initial';

---
[vp run] cache hit, <duration> saved.
vp run: cache hit, <duration> saved.
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ export const shared = 'initial';
// initial output

---
[vp run] cache hit, <duration> saved.
vp run: cache hit, <duration> saved.
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ export const main = 'initial';
// initial output

---
[vp run] cache hit, <duration> saved.
vp run: cache hit, <duration> saved.
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,4 @@ Found 1 warning and 0 errors.
Finished in <duration> on 1 file with 90 rules using <n> threads.

---
[vp run] cache hit, <duration> saved.
vp run: cache hit, <duration> saved.
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ $ node build.js ✓ cache hit, replaying
[build.js] main process end

---
[vp run] cache hit, <duration> saved.
vp run: cache hit, <duration> saved.
> vp run build # cache hit
$ node build.js ✓ cache hit, replaying
[build.js] --------------------------------
Expand Down Expand Up @@ -292,4 +292,4 @@ $ node build.js ✓ cache hit, replaying
[build.js] main process end

---
[vp run] cache hit, <duration> saved.
vp run: cache hit, <duration> saved.
Loading