Skip to content

Commit

Permalink
fix(publish): raise diagnostics for triple-slash directives for `--dr…
Browse files Browse the repository at this point in the history
…y-run` instead of just `publish` (denoland#23811)
  • Loading branch information
dsherret committed May 28, 2024
1 parent 328bd8a commit c4211e2
Show file tree
Hide file tree
Showing 7 changed files with 681 additions and 512 deletions.
43 changes: 43 additions & 0 deletions cli/tools/registry/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use deno_ast::diagnostics::DiagnosticSourcePos;
use deno_ast::diagnostics::DiagnosticSourceRange;
use deno_ast::swc::common::util::take::Take;
use deno_ast::SourcePos;
use deno_ast::SourceRange;
use deno_ast::SourceRanged;
use deno_ast::SourceTextInfo;
use deno_core::anyhow::anyhow;
Expand Down Expand Up @@ -115,6 +116,11 @@ pub enum PublishDiagnostic {
text_info: SourceTextInfo,
referrer: deno_graph::Range,
},
BannedTripleSlashDirectives {
specifier: Url,
text_info: SourceTextInfo,
range: SourceRange,
},
}

impl PublishDiagnostic {
Expand Down Expand Up @@ -162,6 +168,7 @@ impl Diagnostic for PublishDiagnostic {
UnsupportedJsxTsx { .. } => DiagnosticLevel::Warning,
ExcludedModule { .. } => DiagnosticLevel::Error,
MissingConstraint { .. } => DiagnosticLevel::Error,
BannedTripleSlashDirectives { .. } => DiagnosticLevel::Error,
}
}

Expand All @@ -177,6 +184,9 @@ impl Diagnostic for PublishDiagnostic {
UnsupportedJsxTsx { .. } => Cow::Borrowed("unsupported-jsx-tsx"),
ExcludedModule { .. } => Cow::Borrowed("excluded-module"),
MissingConstraint { .. } => Cow::Borrowed("missing-constraint"),
BannedTripleSlashDirectives { .. } => {
Cow::Borrowed("banned-triple-slash-directives")
}
}
}

Expand All @@ -196,6 +206,7 @@ impl Diagnostic for PublishDiagnostic {
UnsupportedJsxTsx { .. } => Cow::Borrowed("JSX and TSX files are currently not supported"),
ExcludedModule { .. } => Cow::Borrowed("module in package's module graph was excluded from publishing"),
MissingConstraint { specifier, .. } => Cow::Owned(format!("specifier '{}' is missing a version constraint", specifier)),
BannedTripleSlashDirectives { .. } => Cow::Borrowed("triple slash directives that modify globals are not allowed"),
}
}

Expand Down Expand Up @@ -253,6 +264,15 @@ impl Diagnostic for PublishDiagnostic {
text_info,
..
} => from_referrer_range(referrer, text_info),
BannedTripleSlashDirectives {
specifier,
range,
text_info,
} => DiagnosticLocation::ModulePosition {
specifier: Cow::Borrowed(specifier),
source_pos: DiagnosticSourcePos::SourcePos(range.start),
text_info: Cow::Borrowed(text_info),
},
}
}

Expand Down Expand Up @@ -319,6 +339,19 @@ impl Diagnostic for PublishDiagnostic {
text_info,
..
} => from_range(text_info, referrer),
BannedTripleSlashDirectives {
range, text_info, ..
} => Some(DiagnosticSnippet {
source: Cow::Borrowed(text_info),
highlight: DiagnosticSnippetHighlight {
style: DiagnosticSnippetHighlightStyle::Error,
range: DiagnosticSourceRange {
start: DiagnosticSourcePos::SourcePos(range.start),
end: DiagnosticSourcePos::SourcePos(range.end),
},
description: Some("the triple slash directive".into()),
},
}),
}
}

Expand Down Expand Up @@ -348,6 +381,9 @@ impl Diagnostic for PublishDiagnostic {
"specify a version constraint for the specifier in the import map"
}))
},
BannedTripleSlashDirectives { .. } => Some(
Cow::Borrowed("remove the triple slash directive"),
),
}
}

Expand Down Expand Up @@ -420,6 +456,10 @@ impl Diagnostic for PublishDiagnostic {
),
Cow::Borrowed("major version if one is published in the future and potentially break"),
]),
BannedTripleSlashDirectives { .. } => Cow::Borrowed(&[
Cow::Borrowed("instead instruct the user of your package to specify these directives"),
Cow::Borrowed("or set their 'lib' compiler option appropriately"),
]),
}
}

Expand Down Expand Up @@ -449,6 +489,9 @@ impl Diagnostic for PublishDiagnostic {
MissingConstraint { .. } => {
Some(Cow::Borrowed("https://jsr.io/go/missing-constraint"))
}
BannedTripleSlashDirectives { .. } => Some(Cow::Borrowed(
"https://jsr.io/go/banned-triple-slash-directives",
)),
}
}
}
Loading

0 comments on commit c4211e2

Please sign in to comment.