summaryrefslogtreecommitdiff
path: root/cli/tools/registry
diff options
context:
space:
mode:
authorDavid Sherret <dsherret@users.noreply.github.com>2024-06-05 11:04:16 -0400
committerGitHub <noreply@github.com>2024-06-05 17:04:16 +0200
commit7ed90a20d04982ae15a52ae2378cbffd4b6839df (patch)
tree3297d6f7227fbf1cf80e17a2a376ef4dfa52e6ad /cli/tools/registry
parent0544d60012006b1c7799d8b6eafacec9567901ad (diff)
fix: better handling of npm resolution occurring on workers (#24094)
Closes https://github.com/denoland/deno/issues/24063
Diffstat (limited to 'cli/tools/registry')
-rw-r--r--cli/tools/registry/diagnostics.rs22
-rw-r--r--cli/tools/registry/graph.rs4
-rw-r--r--cli/tools/registry/tar.rs2
-rw-r--r--cli/tools/registry/unfurl.rs50
4 files changed, 32 insertions, 46 deletions
diff --git a/cli/tools/registry/diagnostics.rs b/cli/tools/registry/diagnostics.rs
index 1c3a3bd58..3f3e1ee96 100644
--- a/cli/tools/registry/diagnostics.rs
+++ b/cli/tools/registry/diagnostics.rs
@@ -40,11 +40,7 @@ impl PublishDiagnosticsCollector {
diagnostics.sort_by_cached_key(|d| d.sorting_key());
for diagnostic in diagnostics {
- // todo(https://github.com/denoland/deno_ast/issues/245): use log crate here
- #[allow(clippy::print_stderr)]
- {
- eprint!("{}", diagnostic.display());
- }
+ log::error!("{}", diagnostic.display());
if matches!(diagnostic.level(), DiagnosticLevel::Error) {
errors += 1;
}
@@ -287,7 +283,7 @@ impl Diagnostic for PublishDiagnostic {
Some(DiagnosticSnippet {
source: Cow::Borrowed(text_info),
- highlight: DiagnosticSnippetHighlight {
+ highlights: vec![DiagnosticSnippetHighlight {
style: DiagnosticSnippetHighlightStyle::Error,
range: DiagnosticSourceRange {
start: DiagnosticSourcePos::LineAndCol {
@@ -300,7 +296,7 @@ impl Diagnostic for PublishDiagnostic {
},
},
description: Some("the specifier".into()),
- },
+ }],
})
}
@@ -314,14 +310,14 @@ impl Diagnostic for PublishDiagnostic {
..
} => Some(DiagnosticSnippet {
source: Cow::Borrowed(text_info),
- highlight: DiagnosticSnippetHighlight {
+ highlights: vec![DiagnosticSnippetHighlight {
style: DiagnosticSnippetHighlightStyle::Warning,
range: DiagnosticSourceRange {
start: DiagnosticSourcePos::SourcePos(range.start),
end: DiagnosticSourcePos::SourcePos(range.end),
},
description: Some("the unanalyzable dynamic import".into()),
- },
+ }],
}),
},
InvalidPath { .. } => None,
@@ -343,14 +339,14 @@ impl Diagnostic for PublishDiagnostic {
range, text_info, ..
} => Some(DiagnosticSnippet {
source: Cow::Borrowed(text_info),
- highlight: DiagnosticSnippetHighlight {
+ highlights: vec![DiagnosticSnippetHighlight {
style: DiagnosticSnippetHighlightStyle::Error,
range: DiagnosticSourceRange {
start: DiagnosticSourcePos::SourcePos(range.start),
end: DiagnosticSourcePos::SourcePos(range.end),
},
description: Some("the triple slash directive".into()),
- },
+ }],
}),
}
}
@@ -398,14 +394,14 @@ impl Diagnostic for PublishDiagnostic {
let end = replacement.line_end(0);
Some(DiagnosticSnippet {
source: Cow::Owned(replacement),
- highlight: DiagnosticSnippetHighlight {
+ highlights: vec![DiagnosticSnippetHighlight {
style: DiagnosticSnippetHighlightStyle::Hint,
range: DiagnosticSourceRange {
start: DiagnosticSourcePos::SourcePos(start),
end: DiagnosticSourcePos::SourcePos(end),
},
description: Some("try this specifier".into()),
- },
+ }],
})
}
None => None,
diff --git a/cli/tools/registry/graph.rs b/cli/tools/registry/graph.rs
index b363efdb4..73b72c1b6 100644
--- a/cli/tools/registry/graph.rs
+++ b/cli/tools/registry/graph.rs
@@ -130,7 +130,7 @@ impl GraphDiagnosticsCollector {
prefer_fast_check_graph: false,
follow_type_only: true,
};
- let mut iter = graph.walk(&graph.roots, options);
+ let mut iter = graph.walk(graph.roots.iter(), options);
while let Some((specifier, entry)) = iter.next() {
if skip_specifiers.contains(specifier) {
iter.skip_previous_dependencies();
@@ -196,7 +196,7 @@ fn check_for_banned_triple_slash_directives(
PublishDiagnostic::BannedTripleSlashDirectives {
specifier: parsed_source.specifier().clone(),
range: comment.range(),
- text_info: parsed_source.text_info().clone(),
+ text_info: parsed_source.text_info_lazy().clone(),
},
);
}
diff --git a/cli/tools/registry/tar.rs b/cli/tools/registry/tar.rs
index 8124a0c9e..f98d4b09c 100644
--- a/cli/tools/registry/tar.rs
+++ b/cli/tools/registry/tar.rs
@@ -126,7 +126,7 @@ fn resolve_content_maybe_unfurling(
let text = String::from_utf8(data)?;
deno_ast::parse_module(deno_ast::ParseParams {
specifier: specifier.clone(),
- text_info: deno_ast::SourceTextInfo::from_string(text),
+ text: text.into(),
media_type,
capture_tokens: false,
maybe_syntax: None,
diff --git a/cli/tools/registry/unfurl.rs b/cli/tools/registry/unfurl.rs
index f45b6ffc3..bc3272835 100644
--- a/cli/tools/registry/unfurl.rs
+++ b/cli/tools/registry/unfurl.rs
@@ -121,16 +121,15 @@ impl<'a> SpecifierUnfurler<'a> {
fn try_unfurl_dynamic_dep(
&self,
module_url: &lsp_types::Url,
- parsed_source: &ParsedSource,
+ text_info: &SourceTextInfo,
dep: &deno_graph::DynamicDependencyDescriptor,
text_changes: &mut Vec<deno_ast::TextChange>,
) -> bool {
match &dep.argument {
deno_graph::DynamicArgument::String(specifier) => {
- let range = to_range(parsed_source, &dep.argument_range);
- let maybe_relative_index = parsed_source.text_info().text_str()
- [range.start..range.end]
- .find(specifier);
+ let range = to_range(text_info, &dep.argument_range);
+ let maybe_relative_index =
+ text_info.text_str()[range.start..range.end].find(specifier);
let Some(relative_index) = maybe_relative_index else {
return true; // always say it's analyzable for a string
};
@@ -159,9 +158,9 @@ impl<'a> SpecifierUnfurler<'a> {
let Some(unfurled) = unfurled else {
return true; // nothing to unfurl
};
- let range = to_range(parsed_source, &dep.argument_range);
+ let range = to_range(text_info, &dep.argument_range);
let maybe_relative_index =
- parsed_source.text_info().text_str()[range.start..].find(specifier);
+ text_info.text_str()[range.start..].find(specifier);
let Some(relative_index) = maybe_relative_index else {
return false;
};
@@ -192,6 +191,7 @@ impl<'a> SpecifierUnfurler<'a> {
diagnostic_reporter: &mut dyn FnMut(SpecifierUnfurlerDiagnostic),
) -> String {
let mut text_changes = Vec::new();
+ let text_info = parsed_source.text_info_lazy();
let module_info = ParserModuleAnalyzer::module_info(parsed_source);
let analyze_specifier =
|specifier: &str,
@@ -199,7 +199,7 @@ impl<'a> SpecifierUnfurler<'a> {
text_changes: &mut Vec<deno_ast::TextChange>| {
if let Some(unfurled) = self.unfurl_specifier(url, specifier) {
text_changes.push(deno_ast::TextChange {
- range: to_range(parsed_source, range),
+ range: to_range(text_info, range),
new_text: unfurled,
});
}
@@ -214,27 +214,19 @@ impl<'a> SpecifierUnfurler<'a> {
);
}
DependencyDescriptor::Dynamic(dep) => {
- let success = self.try_unfurl_dynamic_dep(
- url,
- parsed_source,
- dep,
- &mut text_changes,
- );
+ let success =
+ self.try_unfurl_dynamic_dep(url, text_info, dep, &mut text_changes);
if !success {
- let start_pos = parsed_source
- .text_info()
- .line_start(dep.argument_range.start.line)
+ let start_pos = text_info.line_start(dep.argument_range.start.line)
+ dep.argument_range.start.character;
- let end_pos = parsed_source
- .text_info()
- .line_start(dep.argument_range.end.line)
+ let end_pos = text_info.line_start(dep.argument_range.end.line)
+ dep.argument_range.end.character;
diagnostic_reporter(
SpecifierUnfurlerDiagnostic::UnanalyzableDynamicImport {
specifier: url.to_owned(),
range: SourceRange::new(start_pos, end_pos),
- text_info: parsed_source.text_info().clone(),
+ text_info: text_info.clone(),
},
);
}
@@ -267,10 +259,8 @@ impl<'a> SpecifierUnfurler<'a> {
);
}
- let rewritten_text = deno_ast::apply_text_changes(
- parsed_source.text_info().text_str(),
- text_changes,
- );
+ let rewritten_text =
+ deno_ast::apply_text_changes(text_info.text_str(), text_changes);
rewritten_text
}
}
@@ -295,13 +285,13 @@ fn relative_url(
}
fn to_range(
- parsed_source: &ParsedSource,
+ text_info: &SourceTextInfo,
range: &deno_graph::PositionRange,
) -> std::ops::Range<usize> {
let mut range = range
- .as_source_range(parsed_source.text_info())
- .as_byte_range(parsed_source.text_info().range().start);
- let text = &parsed_source.text_info().text_str()[range.clone()];
+ .as_source_range(text_info)
+ .as_byte_range(text_info.range().start);
+ let text = &text_info.text_str()[range.clone()];
if text.starts_with('"') || text.starts_with('\'') {
range.start += 1;
}
@@ -338,7 +328,7 @@ mod tests {
capture_tokens: false,
maybe_syntax: None,
scope_analysis: false,
- text_info: deno_ast::SourceTextInfo::new(source_code.into()),
+ text: source_code.into(),
})
.unwrap()
}