From d347e73f5aacf47f4ac75faccd06019ad29c6c78 Mon Sep 17 00:00:00 2001 From: Nayeem Rahman Date: Thu, 28 Mar 2024 19:02:07 +0000 Subject: [PATCH] fix(jsr): exclude yanked versions from 'deno add' and completions (#23113) --- cli/jsr.rs | 14 +++++++++----- cli/npm/mod.rs | 2 +- .../testdata/jsr/registry/@denotest/add/meta.json | 3 +++ 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/cli/jsr.rs b/cli/jsr.rs index 1f030ce70b..1e194da71c 100644 --- a/cli/jsr.rs +++ b/cli/jsr.rs @@ -207,14 +207,18 @@ impl JsrFetchResolver { let maybe_get_nv = || async { let name = req.name.clone(); let package_info = self.package_info(&name).await?; - // Find the first matching version of the package which is cached. - let mut versions = package_info.versions.keys().collect::>(); - versions.sort(); + // Find the first matching version of the package. + let mut versions = package_info.versions.iter().collect::>(); + versions.sort_by_key(|(v, _)| *v); let version = versions .into_iter() .rev() - .find(|v| req.version_req.tag().is_none() && req.version_req.matches(v)) - .cloned()?; + .find(|(v, i)| { + !i.yanked + && req.version_req.tag().is_none() + && req.version_req.matches(v) + }) + .map(|(v, _)| v.clone())?; Some(PackageNv { name, version }) }; let nv = maybe_get_nv().await; diff --git a/cli/npm/mod.rs b/cli/npm/mod.rs index 08c15941ab..c17918c671 100644 --- a/cli/npm/mod.rs +++ b/cli/npm/mod.rs @@ -119,7 +119,7 @@ impl NpmFetchResolver { let maybe_get_nv = || async { let name = req.name.clone(); let package_info = self.package_info(&name).await?; - // Find the first matching version of the package which is cached. + // Find the first matching version of the package. let mut versions = package_info.versions.keys().collect::>(); versions.sort(); let version = versions diff --git a/tests/testdata/jsr/registry/@denotest/add/meta.json b/tests/testdata/jsr/registry/@denotest/add/meta.json index 2f4daa8441..72aea80cc3 100644 --- a/tests/testdata/jsr/registry/@denotest/add/meta.json +++ b/tests/testdata/jsr/registry/@denotest/add/meta.json @@ -1,5 +1,8 @@ { "versions": { + "2.0.0": { + "yanked": true + }, "1.0.0": {}, "0.2.0": {} }