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
9 changes: 8 additions & 1 deletion crates/vite_task/src/schedule.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use crate::{
config::{DisplayOptions, ResolvedTask, Workspace},
execute::{OutputKind, execute_task},
fs::FileSystem,
ui::get_display_command,
};

#[derive(Debug)]
Expand All @@ -26,6 +27,7 @@ pub struct ExecutionPlan {
/// Status of a task before execution
#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct PreExecutionStatus {
pub display_command: Option<String>,
pub task: ResolvedTask,
pub cache_status: CacheStatus,
pub display_options: DisplayOptions,
Expand Down Expand Up @@ -148,7 +150,12 @@ impl ExecutionPlan {
.await?;

let has_inner_runner = step.resolved_config.config.command.has_inner_runner();
let pre_execution_status = PreExecutionStatus { task: step, cache_status, display_options };
let pre_execution_status = PreExecutionStatus {
display_command: get_display_command(display_options, &step),
task: step,
cache_status,
display_options,
};

// The inner runner is expected to display the command and the cache status. The outer runner will skip displaying them.
if !has_inner_runner {
Expand Down
58 changes: 37 additions & 21 deletions crates/vite_task/src/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use vite_path::RelativePath;

use crate::{
cache::{CacheMiss, FingerprintMismatch},
config::{DisplayOptions, ResolvedTask},
fingerprint::PostRunFingerprintMismatch,
schedule::{CacheStatus, ExecutionFailure, ExecutionSummary, PreExecutionStatus},
};
Expand All @@ -22,27 +23,38 @@ impl<T: owo_colors::OwoColorize> ColorizeExt for T {
}
}

const COMMAND_STYLE: Style = Style::new().cyan();
const CACHE_MISS_STYLE: Style = Style::new().purple();

pub fn get_display_command(display_options: DisplayOptions, task: &ResolvedTask) -> Option<String> {
let display_command = if display_options.hide_command {
if let Ok(outer_command) = std::env::var("VITE_OUTER_COMMAND") {
outer_command
} else {
return None;
}
} else {
task.resolved_command.fingerprint.command.to_string()
};

let cwd = task.resolved_command.fingerprint.cwd.as_str();
Some(format!(
"{}$ {}",
if cwd.is_empty() { format_args!("") } else { format_args!("~/{}", cwd) },
Comment thread
branchseer marked this conversation as resolved.
display_command
))
}

/// Displayed before the task is executed
impl Display for PreExecutionStatus {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let display_command = format!("$ {}", &self.task.resolved_command.fingerprint.command);
let outer_command =
format!("$ {}", std::env::var("VITE_OUTER_COMMAND").unwrap_or_default());
let display_command: Option<Styled<&String>> = if self.display_options.hide_command {
if outer_command != "$ " {
Some(outer_command.style(Style::new().cyan()))
} else {
None
}
} else {
Some(display_command.style(Style::new().cyan()))
};
let display_command = self.display_command.as_ref().map(|cmd| cmd.style(COMMAND_STYLE));

// Print cache status with improved, shorter messages
match &self.cache_status {
CacheStatus::CacheMiss(CacheMiss::NotFound) => {
// No message for "Cache not found" as requested
tracing::debug!("{}", "Cache not found".style(Style::new().yellow()));
tracing::debug!("{}", "Cache not found".style(CACHE_MISS_STYLE));
if let Some(display_command) = &display_command {
writeln!(f, "{}", display_command)?;
}
Expand Down Expand Up @@ -86,7 +98,7 @@ impl Display for PreExecutionStatus {
format_args!("✗ cache miss: {}, executing", reason),
if display_command.is_some() { ")" } else { "" },
)
.style(Style::new().yellow().dimmed())
.style(CACHE_MISS_STYLE.dimmed())
)?;
}
CacheStatus::CacheHit => {
Expand Down Expand Up @@ -166,7 +178,7 @@ impl Display for ExecutionSummary {
"Statistics:".style(Style::new().bold()),
format!("{} tasks", total).style(Style::new().bright_white()),
format!("• {} cache hits", cache_hits).style(Style::new().green()),
format!("• {} cache misses", cache_misses).style(Style::new().yellow()),
format!("• {} cache misses", cache_misses).style(CACHE_MISS_STYLE),
if failed > 0 {
format!("• {} failed", failed).style(Style::new().red()).to_string()
} else if skipped > 0 {
Expand All @@ -186,7 +198,7 @@ impl Display for ExecutionSummary {
cache_rate.to_string().style(if cache_rate >= 75 {
Style::new().green().bold()
} else if cache_rate >= 50 {
Style::new().yellow()
CACHE_MISS_STYLE
} else {
Style::new().red()
})
Expand All @@ -212,6 +224,10 @@ impl Display for ExecutionSummary {
task_name.style(Style::new().bright_white().bold())
)?;

if let Some(display_command) = &status.pre_execution_status.display_command {
write!(f, ": {}", display_command.style(COMMAND_STYLE))?;
}

// Execution result icon and status
match &status.execution_result {
Ok(exit_status) if *exit_status == 0 => {
Expand Down Expand Up @@ -246,14 +262,14 @@ impl Display for ExecutionSummary {
)?;
}
CacheStatus::CacheMiss(miss) => {
write!(f, " {}", "→ Cache miss: ".style(Style::new().yellow()))?;
write!(f, " {}", "→ Cache miss: ".style(CACHE_MISS_STYLE))?;

match miss {
CacheMiss::NotFound => {
writeln!(
f,
"{}",
"no previous cache entry found".style(Style::new().yellow())
"no previous cache entry found".style(CACHE_MISS_STYLE)
)?;
}
CacheMiss::FingerprintMismatch(mismatch) => {
Expand Down Expand Up @@ -336,13 +352,13 @@ impl Display for ExecutionSummary {
writeln!(
f,
"{}",
"configuration changed".style(Style::new().yellow())
"configuration changed".style(CACHE_MISS_STYLE)
)?;
} else {
writeln!(
f,
"{}",
changes.join("; ").style(Style::new().yellow())
changes.join("; ").style(CACHE_MISS_STYLE)
)?;
}
}
Expand All @@ -353,7 +369,7 @@ impl Display for ExecutionSummary {
f,
"{}",
format!("content of input '{}' changed", path)
.style(Style::new().yellow())
.style(CACHE_MISS_STYLE)
)?;
}
}
Expand Down
6 changes: 3 additions & 3 deletions packages/cli/snap-tests/associate-existing-cache/snap.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Performance: 0% cache hit rate

Task Details:
────────────────────────────────────────────────
[1] script1 ✓
[1] script1: $ echo hello
→ Cache miss: no previous cache entry found
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Expand All @@ -30,7 +30,7 @@ Performance: 100% cache hit rate

Task Details:
────────────────────────────────────────────────
[1] script2 ✓
[1] script2: $ echo hello
→ Cache hit - output replayed
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Expand All @@ -49,6 +49,6 @@ Performance: 0% cache hit rate

Task Details:
────────────────────────────────────────────────
[1] script2 ✓
[1] script2: $ echo world
→ Cache miss: command changed from echo hello to echo world
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
8 changes: 4 additions & 4 deletions packages/cli/snap-tests/cache-clean/snap.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Performance: 0% cache hit rate

Task Details:
────────────────────────────────────────────────
[1] hello ✓
[1] hello: $ echo hello
→ Cache miss: no previous cache entry found
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Expand All @@ -30,7 +30,7 @@ Performance: 100% cache hit rate

Task Details:
────────────────────────────────────────────────
[1] hello ✓
[1] hello: $ echo hello
→ Cache hit - output replayed
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Expand All @@ -49,7 +49,7 @@ Performance: 0% cache hit rate

Task Details:
────────────────────────────────────────────────
[1] hello ✓
[1] hello: $ echo hello
→ Cache miss: no previous cache entry found
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Expand All @@ -68,6 +68,6 @@ Performance: 0% cache hit rate

Task Details:
────────────────────────────────────────────────
[1] hello ✓
[1] hello: $ echo hello
→ Cache miss: no previous cache entry found
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
10 changes: 5 additions & 5 deletions packages/cli/snap-tests/cache-miss-command-change/snap.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ Performance: 0% cache hit rate

Task Details:
────────────────────────────────────────────────
[1] hello(subcommand 0) ✓
[1] hello(subcommand 0): $ echo foo
→ Cache miss: no previous cache entry found
·······················································
[2] hello ✓
[2] hello: $ echo bar
→ Cache miss: no previous cache entry found
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Expand All @@ -40,10 +40,10 @@ Performance: 50% cache hit rate

Task Details:
────────────────────────────────────────────────
[1] hello(subcommand 0) ✓
[1] hello(subcommand 0): $ echo baz
→ Cache miss: command changed from echo foo to echo baz
·······················································
[2] hello ✓
[2] hello: $ echo bar
→ Cache hit - output replayed
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Expand All @@ -62,6 +62,6 @@ Performance: 100% cache hit rate

Task Details:
────────────────────────────────────────────────
[1] hello ✓
[1] hello: $ echo bar
→ Cache hit - output replayed
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Performance: 0% cache hit rate

Task Details:
────────────────────────────────────────────────
[1] hello ✓
[1] hello: $ node -p process.env.MY_ENV
→ Cache miss: no previous cache entry found
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Expand All @@ -30,7 +30,7 @@ Performance: 100% cache hit rate

Task Details:
────────────────────────────────────────────────
[1] hello ✓
[1] hello: $ node -p process.env.MY_ENV
→ Cache hit - output replayed
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Expand All @@ -49,6 +49,6 @@ Performance: 0% cache hit rate

Task Details:
────────────────────────────────────────────────
[1] hello ✓
[1] hello: $ node -p process.env.MY_ENV
→ Cache miss: pass-through env configuration changed from ["MY_ENV"] to ["MY_ENV, MY_ENV2"]
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
4 changes: 2 additions & 2 deletions packages/cli/snap-tests/check-oxlint-env/snap.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Performance: 0% cache hit rate

Task Details:
────────────────────────────────────────────────
[1] check-oxlint-env#check ✓
[1] check-oxlint-env#check: $ node check.js
→ Cache miss: no previous cache entry found
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Expand All @@ -32,6 +32,6 @@ Performance: 0% cache hit rate

Task Details:
────────────────────────────────────────────────
[1] check-oxlint-env#check ✓
[1] check-oxlint-env#check: $ node check.js
→ Cache miss: no previous cache entry found
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
8 changes: 4 additions & 4 deletions packages/cli/snap-tests/exit-code/snap.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Performance: 0% cache hit rate

Task Details:
────────────────────────────────────────────────
[1] script1 ✓
[1] script1: $ echo success
→ Cache miss: no previous cache entry found
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Expand All @@ -30,7 +30,7 @@ Performance: 100% cache hit rate

Task Details:
────────────────────────────────────────────────
[1] script1 ✓
[1] script1: $ echo success
→ Cache hit - output replayed
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Expand All @@ -48,7 +48,7 @@ Performance: 0% cache hit rate

Task Details:
────────────────────────────────────────────────
[1] script2 ✗ (exit code: 1)
[1] script2: $ node failure.js ✗ (exit code: 1)
→ Cache miss: no previous cache entry found
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Expand All @@ -66,6 +66,6 @@ Performance: 0% cache hit rate

Task Details:
────────────────────────────────────────────────
[1] script2 ✗ (exit code: 1)
[1] script2: $ node failure.js ✗ (exit code: 1)
→ Cache miss: no previous cache entry found
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Performance: 0% cache hit rate

Task Details:
────────────────────────────────────────────────
[1] echo ✓
[1] echo: $ echo a
→ Cache miss: no previous cache entry found
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Expand All @@ -30,7 +30,7 @@ Performance: 0% cache hit rate

Task Details:
────────────────────────────────────────────────
[1] echo ✓
[1] echo: $ echo b
→ Cache miss: no previous cache entry found
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Expand All @@ -48,7 +48,7 @@ Performance: 100% cache hit rate

Task Details:
────────────────────────────────────────────────
[1] echo ✓
[1] echo: $ echo a
→ Cache hit - output replayed
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Expand All @@ -66,6 +66,6 @@ Performance: 100% cache hit rate

Task Details:
────────────────────────────────────────────────
[1] echo ✓
[1] echo: $ echo b
→ Cache hit - output replayed
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Loading
Loading