refactor: Improve registry sorting logic for package resolution

This commit is contained in:
2026-05-13 19:43:25 +08:00
parent 9d8dcda366
commit ed85f801e9

View File

@@ -38,7 +38,7 @@ pub fn get_index_path() -> PathBuf {
pub fn resolve_package_from_registry(name: &str) -> Result<JsonValue, String> { pub fn resolve_package_from_registry(name: &str) -> Result<JsonValue, String> {
let config = get_registry_config().ok_or("No registry config found")?; let config = get_registry_config().ok_or("No registry config found")?;
let mut registries: Vec<(&String, &Registry)> = config.registry.iter().collect(); let mut registries: Vec<(&String, &Registry)> = config.registry.iter().collect();
registries.sort_by(|a, b| b.1.priority.cmp(&a.1.priority)); registries.sort_by_key(|b| std::cmp::Reverse(b.1.priority));
for (_name_reg, _reg) in registries { for (_name_reg, _reg) in registries {
let index_path = get_index_path(); let index_path = get_index_path();