summaryrefslogtreecommitdiff
path: root/cli/tools/registry/diagnostics.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/diagnostics.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/diagnostics.rs')
-rw-r--r--cli/tools/registry/diagnostics.rs25
1 files changed, 24 insertions, 1 deletions
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<DiagnosticSnippet<'_>> {
- 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>]> {