Skip to content

Commit 9e71183

Browse files
authored
chore: Adjust vp run output styling. (#213)
This PR aligns the output of `vp run` with what's on the website, see voidzero-dev/vite-plus#758
1 parent 203440c commit 9e71183

File tree

53 files changed

+113
-85
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+113
-85
lines changed

crates/vite_task/src/session/reporter/labeled.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ struct SharedReporterState {
4646
///
4747
/// ## Compact Summary (default)
4848
/// - Single task + not cache hit → no summary at all
49-
/// - Single task + cache hit → thin line + "[vp run] cache hit, {duration} saved."
49+
/// - Single task + cache hit → thin line + "vp run: cache hit, {duration} saved."
5050
/// - Multi-task → thin line + one-liner with stats
5151
///
5252
/// ## Full Summary (`--verbose`)

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

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -227,13 +227,25 @@ fn format_command_with_cache_status(
227227
format_cache_status_inline(cache_status).map_or_else(
228228
|| vite_str::format!("{}\n", command_str.style(COMMAND_STYLE)),
229229
|inline_status| {
230-
// Apply styling based on cache status type
231-
let styled_status = match cache_status {
232-
CacheStatus::Hit { .. } => inline_status.style(Style::new().green().dimmed()),
233-
CacheStatus::Miss(_) => inline_status.style(CACHE_MISS_STYLE.dimmed()),
234-
CacheStatus::Disabled(_) => inline_status.style(Style::new().bright_black()),
235-
};
236-
vite_str::format!("{} {}\n", command_str.style(COMMAND_STYLE), styled_status)
230+
let styled_status = inline_status.split_once(' ').map_or_else(
231+
|| inline_status.style(Style::new().bright_black()).to_string(),
232+
|(symbol, text)| {
233+
let (symbol_style, text_style) = match cache_status {
234+
CacheStatus::Hit { .. } => {
235+
(Style::new().green(), Style::new().bright_black())
236+
}
237+
CacheStatus::Miss(_) => (CACHE_MISS_STYLE, Style::new().bright_black()),
238+
CacheStatus::Disabled(_) => {
239+
(Style::new().black(), Style::new().bright_black())
240+
}
241+
};
242+
243+
vite_str::format!("{} {}", symbol.style(symbol_style), text.style(text_style))
244+
.to_string()
245+
},
246+
);
247+
248+
vite_str::format!("{} {styled_status}\n", command_str.style(COMMAND_STYLE))
237249
},
238250
)
239251
}

crates/vite_task/src/session/reporter/summary.rs

Lines changed: 32 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,20 @@ fn duration_to_ms(d: Duration) -> u64 {
316316
d.as_millis().min(u128::from(u64::MAX)) as u64
317317
}
318318

319+
fn format_summary_duration(d: Duration) -> Str {
320+
let formatted = vite_str::format!("{d:.2?}");
321+
322+
for (suffix, unit) in
323+
[(".00ms", "ms"), (".00s", "s"), (".00us", "us"), (".00µs", "µs"), (".00ns", "ns")]
324+
{
325+
if let Some(prefix) = formatted.as_str().strip_suffix(suffix) {
326+
return vite_str::format!("{prefix}{unit}");
327+
}
328+
}
329+
330+
formatted
331+
}
332+
319333
impl LastRunSummary {
320334
// ── Persistence ──────────────────────────────────────────────────────
321335

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

561576
if stats.total_saved > Duration::ZERO {
577+
let formatted_total_saved = format_summary_duration(stats.total_saved);
562578
let _ = write!(
563579
buf,
564-
", {:.2?} saved in total",
565-
stats.total_saved.style(Style::new().green().bold())
580+
", {} saved in total",
581+
formatted_total_saved.style(Style::new().green().bold())
566582
);
567583
}
568584
let _ = writeln!(buf);
@@ -647,8 +663,8 @@ pub fn format_full_summary(summary: &LastRunSummary) -> Vec<u8> {
647663
///
648664
/// Rules:
649665
/// - Single task + not cache hit → empty (no summary at all)
650-
/// - Single task + cache hit → thin line + "[vp run] cache hit, {duration} saved."
651-
/// - Multi-task → thin line + "[vp run] {hits}/{total} cache hit ({rate}%), {duration} saved."
666+
/// - Single task + cache hit → thin line + "vp run: cache hit, {duration} saved."
667+
/// - Multi-task → thin line + "vp run: {hits}/{total} cache hit ({rate}%), {duration} saved."
652668
/// with optional failure count and `--verbose` hint.
653669
pub fn format_compact_summary(summary: &LastRunSummary) -> Vec<u8> {
654670
let stats = SummaryStats::compute(&summary.tasks);
@@ -667,11 +683,12 @@ pub fn format_compact_summary(summary: &LastRunSummary) -> Vec<u8> {
667683

668684
if is_single_task {
669685
// Single task cache hit
686+
let formatted_total_saved = format_summary_duration(stats.total_saved);
670687
let _ = writeln!(
671688
buf,
672-
"{} cache hit, {:.2?} saved.",
673-
"[vp run]".style(Style::new().bright_black()),
674-
stats.total_saved.style(Style::new().green().bold()),
689+
"{} cache hit, {} saved.",
690+
"vp run:".style(Style::new().blue().bold()),
691+
formatted_total_saved.style(Style::new().green().bold()),
675692
);
676693
} else {
677694
// Multi-task
@@ -692,14 +709,15 @@ pub fn format_compact_summary(summary: &LastRunSummary) -> Vec<u8> {
692709
let _ = write!(
693710
buf,
694711
"{} {hits}/{total} cache hit ({rate}%)",
695-
"[vp run]".style(Style::new().bright_black()),
712+
"vp run:".style(Style::new().blue().bold()),
696713
);
697714

698715
if stats.total_saved > Duration::ZERO {
716+
let formatted_total_saved = format_summary_duration(stats.total_saved);
699717
let _ = write!(
700718
buf,
701-
", {:.2?} saved",
702-
stats.total_saved.style(Style::new().green().bold()),
719+
", {} saved",
720+
formatted_total_saved.style(Style::new().green().bold()),
703721
);
704722
}
705723

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

711-
let _ = write!(
712-
buf,
713-
". {}",
714-
"(Run `vp run --last-details` for full details)".style(Style::new().bright_black()),
715-
);
729+
let _ = write!(buf, ". {}", "(Run ".style(Style::new().bright_black()));
730+
let _ = write!(buf, "{}", "`vp run --last-details`".style(COMMAND_STYLE));
731+
let _ = write!(buf, "{}", " for full details)".style(Style::new().bright_black()));
716732
let _ = writeln!(buf);
717733
}
718734

crates/vite_task_bin/tests/e2e_snapshots/fixtures/associate-existing-cache/snapshots/associate existing cache.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ $ print hello ✓ cache hit, replaying
1010
hello
1111

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

1616
> vp run script2 # cache miss

crates/vite_task_bin/tests/e2e_snapshots/fixtures/builtin-different-cwd/snapshots/builtin different cwd.snap

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ Found 2 warnings and 0 errors.
4242
Finished in <duration> on 2 files with 90 rules using <n> threads.
4343

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

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

7373
---
74-
[vp run] cache hit, <duration> saved.
74+
vp run: cache hit, <duration> saved.

crates/vite_task_bin/tests/e2e_snapshots/fixtures/cache-disabled/snapshots/task with cache enabled.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@ $ print-file test.txt ✓ cache hit, replaying
1010
test content
1111

1212
---
13-
[vp run] cache hit, <duration> saved.
13+
vp run: cache hit, <duration> saved.

crates/vite_task_bin/tests/e2e_snapshots/fixtures/cache-miss-command-change/snapshots/cache miss command change.snap

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ $ print bar
1010
bar
1111

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

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

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

2727
> vp run task # cache hit
2828
$ print bar ✓ cache hit, replaying
2929
bar
3030

3131
---
32-
[vp run] cache hit, <duration> saved.
32+
vp run: cache hit, <duration> saved.

crates/vite_task_bin/tests/e2e_snapshots/fixtures/cache-subcommand/snapshots/cache clean.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ $ print-file test.txt ✓ cache hit, replaying
1010
test content
1111

1212
---
13-
[vp run] cache hit, <duration> saved.
13+
vp run: cache hit, <duration> saved.
1414
> vp cache clean
1515

1616
> vp run cached-task # cache miss after clean

crates/vite_task_bin/tests/e2e_snapshots/fixtures/colon-in-name/snapshots/read file with colon in name.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ $ node read_node_fs.js
88
$ node read_node_fs.jscache hit, replaying
99

1010
---
11-
[vp run] cache hit, <duration> saved.
11+
vp run: cache hit, <duration> saved.

crates/vite_task_bin/tests/e2e_snapshots/fixtures/exit-codes/snapshots/multiple task failures returns exit code 1.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ expression: e2e_outputs
88
~/packages/pkg-b$ node -e "process.exit(7)"
99

1010
---
11-
[vp run] 0/2 cache hit (0%), 2 failed. (Run `vp run --last-details` for full details)
11+
vp run: 0/2 cache hit (0%), 2 failed. (Run `vp run --last-details` for full details)

0 commit comments

Comments
 (0)