From 11db68ce96dfe561da6d7f4938e412635dc688d7 Mon Sep 17 00:00:00 2001 From: Divy Srivastava Date: Mon, 4 Mar 2024 09:55:28 +0530 Subject: 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 --- cli/tools/registry/diagnostics.rs | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) (limited to 'cli/tools/registry/diagnostics.rs') diff --git a/cli/tools/registry/diagnostics.rs b/cli/tools/registry/diagnostics.rs index ff86e68fb..9e88e81de 100644 --- a/cli/tools/registry/diagnostics.rs +++ b/cli/tools/registry/diagnostics.rs @@ -287,7 +287,30 @@ impl Diagnostic for PublishDiagnostic { } fn snippet_fixed(&self) -> Option> { - None + match &self { + PublishDiagnostic::InvalidExternalImport { imported, .. } => { + match super::api::get_jsr_alternative(imported) { + Some(replacement) => { + let replacement = SourceTextInfo::new(replacement.into()); + let start = replacement.line_start(0); + let end = replacement.line_end(0); + Some(DiagnosticSnippet { + source: Cow::Owned(replacement), + highlight: DiagnosticSnippetHighlight { + style: DiagnosticSnippetHighlightStyle::Hint, + range: DiagnosticSourceRange { + start: DiagnosticSourcePos::SourcePos(start), + end: DiagnosticSourcePos::SourcePos(end), + }, + description: Some("try this specifier".into()), + }, + }) + } + None => None, + } + } + _ => None, + } } fn info(&self) -> Cow<'_, [Cow<'_, str>]> { -- cgit v1.2.3