summaryrefslogtreecommitdiff
path: root/cli/tools
diff options
context:
space:
mode:
Diffstat (limited to 'cli/tools')
-rw-r--r--cli/tools/bench.rs22
-rw-r--r--cli/tools/coverage/mod.rs4
-rw-r--r--cli/tools/fmt.rs14
-rw-r--r--cli/tools/info.rs2
-rw-r--r--cli/tools/installer.rs13
-rw-r--r--cli/tools/lint.rs10
-rw-r--r--cli/tools/standalone.rs4
-rw-r--r--cli/tools/task.rs4
-rw-r--r--cli/tools/test.rs117
-rw-r--r--cli/tools/vendor/mappings.rs4
-rw-r--r--cli/tools/vendor/mod.rs20
-rw-r--r--cli/tools/vendor/specifiers.rs15
12 files changed, 170 insertions, 59 deletions
diff --git a/cli/tools/bench.rs b/cli/tools/bench.rs
index a81c0a406..eeda3ea1a 100644
--- a/cli/tools/bench.rs
+++ b/cli/tools/bench.rs
@@ -4,16 +4,16 @@ use crate::args::BenchFlags;
use crate::args::Flags;
use crate::args::TypeCheckMode;
use crate::colors;
-use crate::file_watcher;
-use crate::file_watcher::ResolutionResult;
-use crate::fs_util::collect_specifiers;
-use crate::fs_util::is_supported_bench_path;
use crate::graph_util::contains_specifier;
use crate::graph_util::graph_valid;
use crate::ops;
use crate::proc_state::ProcState;
use crate::tools::test::format_test_error;
use crate::tools::test::TestFilter;
+use crate::util::file_watcher;
+use crate::util::file_watcher::ResolutionResult;
+use crate::util::fs::collect_specifiers;
+use crate::util::path::is_supported_ext;
use crate::worker::create_main_worker_for_test_or_bench;
use deno_core::error::generic_error;
@@ -32,6 +32,7 @@ use log::Level;
use serde::Deserialize;
use serde::Serialize;
use std::collections::HashSet;
+use std::path::Path;
use std::path::PathBuf;
use tokio::sync::mpsc::unbounded_channel;
use tokio::sync::mpsc::UnboundedSender;
@@ -469,6 +470,19 @@ async fn bench_specifiers(
Ok(())
}
+/// Checks if the path has a basename and extension Deno supports for benches.
+fn is_supported_bench_path(path: &Path) -> bool {
+ if let Some(name) = path.file_stem() {
+ let basename = name.to_string_lossy();
+ (basename.ends_with("_bench")
+ || basename.ends_with(".bench")
+ || basename == "bench")
+ && is_supported_ext(path)
+ } else {
+ false
+ }
+}
+
pub async fn run_benchmarks(
flags: Flags,
bench_flags: BenchFlags,
diff --git a/cli/tools/coverage/mod.rs b/cli/tools/coverage/mod.rs
index b76792b1e..b9bbe14f2 100644
--- a/cli/tools/coverage/mod.rs
+++ b/cli/tools/coverage/mod.rs
@@ -3,10 +3,10 @@
use crate::args::CoverageFlags;
use crate::args::Flags;
use crate::colors;
-use crate::fs_util::collect_files;
use crate::proc_state::ProcState;
-use crate::text_encoding::source_map_from_code;
use crate::tools::fmt::format_json;
+use crate::util::fs::collect_files;
+use crate::util::text_encoding::source_map_from_code;
use deno_ast::MediaType;
use deno_ast::ModuleSpecifier;
diff --git a/cli/tools/fmt.rs b/cli/tools/fmt.rs
index 9474411b7..721937b8d 100644
--- a/cli/tools/fmt.rs
+++ b/cli/tools/fmt.rs
@@ -12,13 +12,13 @@ use crate::args::FmtFlags;
use crate::args::FmtOptionsConfig;
use crate::args::ProseWrap;
use crate::colors;
-use crate::diff::diff;
-use crate::file_watcher;
-use crate::file_watcher::ResolutionResult;
-use crate::fs_util::collect_files;
-use crate::fs_util::get_extension;
-use crate::fs_util::specifier_to_file_path;
-use crate::text_encoding;
+use crate::util::diff::diff;
+use crate::util::file_watcher;
+use crate::util::file_watcher::ResolutionResult;
+use crate::util::fs::collect_files;
+use crate::util::path::get_extension;
+use crate::util::path::specifier_to_file_path;
+use crate::util::text_encoding;
use deno_ast::ParsedSource;
use deno_core::anyhow::bail;
use deno_core::anyhow::Context;
diff --git a/cli/tools/info.rs b/cli/tools/info.rs
index 38aa40a5e..a81dcb55c 100644
--- a/cli/tools/info.rs
+++ b/cli/tools/info.rs
@@ -20,7 +20,6 @@ use deno_runtime::colors;
use crate::args::Flags;
use crate::args::InfoFlags;
-use crate::checksum;
use crate::display;
use crate::npm::NpmPackageId;
use crate::npm::NpmPackageReference;
@@ -29,6 +28,7 @@ use crate::npm::NpmPackageResolver;
use crate::npm::NpmResolutionPackage;
use crate::npm::NpmResolutionSnapshot;
use crate::proc_state::ProcState;
+use crate::util::checksum;
pub async fn info(flags: Flags, info_flags: InfoFlags) -> Result<(), AnyError> {
let ps = ProcState::build(flags).await?;
diff --git a/cli/tools/installer.rs b/cli/tools/installer.rs
index b964619d9..6914c9919 100644
--- a/cli/tools/installer.rs
+++ b/cli/tools/installer.rs
@@ -4,8 +4,8 @@ use crate::args::ConfigFlag;
use crate::args::Flags;
use crate::args::InstallFlags;
use crate::args::TypeCheckMode;
-use crate::fs_util;
use crate::npm::NpmPackageReference;
+use crate::util::fs::canonicalize_path_maybe_not_exists;
use deno_core::anyhow::Context;
use deno_core::error::generic_error;
use deno_core::error::AnyError;
@@ -107,9 +107,7 @@ exec deno {} "$@"
fn get_installer_root() -> Result<PathBuf, io::Error> {
if let Ok(env_dir) = env::var("DENO_INSTALL_ROOT") {
if !env_dir.is_empty() {
- return fs_util::canonicalize_path_maybe_not_exists(&PathBuf::from(
- env_dir,
- ));
+ return canonicalize_path_maybe_not_exists(&PathBuf::from(env_dir));
}
}
// Note: on Windows, the $HOME environment variable may be set by users or by
@@ -167,7 +165,7 @@ pub fn infer_name_from_url(url: &Url) -> Option<String> {
pub fn uninstall(name: String, root: Option<PathBuf>) -> Result<(), AnyError> {
let root = if let Some(root) = root {
- fs_util::canonicalize_path_maybe_not_exists(&root)?
+ canonicalize_path_maybe_not_exists(&root)?
} else {
get_installer_root()?
};
@@ -275,7 +273,7 @@ fn resolve_shim_data(
install_flags: &InstallFlags,
) -> Result<ShimData, AnyError> {
let root = if let Some(root) = &install_flags.root {
- fs_util::canonicalize_path_maybe_not_exists(root)?
+ canonicalize_path_maybe_not_exists(root)?
} else {
get_installer_root()?
};
@@ -450,6 +448,7 @@ mod tests {
use super::*;
use crate::args::ConfigFlag;
+ use crate::util::fs::canonicalize_path;
use std::process::Command;
use test_util::testdata_path;
use test_util::TempDir;
@@ -746,7 +745,7 @@ mod tests {
#[test]
fn install_npm_lockfile_default() {
- let temp_dir = fs_util::canonicalize_path(&env::temp_dir()).unwrap();
+ let temp_dir = canonicalize_path(&env::temp_dir()).unwrap();
let shim_data = resolve_shim_data(
&Flags {
allow_all: true,
diff --git a/cli/tools/lint.rs b/cli/tools/lint.rs
index bfbff8005..2f7cd5111 100644
--- a/cli/tools/lint.rs
+++ b/cli/tools/lint.rs
@@ -10,13 +10,13 @@ use crate::args::Flags;
use crate::args::LintConfig;
use crate::args::LintFlags;
use crate::colors;
-use crate::file_watcher;
-use crate::file_watcher::ResolutionResult;
-use crate::fs_util::collect_files;
-use crate::fs_util::is_supported_ext;
-use crate::fs_util::specifier_to_file_path;
use crate::proc_state::ProcState;
use crate::tools::fmt::run_parallelized;
+use crate::util::file_watcher;
+use crate::util::file_watcher::ResolutionResult;
+use crate::util::fs::collect_files;
+use crate::util::path::is_supported_ext;
+use crate::util::path::specifier_to_file_path;
use deno_ast::MediaType;
use deno_core::anyhow::anyhow;
use deno_core::error::generic_error;
diff --git a/cli/tools/standalone.rs b/cli/tools/standalone.rs
index f173103cb..4436aaa28 100644
--- a/cli/tools/standalone.rs
+++ b/cli/tools/standalone.rs
@@ -6,9 +6,9 @@ use crate::args::Flags;
use crate::args::RunFlags;
use crate::args::TypeCheckMode;
use crate::cache::DenoDir;
-use crate::fs_util;
use crate::standalone::Metadata;
use crate::standalone::MAGIC_TRAILER;
+use crate::util::path::path_has_trailing_slash;
use crate::ProcState;
use deno_core::anyhow::bail;
use deno_core::anyhow::Context;
@@ -299,7 +299,7 @@ pub fn resolve_compile_executable_output_path(
) -> Result<PathBuf, AnyError> {
let module_specifier = resolve_url_or_path(&compile_flags.source_file)?;
compile_flags.output.as_ref().and_then(|output| {
- if fs_util::path_has_trailing_slash(output) {
+ if path_has_trailing_slash(output) {
let infer_file_name = infer_name_from_url(&module_specifier).map(PathBuf::from)?;
Some(output.join(infer_file_name))
} else {
diff --git a/cli/tools/task.rs b/cli/tools/task.rs
index 4cbba8661..39d493492 100644
--- a/cli/tools/task.rs
+++ b/cli/tools/task.rs
@@ -3,8 +3,8 @@
use crate::args::Flags;
use crate::args::TaskFlags;
use crate::colors;
-use crate::fs_util;
use crate::proc_state::ProcState;
+use crate::util::fs::canonicalize_path;
use deno_core::anyhow::bail;
use deno_core::anyhow::Context;
use deno_core::error::AnyError;
@@ -40,7 +40,7 @@ pub async fn execute_script(
}
let cwd = match task_flags.cwd {
- Some(path) => fs_util::canonicalize_path(&PathBuf::from(path))?,
+ Some(path) => canonicalize_path(&PathBuf::from(path))?,
None => config_file_path.parent().unwrap().to_owned(),
};
let task_name = task_flags.task;
diff --git a/cli/tools/test.rs b/cli/tools/test.rs
index 1bb891a1e..07d3f250d 100644
--- a/cli/tools/test.rs
+++ b/cli/tools/test.rs
@@ -3,20 +3,20 @@
use crate::args::Flags;
use crate::args::TestFlags;
use crate::args::TypeCheckMode;
-use crate::checksum;
use crate::colors;
use crate::display;
use crate::file_fetcher::File;
-use crate::file_watcher;
-use crate::file_watcher::ResolutionResult;
-use crate::fs_util::collect_specifiers;
-use crate::fs_util::is_supported_test_ext;
-use crate::fs_util::is_supported_test_path;
-use crate::fs_util::specifier_to_file_path;
use crate::graph_util::contains_specifier;
use crate::graph_util::graph_valid;
use crate::ops;
use crate::proc_state::ProcState;
+use crate::util::checksum;
+use crate::util::file_watcher;
+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::specifier_to_file_path;
use crate::worker::create_main_worker_for_test_or_bench;
use deno_ast::swc::common::comments::CommentKind;
@@ -51,6 +51,7 @@ use std::fmt::Write as _;
use std::io::Read;
use std::io::Write;
use std::num::NonZeroUsize;
+use std::path::Path;
use std::path::PathBuf;
use std::sync::Arc;
use std::time::Duration;
@@ -1184,6 +1185,44 @@ async fn test_specifiers(
Ok(())
}
+/// Checks if the path has a basename and extension Deno supports for tests.
+fn is_supported_test_path(path: &Path) -> bool {
+ if let Some(name) = path.file_stem() {
+ let basename = name.to_string_lossy();
+ (basename.ends_with("_test")
+ || basename.ends_with(".test")
+ || basename == "test")
+ && is_supported_ext(path)
+ } else {
+ false
+ }
+}
+
+/// Checks if the path has an extension Deno supports for tests.
+fn is_supported_test_ext(path: &Path) -> bool {
+ if let Some(ext) = get_extension(path) {
+ matches!(
+ ext.as_str(),
+ "ts"
+ | "tsx"
+ | "js"
+ | "jsx"
+ | "mjs"
+ | "mts"
+ | "cjs"
+ | "cts"
+ | "md"
+ | "mkd"
+ | "mkdn"
+ | "mdwn"
+ | "mdown"
+ | "markdown"
+ )
+ } else {
+ false
+ }
+}
+
/// Collects specifiers marking them with the appropriate test mode while maintaining the natural
/// input order.
///
@@ -1667,3 +1706,67 @@ fn start_output_redirect_thread(
}
});
}
+
+#[cfg(test)]
+mod inner_test {
+ use std::path::Path;
+
+ use super::*;
+
+ #[test]
+ fn test_is_supported_test_ext() {
+ assert!(!is_supported_test_ext(Path::new("tests/subdir/redirects")));
+ assert!(is_supported_test_ext(Path::new("README.md")));
+ assert!(is_supported_test_ext(Path::new("readme.MD")));
+ assert!(is_supported_test_ext(Path::new("lib/typescript.d.ts")));
+ assert!(is_supported_test_ext(Path::new(
+ "testdata/run/001_hello.js"
+ )));
+ assert!(is_supported_test_ext(Path::new(
+ "testdata/run/002_hello.ts"
+ )));
+ assert!(is_supported_test_ext(Path::new("foo.jsx")));
+ assert!(is_supported_test_ext(Path::new("foo.tsx")));
+ assert!(is_supported_test_ext(Path::new("foo.TS")));
+ assert!(is_supported_test_ext(Path::new("foo.TSX")));
+ assert!(is_supported_test_ext(Path::new("foo.JS")));
+ assert!(is_supported_test_ext(Path::new("foo.JSX")));
+ assert!(is_supported_test_ext(Path::new("foo.mjs")));
+ assert!(is_supported_test_ext(Path::new("foo.mts")));
+ assert!(is_supported_test_ext(Path::new("foo.cjs")));
+ assert!(is_supported_test_ext(Path::new("foo.cts")));
+ assert!(!is_supported_test_ext(Path::new("foo.mjsx")));
+ assert!(!is_supported_test_ext(Path::new("foo.jsonc")));
+ assert!(!is_supported_test_ext(Path::new("foo.JSONC")));
+ assert!(!is_supported_test_ext(Path::new("foo.json")));
+ assert!(!is_supported_test_ext(Path::new("foo.JsON")));
+ }
+
+ #[test]
+ fn test_is_supported_test_path() {
+ assert!(is_supported_test_path(Path::new(
+ "tests/subdir/foo_test.ts"
+ )));
+ assert!(is_supported_test_path(Path::new(
+ "tests/subdir/foo_test.tsx"
+ )));
+ assert!(is_supported_test_path(Path::new(
+ "tests/subdir/foo_test.js"
+ )));
+ assert!(is_supported_test_path(Path::new(
+ "tests/subdir/foo_test.jsx"
+ )));
+ assert!(is_supported_test_path(Path::new("bar/foo.test.ts")));
+ assert!(is_supported_test_path(Path::new("bar/foo.test.tsx")));
+ assert!(is_supported_test_path(Path::new("bar/foo.test.js")));
+ assert!(is_supported_test_path(Path::new("bar/foo.test.jsx")));
+ assert!(is_supported_test_path(Path::new("foo/bar/test.js")));
+ assert!(is_supported_test_path(Path::new("foo/bar/test.jsx")));
+ assert!(is_supported_test_path(Path::new("foo/bar/test.ts")));
+ assert!(is_supported_test_path(Path::new("foo/bar/test.tsx")));
+ assert!(!is_supported_test_path(Path::new("README.md")));
+ assert!(!is_supported_test_path(Path::new("lib/typescript.d.ts")));
+ assert!(!is_supported_test_path(Path::new("notatest.js")));
+ assert!(!is_supported_test_path(Path::new("NotAtest.ts")));
+ }
+}
diff --git a/cli/tools/vendor/mappings.rs b/cli/tools/vendor/mappings.rs
index 543536128..d1152b12b 100644
--- a/cli/tools/vendor/mappings.rs
+++ b/cli/tools/vendor/mappings.rs
@@ -13,8 +13,8 @@ use deno_graph::ModuleGraph;
use deno_graph::Position;
use deno_graph::Resolved;
-use crate::fs_util::path_with_stem_suffix;
-use crate::fs_util::relative_specifier;
+use crate::util::path::path_with_stem_suffix;
+use crate::util::path::relative_specifier;
use super::specifiers::dir_name_for_root;
use super::specifiers::get_unique_path;
diff --git a/cli/tools/vendor/mod.rs b/cli/tools/vendor/mod.rs
index 3fd381b21..a1057d838 100644
--- a/cli/tools/vendor/mod.rs
+++ b/cli/tools/vendor/mod.rs
@@ -15,11 +15,12 @@ use crate::args::CliOptions;
use crate::args::Flags;
use crate::args::FmtOptionsConfig;
use crate::args::VendorFlags;
-use crate::fs_util;
-use crate::fs_util::relative_specifier;
-use crate::fs_util::specifier_to_file_path;
use crate::proc_state::ProcState;
use crate::tools::fmt::format_json;
+use crate::util::fs::canonicalize_path;
+use crate::util::fs::resolve_from_cwd;
+use crate::util::path::relative_specifier;
+use crate::util::path::specifier_to_file_path;
mod analyze;
mod build;
@@ -38,7 +39,7 @@ pub async fn vendor(
Some(output_path) => output_path.to_owned(),
None => PathBuf::from("vendor/"),
};
- let output_dir = fs_util::resolve_from_cwd(&raw_output_dir)?;
+ let output_dir = resolve_from_cwd(&raw_output_dir)?;
validate_output_dir(&output_dir, &vendor_flags)?;
validate_options(&mut cli_options, &output_dir)?;
let ps = ProcState::from_options(Arc::new(cli_options)).await?;
@@ -110,18 +111,17 @@ fn validate_options(
if let Some(import_map_path) = options
.resolve_import_map_specifier()?
.and_then(|p| specifier_to_file_path(&p).ok())
- .and_then(|p| fs_util::canonicalize_path(&p).ok())
+ .and_then(|p| canonicalize_path(&p).ok())
{
// make the output directory in order to canonicalize it for the check below
std::fs::create_dir_all(output_dir)?;
- let output_dir =
- fs_util::canonicalize_path(output_dir).with_context(|| {
- format!("Failed to canonicalize: {}", output_dir.display())
- })?;
+ let output_dir = canonicalize_path(output_dir).with_context(|| {
+ format!("Failed to canonicalize: {}", output_dir.display())
+ })?;
if import_map_path.starts_with(&output_dir) {
// canonicalize to make the test for this pass on the CI
- let cwd = fs_util::canonicalize_path(&std::env::current_dir()?)?;
+ let cwd = canonicalize_path(&std::env::current_dir()?)?;
// We don't allow using the output directory to help generate the
// new state because this may lead to cryptic error messages.
log::warn!(
diff --git a/cli/tools/vendor/specifiers.rs b/cli/tools/vendor/specifiers.rs
index 5d4f98278..9d513cc92 100644
--- a/cli/tools/vendor/specifiers.rs
+++ b/cli/tools/vendor/specifiers.rs
@@ -8,8 +8,9 @@ use deno_ast::ModuleSpecifier;
use deno_core::anyhow::anyhow;
use deno_core::error::AnyError;
-use crate::fs_util;
-use crate::fs_util::path_with_stem_suffix;
+use crate::util::path::is_banned_path_char;
+use crate::util::path::path_with_stem_suffix;
+use crate::util::path::root_url_to_safe_local_dirname;
/// Partitions the provided specifiers by the non-path and non-query parts of a specifier.
pub fn partition_by_root_specifiers<'a>(
@@ -30,7 +31,7 @@ pub fn partition_by_root_specifiers<'a>(
/// Gets the directory name to use for the provided root.
pub fn dir_name_for_root(root: &ModuleSpecifier) -> PathBuf {
- fs_util::root_url_to_safe_local_dirname(root)
+ root_url_to_safe_local_dirname(root)
}
/// Gets a unique file path given the provided file path
@@ -74,13 +75,7 @@ pub fn is_remote_specifier_text(text: &str) -> bool {
pub fn sanitize_filepath(text: &str) -> String {
text
.chars()
- .map(|c| {
- if fs_util::is_banned_path_char(c) {
- '_'
- } else {
- c
- }
- })
+ .map(|c| if is_banned_path_char(c) { '_' } else { c })
.collect()
}