Skip to content

Commit

Permalink
fix: try to find cmd with yarn@berry
Browse files Browse the repository at this point in the history
  • Loading branch information
Zhazhazhu committed Mar 14, 2024
1 parent f33f6fd commit 08e7912
Showing 1 changed file with 19 additions and 23 deletions.
42 changes: 19 additions & 23 deletions src/detect/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,30 +105,26 @@ pub fn detect(options: DetectOptions) -> Option<Agent> {
String::from(&packageManager)
};
let parts = parts.split('@').collect::<Vec<&str>>();
if let [name, ver] = parts.as_slice() {
version = Some(ver.to_string());
let ver = ver
.split(".")
.map(String::from)
.collect::<Vec<String>>()
.first()
.map(String::from);
let name = parts[0];
version = Some(parts[1].to_string());
let ver = parts[1]
.split(".")
.map(String::from)
.collect::<Vec<String>>()[0]
.to_string();

if let Some(ver) = &ver {
let ver = ver.parse::<i32>().unwrap();
let ver = ver.parse::<i32>().unwrap();

if name.to_string() == "yarn" && ver > 1 {
agent = Some(Agent::YarnBerry);
version = Some("berry".into())
} else if name.to_string() == "pnpm" && ver < 7 {
agent = Some(Agent::Pnpm6);
} else if AGENT_MAP.contains_key(name) {
agent = AGENT_MAP.get(name).cloned();
//TODO plan use HashMap
} else if !options.programmatic {
println!("[ni] Unknown packageManager: {}", &packageManager);
}
}
if name.to_string() == "yarn" && ver > 1 {
agent = Some(Agent::YarnBerry);
version = Some("berry".into())
} else if name.to_string() == "pnpm" && ver < 7 {
agent = Some(Agent::Pnpm6);
} else if AGENT_MAP.contains_key(name) {
agent = AGENT_MAP.get(name).cloned();
//TODO plan use HashMap
} else if !options.programmatic {
println!("[ni] Unknown packageManager: {}", &packageManager);
}
}
}
Expand All @@ -147,7 +143,7 @@ pub fn detect(options: DetectOptions) -> Option<Agent> {
}

if let Some(agent) = &agent {
let cmd = which_cmd(&agent.as_str());
let cmd = which_cmd(&agent.as_str().split("@").collect::<Vec<&str>>()[0]);
if cmd == false && options.programmatic == false {
if options.auto_install == false {
println!(
Expand Down

0 comments on commit 08e7912

Please sign in to comment.