mirror of
https://github.com/tauri-apps/tauri.git
synced 2026-04-01 10:01:07 +02:00
fix(cli): tauri info can't find the latest version for rust crates (#13096)
* fix(cli): `tauri info` can't find the latest version for rust crates * Forget to remove dbg! * Use strip_suffix * Add change file
This commit is contained in:
5
.changes/fix-tauri-info-crate-latest-version.md
Normal file
5
.changes/fix-tauri-info-crate-latest-version.md
Normal file
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"tauri-cli": patch:bug
|
||||
---
|
||||
|
||||
Fix `tauri info` can't find the latest version for rust crates
|
||||
5
.changes/fix-tauri-info-request-log-level.md
Normal file
5
.changes/fix-tauri-info-request-log-level.md
Normal file
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"tauri-cli": patch:bug
|
||||
---
|
||||
|
||||
Fix `tauri info` logging network operations in `info` level instead of `debug`
|
||||
12
Cargo.lock
generated
12
Cargo.lock
generated
@@ -1355,7 +1355,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "117725a109d387c937a1533ce01b450cbde6b88abceea8473c4d7a85853cda3c"
|
||||
dependencies = [
|
||||
"lazy_static",
|
||||
"windows-sys 0.59.0",
|
||||
"windows-sys 0.48.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -4305,7 +4305,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "fc2f4eb4bc735547cfed7c0a4922cbd04a4655978c09b54f1f7b228750664c34"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"windows-targets 0.52.6",
|
||||
"windows-targets 0.48.5",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -5792,7 +5792,7 @@ dependencies = [
|
||||
"aes-gcm",
|
||||
"aes-kw",
|
||||
"argon2",
|
||||
"base64 0.22.1",
|
||||
"base64 0.21.7",
|
||||
"bitfield",
|
||||
"block-padding",
|
||||
"blowfish",
|
||||
@@ -9654,9 +9654,9 @@ checksum = "8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1"
|
||||
|
||||
[[package]]
|
||||
name = "ureq"
|
||||
version = "3.0.2"
|
||||
version = "3.0.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "aa6a209bb4b8d5903579fc4f8cd12ce5594f1ed6b735bf290ab5e2bdb3e70013"
|
||||
checksum = "217751151c53226090391713e533d9a5e904ba2570dabaaace29032687589c3e"
|
||||
dependencies = [
|
||||
"base64 0.22.1",
|
||||
"cc",
|
||||
@@ -10177,7 +10177,7 @@ version = "0.1.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cf221c93e13a30d793f7645a0e7762c55d169dbb0a49671918a2319d289b10bb"
|
||||
dependencies = [
|
||||
"windows-sys 0.59.0",
|
||||
"windows-sys 0.48.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
||||
@@ -97,15 +97,30 @@ impl std::fmt::Display for CrateVersion {
|
||||
}
|
||||
}
|
||||
|
||||
// Reference: https://github.com/rust-lang/crates.io/blob/98c83c8231cbcd15d6b8f06d80a00ad462f71585/src/views.rs#L274
|
||||
#[derive(serde::Deserialize)]
|
||||
struct CrateMetadata {
|
||||
/// The "default" version of this crate.
|
||||
///
|
||||
/// This version will be displayed by default on the crate's page.
|
||||
pub default_version: Option<String>,
|
||||
}
|
||||
|
||||
// Reference: https://github.com/rust-lang/crates.io/blob/98c83c8231cbcd15d6b8f06d80a00ad462f71585/src/controllers/krate/metadata.rs#L44
|
||||
#[derive(serde::Deserialize)]
|
||||
struct CrateIoGetResponse {
|
||||
/// The crate metadata.
|
||||
#[serde(rename = "crate")]
|
||||
krate: CrateMetadata,
|
||||
}
|
||||
|
||||
pub fn crate_latest_version(name: &str) -> Option<String> {
|
||||
let url = format!("https://docs.rs/crate/{name}/");
|
||||
let response = ureq::get(&url).call().ok()?;
|
||||
if response.status().is_redirection() {
|
||||
if let Some(location) = response.headers().get("location") {
|
||||
return location.to_str().ok().map(|s| s.replace(&url, ""));
|
||||
}
|
||||
}
|
||||
None
|
||||
// Reference: https://github.com/rust-lang/crates.io/blob/98c83c8231cbcd15d6b8f06d80a00ad462f71585/src/controllers/krate/metadata.rs#L88
|
||||
let url = format!("https://crates.io/api/v1/crates/{name}?include");
|
||||
let mut response = ureq::get(&url).call().ok()?;
|
||||
let metadata: CrateIoGetResponse =
|
||||
serde_json::from_reader(response.body_mut().as_reader()).unwrap();
|
||||
metadata.krate.default_version
|
||||
}
|
||||
|
||||
pub fn crate_version(
|
||||
|
||||
@@ -47,18 +47,20 @@ pub fn items(frontend_dir: Option<&PathBuf>, tauri_dir: Option<&Path>) -> Vec<Se
|
||||
if o.status.success() {
|
||||
let out = String::from_utf8_lossy(o.stdout.as_slice());
|
||||
let (package, version) = out.split_once(' ').unwrap_or_default();
|
||||
let latest_ver = crate_latest_version(package).unwrap_or_default();
|
||||
let version = version.strip_suffix('\n').unwrap_or(version);
|
||||
let latest_version = crate_latest_version(package).unwrap_or_default();
|
||||
format!(
|
||||
"{} {}: {}{}",
|
||||
package,
|
||||
"🦀",
|
||||
version.split_once('\n').unwrap_or_default().0,
|
||||
if !(version.is_empty() || latest_ver.is_empty()) {
|
||||
let version = semver::Version::parse(version).unwrap();
|
||||
let target_version = semver::Version::parse(latest_ver.as_str()).unwrap();
|
||||
"{package} 🦀: {version}{}",
|
||||
if !(version.is_empty() || latest_version.is_empty()) {
|
||||
let current_version = semver::Version::parse(version).unwrap();
|
||||
let target_version = semver::Version::parse(latest_version.as_str()).unwrap();
|
||||
|
||||
if version < target_version {
|
||||
format!(" ({}, latest: {})", "outdated".yellow(), latest_ver.green())
|
||||
if current_version < target_version {
|
||||
format!(
|
||||
" ({}, latest: {})",
|
||||
"outdated".yellow(),
|
||||
latest_version.green()
|
||||
)
|
||||
} else {
|
||||
"".into()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user