summaryrefslogtreecommitdiff
path: root/cli/tools/registry/api.rs
diff options
context:
space:
mode:
authorDivy Srivastava <dj.srivastava23@gmail.com>2024-03-04 09:55:28 +0530
committerGitHub <noreply@github.com>2024-03-04 09:55:28 +0530
commit11db68ce96dfe561da6d7f4938e412635dc688d7 (patch)
treebc2d380d238be3af73de8f86218025a850c725b8 /cli/tools/registry/api.rs
parent942b2aaca57880152877a34006b30d2e982dec00 (diff)
feat(publish): add `npm:` suggestion for esm.sh specifiers (#22343)
![image](https://github.com/denoland/deno/assets/34997667/f32642ed-c109-4519-84c5-6f78e9452703) Co-authored-by: David Sherret <dsherret@users.noreply.github.com>
Diffstat (limited to 'cli/tools/registry/api.rs')
-rw-r--r--cli/tools/registry/api.rs14
1 files changed, 14 insertions, 0 deletions
diff --git a/cli/tools/registry/api.rs b/cli/tools/registry/api.rs
index b8eb6c18e..de9b4a333 100644
--- a/cli/tools/registry/api.rs
+++ b/cli/tools/registry/api.rs
@@ -3,6 +3,7 @@
use deno_core::error::AnyError;
use deno_core::serde_json;
use deno_runtime::deno_fetch::reqwest;
+use lsp_types::Url;
use serde::de::DeserializeOwned;
#[derive(serde::Deserialize)]
@@ -142,3 +143,16 @@ pub async fn get_package(
let response = client.get(&package_url).send().await?;
Ok(response)
}
+
+pub fn get_jsr_alternative(imported: &Url) -> Option<String> {
+ if !matches!(imported.host_str(), Some("esm.sh")) {
+ return None;
+ }
+
+ let mut segments = imported.path_segments().unwrap();
+ match segments.next() {
+ Some("gh") => None,
+ Some(module) => Some(format!("\"npm:{module}\"")),
+ None => None,
+ }
+}