summaryrefslogtreecommitdiff
path: root/cli/tools/registry
diff options
context:
space:
mode:
authorDavid Sherret <dsherret@users.noreply.github.com>2024-02-08 20:40:26 -0500
committerGitHub <noreply@github.com>2024-02-09 01:40:26 +0000
commite5e2c45998d3a655c4b2d78c0a1fcb61e09c1982 (patch)
tree4a3af21378652245bdd2e58cc615458d5c163c2c /cli/tools/registry
parentb07a156b1d2548c07c7e822ab69d2ef9bfaca630 (diff)
fix: upgrade to deno_ast 0.33 (#22341)
* Uses diagnostics from deno_ast * Real fix for https://github.com/denoland/deno/pull/22310 * Moves `deno lint --json` code here * Upgrades swc Closes #22117 Closes #22109 Closes #21927 Closes #20993
Diffstat (limited to 'cli/tools/registry')
-rw-r--r--cli/tools/registry/diagnostics.rs175
-rw-r--r--cli/tools/registry/graph.rs25
-rw-r--r--cli/tools/registry/mod.rs11
-rw-r--r--cli/tools/registry/tar.rs2
4 files changed, 90 insertions, 123 deletions
diff --git a/cli/tools/registry/diagnostics.rs b/cli/tools/registry/diagnostics.rs
index e7f947303..aeb5d61e2 100644
--- a/cli/tools/registry/diagnostics.rs
+++ b/cli/tools/registry/diagnostics.rs
@@ -1,28 +1,25 @@
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
use std::borrow::Cow;
-use std::fmt::Display;
use std::path::PathBuf;
use std::sync::Arc;
use std::sync::Mutex;
+use deno_ast::diagnostics::Diagnostic;
+use deno_ast::diagnostics::DiagnosticLevel;
+use deno_ast::diagnostics::DiagnosticLocation;
+use deno_ast::diagnostics::DiagnosticSnippet;
+use deno_ast::diagnostics::DiagnosticSnippetHighlight;
+use deno_ast::diagnostics::DiagnosticSnippetHighlightStyle;
+use deno_ast::diagnostics::DiagnosticSourcePos;
+use deno_ast::diagnostics::DiagnosticSourceRange;
use deno_ast::swc::common::util::take::Take;
+use deno_ast::SourceTextInfo;
use deno_core::anyhow::anyhow;
use deno_core::error::AnyError;
use deno_graph::FastCheckDiagnostic;
use lsp_types::Url;
-use crate::cache::LazyGraphSourceParser;
-use crate::diagnostics::Diagnostic;
-use crate::diagnostics::DiagnosticLevel;
-use crate::diagnostics::DiagnosticLocation;
-use crate::diagnostics::DiagnosticSnippet;
-use crate::diagnostics::DiagnosticSnippetHighlight;
-use crate::diagnostics::DiagnosticSnippetHighlightStyle;
-use crate::diagnostics::DiagnosticSnippetSource;
-use crate::diagnostics::DiagnosticSourcePos;
-use crate::diagnostics::DiagnosticSourceRange;
-use crate::diagnostics::SourceTextParsedSourceStore;
use crate::util::import_map::ImportMapUnfurlDiagnostic;
#[derive(Clone, Default)]
@@ -31,16 +28,12 @@ pub struct PublishDiagnosticsCollector {
}
impl PublishDiagnosticsCollector {
- pub fn print_and_error(
- &self,
- sources: LazyGraphSourceParser,
- ) -> Result<(), AnyError> {
+ pub fn print_and_error(&self) -> Result<(), AnyError> {
let mut errors = 0;
let mut has_zap_errors = false;
let diagnostics = self.diagnostics.lock().unwrap().take();
- let sources = SourceTextParsedSourceStore(sources);
for diagnostic in diagnostics {
- eprint!("{}", diagnostic.display(&sources));
+ eprint!("{}", diagnostic.display());
if matches!(diagnostic.level(), DiagnosticLevel::Error) {
errors += 1;
}
@@ -90,6 +83,7 @@ pub enum PublishDiagnostic {
InvalidExternalImport {
kind: String,
imported: Url,
+ text_info: SourceTextInfo,
referrer: deno_graph::Range,
},
}
@@ -110,22 +104,22 @@ impl Diagnostic for PublishDiagnostic {
}
}
- fn code(&self) -> impl Display + '_ {
+ fn code(&self) -> Cow<'_, str> {
use PublishDiagnostic::*;
match &self {
FastCheck(diagnostic) => diagnostic.code(),
- ImportMapUnfurl(diagnostic) => diagnostic.code(),
- InvalidPath { .. } => "invalid-path",
- DuplicatePath { .. } => "case-insensitive-duplicate-path",
- UnsupportedFileType { .. } => "unsupported-file-type",
- InvalidExternalImport { .. } => "invalid-external-import",
+ ImportMapUnfurl(diagnostic) => Cow::Borrowed(diagnostic.code()),
+ InvalidPath { .. } => Cow::Borrowed("invalid-path"),
+ DuplicatePath { .. } => Cow::Borrowed("case-insensitive-duplicate-path"),
+ UnsupportedFileType { .. } => Cow::Borrowed("unsupported-file-type"),
+ InvalidExternalImport { .. } => Cow::Borrowed("invalid-external-import"),
}
}
- fn message(&self) -> impl Display + '_ {
+ fn message(&self) -> Cow<'_, str> {
use PublishDiagnostic::*;
match &self {
- FastCheck(diagnostic) => Cow::Owned(diagnostic.to_string()) ,
+ FastCheck(diagnostic) => diagnostic.message(),
ImportMapUnfurl(diagnostic) => Cow::Borrowed(diagnostic.message()),
InvalidPath { message, .. } => Cow::Borrowed(message.as_str()),
DuplicatePath { .. } => {
@@ -141,21 +135,15 @@ impl Diagnostic for PublishDiagnostic {
fn location(&self) -> DiagnosticLocation {
use PublishDiagnostic::*;
match &self {
- FastCheck(diagnostic) => match diagnostic.range() {
- Some(range) => DiagnosticLocation::ModulePosition {
- specifier: Cow::Borrowed(diagnostic.specifier()),
- source_pos: DiagnosticSourcePos::SourcePos(range.range.start),
- },
- None => DiagnosticLocation::Module {
- specifier: Cow::Borrowed(diagnostic.specifier()),
- },
- },
+ FastCheck(diagnostic) => diagnostic.location(),
ImportMapUnfurl(diagnostic) => match diagnostic {
ImportMapUnfurlDiagnostic::UnanalyzableDynamicImport {
specifier,
+ text_info,
range,
} => DiagnosticLocation::ModulePosition {
specifier: Cow::Borrowed(specifier),
+ text_info: Cow::Borrowed(text_info),
source_pos: DiagnosticSourcePos::SourcePos(range.start),
},
},
@@ -168,41 +156,31 @@ impl Diagnostic for PublishDiagnostic {
UnsupportedFileType { specifier, .. } => DiagnosticLocation::Module {
specifier: Cow::Borrowed(specifier),
},
- InvalidExternalImport { referrer, .. } => {
- DiagnosticLocation::ModulePosition {
- specifier: Cow::Borrowed(&referrer.specifier),
- source_pos: DiagnosticSourcePos::LineAndCol {
- line: referrer.start.line,
- column: referrer.start.character,
- },
- }
- }
+ InvalidExternalImport {
+ referrer,
+ text_info,
+ ..
+ } => DiagnosticLocation::ModulePosition {
+ specifier: Cow::Borrowed(&referrer.specifier),
+ text_info: Cow::Borrowed(text_info),
+ source_pos: DiagnosticSourcePos::LineAndCol {
+ line: referrer.start.line,
+ column: referrer.start.character,
+ },
+ },
}
}
fn snippet(&self) -> Option<DiagnosticSnippet<'_>> {
match &self {
- PublishDiagnostic::FastCheck(diagnostic) => {
- diagnostic.range().map(|range| DiagnosticSnippet {
- source: DiagnosticSnippetSource::Specifier(Cow::Borrowed(
- diagnostic.specifier(),
- )),
- highlight: DiagnosticSnippetHighlight {
- style: DiagnosticSnippetHighlightStyle::Error,
- range: DiagnosticSourceRange {
- start: DiagnosticSourcePos::SourcePos(range.range.start),
- end: DiagnosticSourcePos::SourcePos(range.range.end),
- },
- description: diagnostic.range_description().map(Cow::Borrowed),
- },
- })
- }
+ PublishDiagnostic::FastCheck(diagnostic) => diagnostic.snippet(),
PublishDiagnostic::ImportMapUnfurl(diagnostic) => match diagnostic {
ImportMapUnfurlDiagnostic::UnanalyzableDynamicImport {
- specifier,
+ text_info,
range,
+ ..
} => Some(DiagnosticSnippet {
- source: DiagnosticSnippetSource::Specifier(Cow::Borrowed(specifier)),
+ source: Cow::Borrowed(text_info),
highlight: DiagnosticSnippetHighlight {
style: DiagnosticSnippetHighlightStyle::Warning,
range: DiagnosticSourceRange {
@@ -216,44 +194,44 @@ impl Diagnostic for PublishDiagnostic {
PublishDiagnostic::InvalidPath { .. } => None,
PublishDiagnostic::DuplicatePath { .. } => None,
PublishDiagnostic::UnsupportedFileType { .. } => None,
- PublishDiagnostic::InvalidExternalImport { referrer, .. } => {
- Some(DiagnosticSnippet {
- source: DiagnosticSnippetSource::Specifier(Cow::Borrowed(
- &referrer.specifier,
- )),
- highlight: DiagnosticSnippetHighlight {
- style: DiagnosticSnippetHighlightStyle::Error,
- range: DiagnosticSourceRange {
- start: DiagnosticSourcePos::LineAndCol {
- line: referrer.start.line,
- column: referrer.start.character,
- },
- end: DiagnosticSourcePos::LineAndCol {
- line: referrer.end.line,
- column: referrer.end.character,
- },
+ PublishDiagnostic::InvalidExternalImport {
+ referrer,
+ text_info,
+ ..
+ } => Some(DiagnosticSnippet {
+ source: Cow::Borrowed(text_info),
+ highlight: DiagnosticSnippetHighlight {
+ style: DiagnosticSnippetHighlightStyle::Error,
+ range: DiagnosticSourceRange {
+ start: DiagnosticSourcePos::LineAndCol {
+ line: referrer.start.line,
+ column: referrer.start.character,
+ },
+ end: DiagnosticSourcePos::LineAndCol {
+ line: referrer.end.line,
+ column: referrer.end.character,
},
- description: Some("the specifier".into()),
},
- })
- }
+ description: Some("the specifier".into()),
+ },
+ }),
}
}
- fn hint(&self) -> Option<impl Display + '_> {
+ fn hint(&self) -> Option<Cow<'_, str>> {
match &self {
- PublishDiagnostic::FastCheck(diagnostic) => Some(diagnostic.fix_hint()),
+ PublishDiagnostic::FastCheck(diagnostic) => diagnostic.hint(),
PublishDiagnostic::ImportMapUnfurl(_) => None,
PublishDiagnostic::InvalidPath { .. } => Some(
- "rename or remove the file, or add it to 'publish.exclude' in the config file",
+ Cow::Borrowed("rename or remove the file, or add it to 'publish.exclude' in the config file"),
),
PublishDiagnostic::DuplicatePath { .. } => Some(
- "rename or remove the file",
+ Cow::Borrowed("rename or remove the file"),
),
PublishDiagnostic::UnsupportedFileType { .. } => Some(
- "remove the file, or add it to 'publish.exclude' in the config file",
+ Cow::Borrowed("remove the file, or add it to 'publish.exclude' in the config file"),
),
- PublishDiagnostic::InvalidExternalImport { .. } => Some("replace this import with one from jsr or npm, or vendor the dependency into your package")
+ PublishDiagnostic::InvalidExternalImport { .. } => Some(Cow::Borrowed("replace this import with one from jsr or npm, or vendor the dependency into your package"))
}
}
@@ -264,12 +242,7 @@ impl Diagnostic for PublishDiagnostic {
fn info(&self) -> Cow<'_, [Cow<'_, str>]> {
match &self {
PublishDiagnostic::FastCheck(diagnostic) => {
- let infos = diagnostic
- .additional_info()
- .iter()
- .map(|s| Cow::Borrowed(*s))
- .collect();
- Cow::Owned(infos)
+ diagnostic.info()
}
PublishDiagnostic::ImportMapUnfurl(diagnostic) => match diagnostic {
ImportMapUnfurlDiagnostic::UnanalyzableDynamicImport { .. } => Cow::Borrowed(&[
@@ -296,25 +269,23 @@ impl Diagnostic for PublishDiagnostic {
}
}
- fn docs_url(&self) -> Option<impl Display + '_> {
+ fn docs_url(&self) -> Option<Cow<'_, str>> {
match &self {
- PublishDiagnostic::FastCheck(diagnostic) => {
- Some(format!("https://jsr.io/go/{}", diagnostic.code()))
- }
+ PublishDiagnostic::FastCheck(diagnostic) => diagnostic.docs_url(),
PublishDiagnostic::ImportMapUnfurl(diagnostic) => match diagnostic {
ImportMapUnfurlDiagnostic::UnanalyzableDynamicImport { .. } => None,
},
PublishDiagnostic::InvalidPath { .. } => {
- Some("https://jsr.io/go/invalid-path".to_owned())
- }
- PublishDiagnostic::DuplicatePath { .. } => {
- Some("https://jsr.io/go/case-insensitive-duplicate-path".to_owned())
+ Some(Cow::Borrowed("https://jsr.io/go/invalid-path"))
}
+ PublishDiagnostic::DuplicatePath { .. } => Some(Cow::Borrowed(
+ "https://jsr.io/go/case-insensitive-duplicate-path",
+ )),
PublishDiagnostic::UnsupportedFileType { .. } => {
- Some("https://jsr.io/go/unsupported-file-type".to_owned())
+ Some(Cow::Borrowed("https://jsr.io/go/unsupported-file-type"))
}
PublishDiagnostic::InvalidExternalImport { .. } => {
- Some("https://jsr.io/go/invalid-external-import".to_owned())
+ Some(Cow::Borrowed("https://jsr.io/go/invalid-external-import"))
}
}
}
diff --git a/cli/tools/registry/graph.rs b/cli/tools/registry/graph.rs
index d9fb665c4..3445d55e7 100644
--- a/cli/tools/registry/graph.rs
+++ b/cli/tools/registry/graph.rs
@@ -2,8 +2,10 @@
use std::collections::HashSet;
use std::collections::VecDeque;
+use std::sync::Arc;
use deno_ast::ModuleSpecifier;
+use deno_ast::SourceTextInfo;
use deno_config::ConfigFile;
use deno_config::WorkspaceConfig;
use deno_core::anyhow::bail;
@@ -76,7 +78,9 @@ pub fn collect_invalid_external_imports(
let mut skip_specifiers: HashSet<Url> = HashSet::new();
let mut collect_if_invalid =
- |skip_specifiers: &mut HashSet<Url>, resolution: &ResolutionResolved| {
+ |skip_specifiers: &mut HashSet<Url>,
+ text: &Arc<str>,
+ resolution: &ResolutionResolved| {
if visited.insert(resolution.specifier.clone()) {
match resolution.specifier.scheme() {
"file" | "data" | "node" => {}
@@ -88,6 +92,7 @@ pub fn collect_invalid_external_imports(
diagnostics_collector.push(
PublishDiagnostic::InvalidExternalImport {
kind: format!("non-JSR '{}'", resolution.specifier.scheme()),
+ text_info: SourceTextInfo::new(text.clone()),
imported: resolution.specifier.clone(),
referrer: resolution.range.clone(),
},
@@ -98,6 +103,7 @@ pub fn collect_invalid_external_imports(
diagnostics_collector.push(
PublishDiagnostic::InvalidExternalImport {
kind: format!("'{}'", resolution.specifier.scheme()),
+ text_info: SourceTextInfo::new(text.clone()),
imported: resolution.specifier.clone(),
referrer: resolution.range.clone(),
},
@@ -128,10 +134,10 @@ pub fn collect_invalid_external_imports(
for (_, dep) in &module.dependencies {
if let Some(resolved) = dep.maybe_code.ok() {
- collect_if_invalid(&mut skip_specifiers, resolved);
+ collect_if_invalid(&mut skip_specifiers, &module.source, resolved);
}
if let Some(resolved) = dep.maybe_type.ok() {
- collect_if_invalid(&mut skip_specifiers, resolved);
+ collect_if_invalid(&mut skip_specifiers, &module.source, resolved);
}
}
}
@@ -144,7 +150,7 @@ pub fn collect_fast_check_type_graph_diagnostics(
packages: &[MemberRoots],
diagnostics_collector: &PublishDiagnosticsCollector,
) -> bool {
- let mut seen_diagnostics = HashSet::new();
+ let mut had_diagnostic = false;
let mut seen_modules = HashSet::with_capacity(graph.specifiers_count());
for package in packages {
let mut pending = VecDeque::new();
@@ -161,12 +167,9 @@ pub fn collect_fast_check_type_graph_diagnostics(
let Some(es_module) = module.js() else {
continue;
};
- if let Some(diagnostic) = es_module.fast_check_diagnostic() {
- for diagnostic in diagnostic.flatten_multiple() {
- if !seen_diagnostics.insert(diagnostic.message_with_range_for_test())
- {
- continue;
- }
+ if let Some(diagnostics) = es_module.fast_check_diagnostics() {
+ for diagnostic in diagnostics {
+ had_diagnostic = true;
diagnostics_collector
.push(PublishDiagnostic::FastCheck(diagnostic.clone()));
if matches!(
@@ -197,5 +200,5 @@ pub fn collect_fast_check_type_graph_diagnostics(
}
}
- !seen_diagnostics.is_empty()
+ had_diagnostic
}
diff --git a/cli/tools/registry/mod.rs b/cli/tools/registry/mod.rs
index 5f03fa6fd..cfdec04c5 100644
--- a/cli/tools/registry/mod.rs
+++ b/cli/tools/registry/mod.rs
@@ -643,7 +643,6 @@ async fn publish_package(
struct PreparePackagesData {
publish_order_graph: PublishOrderGraph,
- graph: Arc<deno_graph::ModuleGraph>,
package_by_name: HashMap<String, Rc<PreparedPublishPackage>>,
}
@@ -678,7 +677,7 @@ async fn prepare_packages_for_publishing(
let package = prepare_publish(
&deno_json,
source_cache.clone(),
- graph.clone(),
+ graph,
import_map,
diagnostics_collector,
)
@@ -689,7 +688,6 @@ async fn prepare_packages_for_publishing(
let package_by_name = HashMap::from([(package_name, package)]);
return Ok(PreparePackagesData {
publish_order_graph,
- graph,
package_by_name,
});
};
@@ -743,7 +741,6 @@ async fn prepare_packages_for_publishing(
}
Ok(PreparePackagesData {
publish_order_graph,
- graph,
package_by_name,
})
}
@@ -849,11 +846,7 @@ pub async fn publish(
)
.await?;
- let source_parser = LazyGraphSourceParser::new(
- cli_factory.parsed_source_cache(),
- &prepared_data.graph,
- );
- diagnostics_collector.print_and_error(source_parser)?;
+ diagnostics_collector.print_and_error()?;
if prepared_data.package_by_name.is_empty() {
bail!("No packages to publish");
diff --git a/cli/tools/registry/tar.rs b/cli/tools/registry/tar.rs
index e63a76516..6543fbf2e 100644
--- a/cli/tools/registry/tar.rs
+++ b/cli/tools/registry/tar.rs
@@ -206,7 +206,7 @@ fn resolve_content_maybe_unfurling(
let text = String::from_utf8(data)?;
deno_ast::parse_module(deno_ast::ParseParams {
- specifier: specifier.to_string(),
+ specifier: specifier.clone(),
text_info: deno_ast::SourceTextInfo::from_string(text),
media_type,
capture_tokens: false,