From 9a30810a67e10101b9b997c58c88ae715e179543 Mon Sep 17 00:00:00 2001 From: Roland Schaer Date: Wed, 6 Mar 2024 16:00:16 -0300 Subject: [PATCH] fix(npm): mise use -g npm:yarn@latest installs wrong version --- src/forge/npm.rs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/forge/npm.rs b/src/forge/npm.rs index 033e66a4ac..39be0138ef 100644 --- a/src/forge/npm.rs +++ b/src/forge/npm.rs @@ -7,11 +7,13 @@ use crate::config::{Config, Settings}; use crate::forge::{Forge, ForgeType}; use crate::install_context::InstallContext; +use serde_json::Value; #[derive(Debug)] pub struct NPMForge { fa: ForgeArg, remote_version_cache: CacheManager>, + latest_version_cache: CacheManager>, } impl Forge for NPMForge { @@ -33,6 +35,20 @@ impl Forge for NPMForge { .cloned() } + fn latest_stable_version(&self) -> eyre::Result> { + self.latest_version_cache + .get_or_try_init(|| { + let raw = cmd!("npm", "view", self.name(), "dist-tags", "--json").read()?; + let dist_tags: Value = serde_json::from_str(&raw)?; + let latest = match dist_tags["latest"] { + Value::String(ref s) => Some(s.clone()), + _ => self.latest_version(Some("latest".into())).unwrap(), + }; + Ok(latest) + }) + .cloned() + } + fn install_version_impl(&self, ctx: &InstallContext) -> eyre::Result<()> { let config = Config::try_get()?; let settings = Settings::get(); @@ -59,6 +75,7 @@ impl NPMForge { remote_version_cache: CacheManager::new( fa.cache_path.join("remote_versions.msgpack.z"), ), + latest_version_cache: CacheManager::new(fa.cache_path.join("latest_version.msgpack.z")), fa, } }