使用rust which包来查找命令路径,解决部分电脑环境变量识别问题

This commit is contained in:
xintaofei
2026-03-18 22:59:12 +08:00
parent 0209de17eb
commit e3784fb3f3
5 changed files with 55 additions and 27 deletions

View File

@@ -131,9 +131,13 @@ async fn build_agent(
parts.push(format!("{k}={v}"));
}
parts.push(
crate::process::normalized_program(cmd)
.to_string_lossy()
.to_string(),
which::which(cmd)
.map(|p| p.to_string_lossy().to_string())
.unwrap_or_else(|_| {
crate::process::normalized_program(cmd)
.to_string_lossy()
.to_string()
}),
);
for a in args {
parts.push((*a).into());

View File

@@ -93,14 +93,24 @@ async fn check_npm_environment(node_required: Option<&str>) -> Vec<CheckItem> {
return checks;
}
// Run node and npm checks in parallel
// Resolve absolute paths via `which` crate to avoid GUI PATH issues,
// then run version checks in parallel.
let node_path = which::which("node").ok();
let npm_path = which::which("npm").ok();
let (node_result, npm_result) = tokio::join!(
crate::process::tokio_command("node")
.arg("--version")
.output(),
crate::process::tokio_command("npm")
.arg("--version")
.output(),
async {
match &node_path {
Some(p) => crate::process::tokio_command(p).arg("--version").output().await,
None => Err(std::io::Error::new(std::io::ErrorKind::NotFound, "node not found in PATH")),
}
},
async {
match &npm_path {
Some(p) => crate::process::tokio_command(p).arg("--version").output().await,
None => Err(std::io::Error::new(std::io::ErrorKind::NotFound, "npm not found in PATH")),
}
},
);
// Track the raw node version string for reuse in the version check