summaryrefslogtreecommitdiff
path: root/cli/tools
diff options
context:
space:
mode:
Diffstat (limited to 'cli/tools')
-rw-r--r--cli/tools/check.rs4
-rw-r--r--cli/tools/info.rs43
-rw-r--r--cli/tools/lint.rs5
-rw-r--r--cli/tools/test.rs28
-rw-r--r--cli/tools/vendor/mappings.rs2
5 files changed, 40 insertions, 42 deletions
diff --git a/cli/tools/check.rs b/cli/tools/check.rs
index 77bc0f441..ec1f91a1d 100644
--- a/cli/tools/check.rs
+++ b/cli/tools/check.rs
@@ -264,8 +264,7 @@ fn get_tsc_roots(
}
}
- // todo(https://github.com/denoland/deno_graph/pull/253/): pre-allocate this
- let mut result = Vec::new();
+ let mut result = Vec::with_capacity(graph.specifiers_count());
if graph.has_node_specifier {
// inject a specifier that will resolve node types
result.push((
@@ -313,6 +312,7 @@ fn get_tsc_roots(
maybe_get_check_entry(module, check_js)
}
}));
+
result
}
diff --git a/cli/tools/info.rs b/cli/tools/info.rs
index 1cc60286d..5d4bc7bad 100644
--- a/cli/tools/info.rs
+++ b/cli/tools/info.rs
@@ -15,6 +15,7 @@ use deno_graph::npm::NpmPackageNvReference;
use deno_graph::npm::NpmPackageReqReference;
use deno_graph::Dependency;
use deno_graph::Module;
+use deno_graph::ModuleError;
use deno_graph::ModuleGraph;
use deno_graph::ModuleGraphError;
use deno_graph::Resolution;
@@ -477,7 +478,8 @@ impl<'a> GraphDisplayContext<'a> {
Ok(())
}
Err(err) => {
- if let ModuleGraphError::Missing(_, _) = *err {
+ if let ModuleGraphError::ModuleError(ModuleError::Missing(_, _)) = *err
+ {
writeln!(
writer,
"{} module could not be found",
@@ -621,28 +623,29 @@ impl<'a> GraphDisplayContext<'a> {
) -> TreeNode {
self.seen.insert(specifier.to_string());
match err {
- ModuleGraphError::InvalidTypeAssertion { .. } => {
- self.build_error_msg(specifier, "(invalid import assertion)")
- }
- ModuleGraphError::LoadingErr(_, _, _) => {
- self.build_error_msg(specifier, "(loading error)")
- }
- ModuleGraphError::ParseErr(_, _) => {
- self.build_error_msg(specifier, "(parsing error)")
- }
+ ModuleGraphError::ModuleError(err) => match err {
+ ModuleError::InvalidTypeAssertion { .. } => {
+ self.build_error_msg(specifier, "(invalid import assertion)")
+ }
+ ModuleError::LoadingErr(_, _, _) => {
+ self.build_error_msg(specifier, "(loading error)")
+ }
+ ModuleError::ParseErr(_, _) => {
+ self.build_error_msg(specifier, "(parsing error)")
+ }
+ ModuleError::UnsupportedImportAssertionType { .. } => {
+ self.build_error_msg(specifier, "(unsupported import assertion)")
+ }
+ ModuleError::UnsupportedMediaType { .. } => {
+ self.build_error_msg(specifier, "(unsupported)")
+ }
+ ModuleError::Missing(_, _) | ModuleError::MissingDynamic(_, _) => {
+ self.build_error_msg(specifier, "(missing)")
+ }
+ },
ModuleGraphError::ResolutionError(_) => {
self.build_error_msg(specifier, "(resolution error)")
}
- ModuleGraphError::UnsupportedImportAssertionType { .. } => {
- self.build_error_msg(specifier, "(unsupported import assertion)")
- }
- ModuleGraphError::UnsupportedMediaType { .. } => {
- self.build_error_msg(specifier, "(unsupported)")
- }
- ModuleGraphError::Missing(_, _)
- | ModuleGraphError::MissingDynamic(_, _) => {
- self.build_error_msg(specifier, "(missing)")
- }
}
}
diff --git a/cli/tools/lint.rs b/cli/tools/lint.rs
index 4eebf9e16..821257570 100644
--- a/cli/tools/lint.rs
+++ b/cli/tools/lint.rs
@@ -35,6 +35,7 @@ use serde::Serialize;
use std::fs;
use std::io::stdin;
use std::io::Read;
+use std::path::Path;
use std::path::PathBuf;
use std::sync::atomic::AtomicBool;
use std::sync::atomic::Ordering;
@@ -245,12 +246,12 @@ pub fn create_linter(
}
fn lint_file(
- file_path: &PathBuf,
+ file_path: &Path,
source_code: String,
lint_rules: Vec<&'static dyn LintRule>,
) -> Result<(Vec<LintDiagnostic>, String), AnyError> {
let file_name = file_path.to_string_lossy().to_string();
- let media_type = MediaType::from(file_path);
+ let media_type = MediaType::from_path(file_path);
let linter = create_linter(media_type, lint_rules);
diff --git a/cli/tools/test.rs b/cli/tools/test.rs
index 0d9637c3d..20788dbd9 100644
--- a/cli/tools/test.rs
+++ b/cli/tools/test.rs
@@ -16,6 +16,7 @@ use crate::util::file_watcher::ResolutionResult;
use crate::util::fs::collect_specifiers;
use crate::util::path::get_extension;
use crate::util::path::is_supported_ext;
+use crate::util::path::mapped_specifier_for_tsc;
use crate::worker::create_main_worker_for_test_or_bench;
use deno_ast::swc::common::comments::CommentKind;
@@ -740,7 +741,6 @@ async fn test_specifier(
}
fn extract_files_from_regex_blocks(
- current_dir: &Path,
specifier: &ModuleSpecifier,
source: &str,
media_type: MediaType,
@@ -800,17 +800,17 @@ fn extract_files_from_regex_blocks(
writeln!(file_source, "{}", text.as_str()).unwrap();
}
- let file_specifier = deno_core::resolve_url_or_path(
- &format!(
- "{}${}-{}{}",
- specifier,
- file_line_index + line_offset + 1,
- file_line_index + line_offset + line_count + 1,
- file_media_type.as_ts_extension(),
- ),
- current_dir,
- )
+ let file_specifier = ModuleSpecifier::parse(&format!(
+ "{}${}-{}",
+ specifier,
+ file_line_index + line_offset + 1,
+ file_line_index + line_offset + line_count + 1,
+ ))
.unwrap();
+ let file_specifier =
+ mapped_specifier_for_tsc(&file_specifier, file_media_type)
+ .map(|s| ModuleSpecifier::parse(&s).unwrap())
+ .unwrap_or(file_specifier);
Some(File {
local: file_specifier.to_file_path().unwrap(),
@@ -827,7 +827,6 @@ fn extract_files_from_regex_blocks(
}
fn extract_files_from_source_comments(
- current_dir: &Path,
specifier: &ModuleSpecifier,
source: Arc<str>,
media_type: MediaType,
@@ -855,7 +854,6 @@ fn extract_files_from_source_comments(
})
.flat_map(|comment| {
extract_files_from_regex_blocks(
- current_dir,
specifier,
&comment.text,
media_type,
@@ -871,7 +869,6 @@ fn extract_files_from_source_comments(
}
fn extract_files_from_fenced_blocks(
- current_dir: &Path,
specifier: &ModuleSpecifier,
source: &str,
media_type: MediaType,
@@ -885,7 +882,6 @@ fn extract_files_from_fenced_blocks(
let lines_regex = Regex::new(r"(?:\# ?)?(.*)")?;
extract_files_from_regex_blocks(
- current_dir,
specifier,
source,
media_type,
@@ -906,14 +902,12 @@ async fn fetch_inline_files(
let inline_files = if file.media_type == MediaType::Unknown {
extract_files_from_fenced_blocks(
- ps.options.initial_cwd(),
&file.specifier,
&file.source,
file.media_type,
)
} else {
extract_files_from_source_comments(
- ps.options.initial_cwd(),
&file.specifier,
file.source,
file.media_type,
diff --git a/cli/tools/vendor/mappings.rs b/cli/tools/vendor/mappings.rs
index 1ecc14edf..3addd861d 100644
--- a/cli/tools/vendor/mappings.rs
+++ b/cli/tools/vendor/mappings.rs
@@ -200,7 +200,7 @@ fn path_with_extension(path: &Path, new_ext: &str) -> PathBuf {
// maintain casing
return path.to_path_buf();
}
- let media_type: MediaType = path.into();
+ let media_type = MediaType::from_path(path);
if media_type == MediaType::Unknown {
return path.with_file_name(format!(
"{}.{}",