Skip to content

Commit d1d530c

Browse files
authored
Merge branch 'main' into feat/2219-remove-git-hooks
2 parents bf2ef7c + 9684a9e commit d1d530c

1 file changed

Lines changed: 2 additions & 18 deletions

File tree

  • crates/vp_global_cli/src/commands/env

crates/vp_global_cli/src/commands/env/list.rs

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//!
33
//! Handles `vp env list` to show Node.js versions installed in VP_HOME/js_runtime/node/.
44
5-
use std::{cmp::Ordering, process::ExitStatus};
5+
use std::process::ExitStatus;
66

77
use owo_colors::OwoColorize;
88
use serde::Serialize;
@@ -38,18 +38,10 @@ pub(super) fn list_installed_versions(node_dir: &std::path::Path) -> Vec<String>
3838
})
3939
.collect();
4040

41-
versions.sort_by(|a, b| compare_versions(a, b));
41+
versions.sort_by_cached_key(|v| node_semver::Version::parse(v).ok());
4242
versions
4343
}
4444

45-
/// Compare two version strings numerically (e.g., "20.18.0" vs "22.13.0").
46-
fn compare_versions(a: &str, b: &str) -> Ordering {
47-
let parse = |v: &str| -> Vec<u64> { v.split('.').filter_map(|p| p.parse().ok()).collect() };
48-
let a_parts = parse(a);
49-
let b_parts = parse(b);
50-
a_parts.cmp(&b_parts)
51-
}
52-
5345
/// Execute the list command (local installed versions).
5446
pub async fn execute(cwd: AbsolutePathBuf, json_output: bool) -> Result<ExitStatus, Error> {
5547
let home_dir = vp_shared::get_vp_home()?;
@@ -131,14 +123,6 @@ fn print_human(versions: &[String], current: Option<&str>, default: Option<&str>
131123
mod tests {
132124
use super::*;
133125

134-
#[test]
135-
fn test_version_cmp() {
136-
assert_eq!(compare_versions("18.20.0", "20.18.0"), Ordering::Less);
137-
assert_eq!(compare_versions("22.13.0", "20.18.0"), Ordering::Greater);
138-
assert_eq!(compare_versions("20.18.0", "20.18.0"), Ordering::Equal);
139-
assert_eq!(compare_versions("20.9.0", "20.18.0"), Ordering::Less);
140-
}
141-
142126
#[test]
143127
fn test_list_installed_versions_nonexistent_dir() {
144128
let versions = list_installed_versions(std::path::Path::new("/nonexistent/path"));

0 commit comments

Comments
 (0)