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
352 changes: 186 additions & 166 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion crates/vite_package_manager/src/package_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ fn get_package_manager_type_and_version(
&& let Some((name, version_with_hash)) = package_json.package_manager.split_once('@')
{
// Parse version and optional hash (format: version+sha512.hash)
let (version, hash) = if let Some((ver, hash_part)) = version_with_hash.split_once("+")
let (version, hash) = if let Some((ver, hash_part)) = version_with_hash.split_once('+')
{
(ver, Some(hash_part.into()))
} else {
Expand Down
2 changes: 1 addition & 1 deletion crates/vite_package_manager/src/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ pub async fn verify_file_hash(
if actual_hex != expected_hex {
return Err(Error::HashMismatch {
expected: expected_hash.into(),
actual: format!("{}.{}", algorithm, actual_hex).into(),
actual: format!("{algorithm}.{actual_hex}").into(),
});
}

Expand Down
2 changes: 1 addition & 1 deletion crates/vite_task/src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ impl ResolvedTask {
}
}

pub fn is_builtin(&self) -> bool {
pub const fn is_builtin(&self) -> bool {
self.name.package_name.is_none()
}

Expand Down
5 changes: 2 additions & 3 deletions crates/vite_task/src/execute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -320,8 +320,7 @@ pub static CURRENT_EXECUTION_ID: LazyLock<Option<String>> =

pub static EXECUTION_SUMMARY_DIR: LazyLock<PathBuf> = LazyLock::new(|| {
std::env::var("VITE_TASK_EXECUTION_DIR")
.map(PathBuf::from)
.unwrap_or_else(|_| tempfile::tempdir().unwrap().keep())
.map_or_else(|_| tempfile::tempdir().unwrap().keep(), PathBuf::from)
});

pub async fn execute_task(
Expand Down Expand Up @@ -358,7 +357,7 @@ pub async fn execute_task(
if resolved_command.fingerprint.command.has_inner_runner() {
resolved_command.fingerprint.command.to_string()
} else {
"".to_string()
String::new()
},
)
.env("VITE_TASK_EXECUTION_ID", execution_id)
Expand Down
2 changes: 1 addition & 1 deletion crates/vite_task/src/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ impl FileSystem for RealFileSystem {
// Is a directory on Unix - use the optimized nix implementation first
#[cfg(unix)]
{
return RealFileSystem::process_directory_unix(reader.into_inner(), path_read);
return Self::process_directory_unix(reader.into_inner(), path_read);
}
#[cfg(windows)]
{
Expand Down
5 changes: 2 additions & 3 deletions crates/vite_task/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -342,9 +342,8 @@ pub async fn main<
.await?;
let resolved_vite_config: Option<ResolvedUniversalViteConfig> = vite_config
.map(|vite_config| {
serde_json::from_str(&vite_config).map_err(|err| {
serde_json::from_str(&vite_config).inspect_err(|_| {
tracing::error!("Failed to parse vite config: {vite_config}");
err
})
})
.transpose()?;
Expand Down Expand Up @@ -455,7 +454,7 @@ pub async fn main<
}
}

let _ = std::fs::remove_dir_all(&execution_summary_dir);
let _ = std::fs::remove_dir_all(execution_summary_dir);
if matches!(&args.commands, Commands::Run { .. }) {
print!("{}", &summary);
}
Expand Down
4 changes: 2 additions & 2 deletions crates/vite_task/src/schedule.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ pub struct ExecutionStatus {
/// `Err(_)` means the task doesn't have a exit status at all, e.g. skipped due to failed direct or indirect dependency.
///
/// For example, for three tasks declared as: "false && echo foo && echo bar",
/// their execution_result in order would be:
/// their `execution_result` in order would be:
/// - `Ok(ExitStatus(1))`
/// - `Err(SkippedDueToFailedDependency)`
/// - `Err(SkippedDueToFailedDependency)`
Expand Down Expand Up @@ -162,7 +162,7 @@ impl ExecutionPlan {

// The inner runner is expected to display the command and the cache status. The outer runner will skip displaying them.
if !has_inner_runner {
print!("{}", pre_execution_status);
print!("{pre_execution_status}");
}

// Execute or replay the task
Expand Down
54 changes: 24 additions & 30 deletions crates/vite_task/src/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ pub fn get_display_command(display_options: DisplayOptions, task: &ResolvedTask)
let cwd = task.resolved_command.fingerprint.cwd.as_str();
Some(format!(
"{}$ {}",
if cwd.is_empty() { format_args!("") } else { format_args!("~/{}", cwd) },
if cwd.is_empty() { format_args!("") } else { format_args!("~/{cwd}") },
display_command
))
}
Expand All @@ -56,12 +56,12 @@ impl Display for PreExecutionStatus {
// No message for "Cache not found" as requested
tracing::debug!("{}", "Cache not found".style(CACHE_MISS_STYLE));
if let Some(display_command) = &display_command {
writeln!(f, "{}", display_command)?;
writeln!(f, "{display_command}")?;
}
}
CacheStatus::CacheMiss(CacheMiss::FingerprintMismatch(mismatch)) => {
if let Some(display_command) = &display_command {
write!(f, "{} ", display_command)?;
write!(f, "{display_command} ")?;
}

let current = &self.task.resolved_command.fingerprint;
Expand All @@ -71,22 +71,22 @@ impl Display for PreExecutionStatus {
// For now, just say "command changed" for any command fingerprint mismatch
// The detailed analysis will be in the summary
if previous.command != current.command {
format!("command changed")
"command changed".to_string()
} else if previous.cwd != current.cwd {
format!("working directory changed")
"working directory changed".to_string()
} else if previous.envs_without_pass_through
!= current.envs_without_pass_through
|| previous.pass_through_envs != current.pass_through_envs
{
format!("envs changed")
"envs changed".to_string()
} else {
format!("command configuration changed")
"command configuration changed".to_string()
}
}
FingerprintMismatch::PostRunFingerprintMismatch(
PostRunFingerprintMismatch::InputContentChanged { path },
) => {
format!("content of input '{}' changed", path)
format!("content of input '{path}' changed")
}
};
writeln!(
Expand All @@ -104,7 +104,7 @@ impl Display for PreExecutionStatus {
CacheStatus::CacheHit { .. } => {
if !self.display_options.ignore_replay {
if let Some(display_command) = &display_command {
write!(f, "{} ", display_command)?;
write!(f, "{display_command} ")?;
}
writeln!(
f,
Expand Down Expand Up @@ -176,20 +176,20 @@ impl Display for ExecutionSummary {
f,
"{} {} {} {} {}",
"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(CACHE_MISS_STYLE),
format!(" {total} tasks").style(Style::new().bright_white()),
format!("• {cache_hits} cache hits").style(Style::new().green()),
format!("• {cache_misses} cache misses").style(CACHE_MISS_STYLE),
if failed > 0 {
format!("• {} failed", failed).style(Style::new().red()).to_string()
format!("• {failed} failed").style(Style::new().red()).to_string()
} else if skipped > 0 {
format!("• {} skipped", skipped).style(Style::new().bright_black()).to_string()
format!("• {skipped} skipped").style(Style::new().bright_black()).to_string()
} else {
String::new()
}
)?;

let cache_rate =
if total > 0 { (cache_hits as f64 / total as f64 * 100.0) as u32 } else { 0 };
if total > 0 { (f64::from(cache_hits) / total as f64 * 100.0) as u32 } else { 0 };

let total_duration = self
.execution_statuses
Expand All @@ -209,7 +209,7 @@ impl Display for ExecutionSummary {
f,
"{} {} cache hit rate",
"Performance:".style(Style::new().bold()),
format_args!("{}%", cache_rate).style(if cache_rate >= 75 {
format_args!("{cache_rate}%").style(if cache_rate >= 75 {
Style::new().green().bold()
} else if cache_rate >= 50 {
CACHE_MISS_STYLE
Expand Down Expand Up @@ -260,7 +260,7 @@ impl Display for ExecutionSummary {
f,
" {} {}",
"✗".style(Style::new().red().bold()),
format!("(exit code: {})", exit_status).style(Style::new().red())
format!("(exit code: {exit_status})").style(Style::new().red())
)?;
}
Err(ExecutionFailure::SkippedDueToFailedDependency) => {
Expand All @@ -281,7 +281,7 @@ impl Display for ExecutionSummary {
f,
" {} {}",
"→ Cache hit - output replayed".style(Style::new().green()),
format!("- {:.2?} saved", original_duration).style(Style::new().green())
format!("- {original_duration:.2?} saved").style(Style::new().green())
)?;
}
CacheStatus::CacheMiss(miss) => {
Expand Down Expand Up @@ -312,7 +312,7 @@ impl Display for ExecutionSummary {
if previous_command_fingerprint.cwd
!= current_command_fingerprint.cwd
{
fn display_cwd(cwd: &RelativePath) -> &str {
const fn display_cwd(cwd: &RelativePath) -> &str {
if cwd.as_str().is_empty() { "." } else { cwd.as_str() }
}
changes.push(format!(
Expand Down Expand Up @@ -353,22 +353,16 @@ impl Display for ExecutionSummary {
{
if &previous_env_value != current_value {
changes.push(format!(
"env {} value changed from '{}' to '{}'",
key, previous_env_value, current_value,
"env {key} value changed from '{previous_env_value}' to '{current_value}'",
));
}
} else {
changes.push(format!(
"env {}={} added",
key, current_value,
));
changes
.push(format!("env {key}={current_value} added",));
}
}
for (key, previous_value) in previous_envs {
changes.push(format!(
"env {}={} removed",
key, previous_value
));
changes.push(format!("env {key}={previous_value} removed"));
}

if changes.is_empty() {
Expand All @@ -391,7 +385,7 @@ impl Display for ExecutionSummary {
writeln!(
f,
"{}",
format!("content of input '{}' changed", path)
format!("content of input '{path}' changed")
.style(CACHE_MISS_STYLE)
)?;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/binding/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ pub async fn run(options: CliOptions) -> Result<i32> {
_ => {
// Convert Rust errors to NAPI errors for JavaScript
tracing::error!("Rust error: {:?}", e);
return Err(anyhow::Error::from(e).into());
Err(anyhow::Error::from(e).into())
}
}
}
Expand Down
Loading