Skip to content

Commit 42c817f

Browse files
committed
fix(js_runtime): show descriptive message in download progress bar
Display what is being downloaded (e.g., "Downloading Node.js v22.13.1...") above the progress bar so users understand what the download is for.
1 parent a5932b9 commit 42c817f

2 files changed

Lines changed: 16 additions & 16 deletions

File tree

crates/vite_js_runtime/src/download.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,14 @@ pub struct CachedFetchResponse {
2929
}
3030

3131
/// Download a file with retry logic and progress bar
32-
pub async fn download_file(url: &str, target_path: &AbsolutePath) -> Result<(), Error> {
32+
///
33+
/// The `message` parameter is displayed to the user to indicate what is being downloaded
34+
/// (e.g., "Downloading Node.js v22.13.1").
35+
pub async fn download_file(
36+
url: &str,
37+
target_path: &AbsolutePath,
38+
message: &str,
39+
) -> Result<(), Error> {
3340
tracing::debug!("Downloading {url} to {target_path:?}");
3441

3542
let response = (|| async { reqwest::get(url).await?.error_for_status() })
@@ -45,13 +52,6 @@ pub async fn download_file(url: &str, target_path: &AbsolutePath) -> Result<(),
4552
// Get Content-Length for progress bar
4653
let total_size = response.content_length();
4754

48-
// Extract filename for display
49-
let filename = target_path
50-
.as_path()
51-
.file_name()
52-
.map(|s| s.to_string_lossy().to_string())
53-
.unwrap_or_else(|| "file".to_string());
54-
5555
// Create progress bar (only in TTY and not in CI)
5656
let is_ci = std::env::var("CI").is_ok();
5757
let progress = if std::io::stderr().is_terminal() && !is_ci {
@@ -61,7 +61,7 @@ pub async fn download_file(url: &str, target_path: &AbsolutePath) -> Result<(),
6161
pb.set_style(
6262
ProgressStyle::default_bar()
6363
.template(
64-
"{spinner:.green} [{elapsed_precise}] [{bar:40.cyan/blue}] \
64+
"{msg}\n{spinner:.green} [{elapsed_precise}] [{bar:40.cyan/blue}] \
6565
{bytes}/{total_bytes} ({bytes_per_sec}, {eta})",
6666
)
6767
.expect("valid progress bar template")
@@ -74,15 +74,15 @@ pub async fn download_file(url: &str, target_path: &AbsolutePath) -> Result<(),
7474
pb.set_style(
7575
ProgressStyle::default_spinner()
7676
.template(
77-
"{spinner:.green} [{elapsed_precise}] {bytes} ({bytes_per_sec}) {msg}",
77+
"{msg}\n{spinner:.green} [{elapsed_precise}] {bytes} ({bytes_per_sec})",
7878
)
7979
.expect("valid spinner template"),
8080
);
8181
pb.enable_steady_tick(Duration::from_millis(100));
8282
pb
8383
}
8484
};
85-
pb.set_message(format!("Downloading {filename}"));
85+
pb.set_message(message.to_string());
8686
Some(pb)
8787
} else {
8888
None
@@ -103,7 +103,7 @@ pub async fn download_file(url: &str, target_path: &AbsolutePath) -> Result<(),
103103
file.flush().await?;
104104

105105
if let Some(pb) = progress {
106-
pb.finish_with_message(format!("Downloaded {filename}"));
106+
pb.finish_and_clear();
107107
}
108108

109109
tracing::debug!("Download completed: {target_path:?}");

crates/vite_js_runtime/src/runtime.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,6 @@ pub async fn download_runtime_with_provider<P: JsRuntimeProvider>(
111111
let cache_dir = crate::cache::get_cache_dir()?;
112112

113113
// Get paths from provider
114-
let platform_str = provider.platform_string(platform);
115114
let binary_relative_path = provider.binary_relative_path(platform);
116115
let bin_dir_relative_path = provider.bin_dir_relative_path(platform);
117116

@@ -139,7 +138,8 @@ pub async fn download_runtime_with_provider<P: JsRuntimeProvider>(
139138
tokio::fs::remove_dir_all(&install_dir).await?;
140139
}
141140

142-
tracing::info!("Downloading {} {version} for {platform_str}...", provider.name());
141+
let download_message = format!("Downloading {} v{version}...", provider.name());
142+
tracing::info!("{download_message}");
143143

144144
// Get download info from provider
145145
let download_info = provider.get_download_info(version, platform);
@@ -159,15 +159,15 @@ pub async fn download_runtime_with_provider<P: JsRuntimeProvider>(
159159
provider.parse_shasums(&shasums_content, &download_info.archive_filename)?;
160160

161161
// Download archive
162-
download_file(&download_info.archive_url, &archive_path).await?;
162+
download_file(&download_info.archive_url, &archive_path, &download_message).await?;
163163

164164
// Verify hash
165165
verify_file_hash(&archive_path, &expected_hash, &download_info.archive_filename)
166166
.await?;
167167
}
168168
HashVerification::None => {
169169
// Download archive without verification
170-
download_file(&download_info.archive_url, &archive_path).await?;
170+
download_file(&download_info.archive_url, &archive_path, &download_message).await?;
171171
}
172172
}
173173

0 commit comments

Comments
 (0)