Skip to content

Commit 7d04484

Browse files
authored
fix: detect cli@v2 alpha (#421)
1 parent 64ac1ee commit 7d04484

2 files changed

Lines changed: 21 additions & 10 deletions

File tree

.changes/deps-tauri-cli-alpha.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
"create-tauri-app": "patch"
3+
"create-tauri-app-js": "patch"
4+
---
5+
6+
Print info to install `tauri-cli@2.0.0-alpha` if it wasn't detected and `--alpha` flag was passed.
7+

packages/cli/src/deps.rs

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use template::Template;
33
use crate::colors::*;
44
use crate::internal::template;
55
use crate::package_manager::PackageManager;
6-
use std::process::Command;
6+
use std::process::{Command, Output};
77

88
fn is_rustc_installed() -> bool {
99
Command::new("rustc")
@@ -34,15 +34,19 @@ fn is_trunk_installed() -> bool {
3434
.map(|o| o.status.success())
3535
.unwrap_or(false)
3636
}
37-
fn is_tauri_cli_installed() -> bool {
37+
fn is_appropriate_tauri_cli_installed(alpha: bool) -> bool {
38+
let check = |o: Output| match o.status.success() {
39+
true if alpha => String::from_utf8_lossy(&o.stderr)
40+
.split_once(' ')
41+
.map(|(_, v)| v.starts_with('2'))
42+
.unwrap_or(false),
43+
s => s,
44+
};
3845
Command::new("cargo")
39-
.arg("tauri")
40-
.arg("-V")
46+
.args(["tauri", "-V"])
4147
.output()
42-
.map(|o| {
43-
let s = String::from_utf8_lossy(&o.stderr);
44-
!s.starts_with("error:")
45-
})
48+
.map(check)
49+
.or_else(|_| Command::new("tauri").arg("-V").output().map(check))
4650
.unwrap_or(false)
4751
}
4852
fn is_wasm32_installed() -> bool {
@@ -172,11 +176,11 @@ pub fn print_missing_deps(pkg_manager: PackageManager, template: Template, alpha
172176
(
173177
"Tauri CLI",
174178
if alpha {
175-
format!("Run `{BLUE}{BOLD}cargo install tauri-cli --version ^2.0.0-alpha{RESET}`")
179+
format!("Run `{BLUE}{BOLD}cargo install tauri-cli --version '^2.0.0-alpha'{RESET}`")
176180
} else {
177181
format!("Run `{BLUE}{BOLD}cargo install tauri-cli{RESET}`")
178182
},
179-
&is_tauri_cli_installed,
183+
&|| is_appropriate_tauri_cli_installed(alpha),
180184
pkg_manager.is_node() || !template.needs_tauri_cli(),
181185
),
182186
(

0 commit comments

Comments
 (0)