Skip to content

fix(publish): raise diagnostics for triple-slash directives for --dry-run instead of just publish #23811

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
May 28, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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