Skip to content

Commit

Permalink
fix(npm): mise use -g npm:yarn@latest installs wrong version
Browse files Browse the repository at this point in the history
  • Loading branch information
roele committed Mar 6, 2024
1 parent 0d95fde commit 9a30810
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/forge/npm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Vec<String>>,
latest_version_cache: CacheManager<Option<String>>,
}

impl Forge for NPMForge {
Expand All @@ -33,6 +35,20 @@ impl Forge for NPMForge {
.cloned()
}

fn latest_stable_version(&self) -> eyre::Result<Option<String>> {
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();
Expand All @@ -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,
}
}
Expand Down

0 comments on commit 9a30810

Please sign in to comment.