From 7cd0bd7d2f643c523bcb34b56e0d9d9fb223d352 Mon Sep 17 00:00:00 2001 From: The1111mp Date: Thu, 12 Oct 2023 15:39:56 +0800 Subject: [PATCH] fix: Getting npm perfix path is more reliable. Signed-off-by: The1111mp --- src/run/npm.rs | 2 +- src/run/nvmd.rs | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/run/npm.rs b/src/run/npm.rs index 21cebc8..d692672 100644 --- a/src/run/npm.rs +++ b/src/run/npm.rs @@ -248,7 +248,7 @@ fn get_npm_perfix() -> String { let mut perfix = String::from(""); for line in lines { let cur_line = line.unwrap(); - if cur_line.contains(".nvmd") { + if PathBuf::from(&cur_line).is_dir() { perfix = cur_line; } } diff --git a/src/run/nvmd.rs b/src/run/nvmd.rs index fb0d098..9274e10 100644 --- a/src/run/nvmd.rs +++ b/src/run/nvmd.rs @@ -97,8 +97,8 @@ fn command_for_list() -> Result<(), Error> { for item in ls_result.items { match item.get(&DirEntryAttr::Name) { Some(DirEntryValue::String(version)) => { - if is_uninstall_version(version) { - versions.push(version.clone()); + if is_valid_version(version) { + versions.push(version.to_string()); } } _ => {} @@ -128,7 +128,7 @@ fn command_for_use_global(ver: &String) { version.remove(0); } - if !is_uninstall_version(&version) { + if !is_valid_version(&version) { eprintln!("nvm-desktop: v{} has not been installed", &version); return; } @@ -152,7 +152,7 @@ fn command_for_use_project(ver: &String) { version.remove(0); } - if !is_uninstall_version(&version) { + if !is_valid_version(&version) { eprintln!("nvm-desktop: v{} has not been installed", &version); return; } @@ -241,7 +241,7 @@ fn command_for_which(ver: &String) { } } -fn is_uninstall_version(version: &String) -> bool { +fn is_valid_version(version: &String) -> bool { let mut version_path = NVMD_PATH.clone(); version_path.push("versions"); version_path.push(&version);