diff options
author | Leo Kettmeir <crowlkats@toaxl.com> | 2022-01-05 00:46:34 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-01-05 00:46:34 +0100 |
commit | 80bf2828c6398d000968d61f56f2f808a569adc2 (patch) | |
tree | 22344860e38d03d0ea52e7f66a85c517531d95d8 /cli/fs_util.rs | |
parent | 22d140ffb194de38d842525907265e8a1ca51b04 (diff) |
fix: support `mts`, `cjs` & `cts` files for `deno test` & `deno fmt` (#13274)
Diffstat (limited to 'cli/fs_util.rs')
-rw-r--r-- | cli/fs_util.rs | 46 |
1 files changed, 25 insertions, 21 deletions
diff --git a/cli/fs_util.rs b/cli/fs_util.rs index 20b20cccd..a0b6f64f6 100644 --- a/cli/fs_util.rs +++ b/cli/fs_util.rs @@ -130,7 +130,10 @@ pub fn resolve_from_cwd(path: &Path) -> Result<PathBuf, AnyError> { /// Checks if the path has extension Deno supports. pub fn is_supported_ext(path: &Path) -> bool { if let Some(ext) = get_extension(path) { - matches!(ext.as_str(), "ts" | "tsx" | "js" | "jsx" | "mjs") + matches!( + ext.as_str(), + "ts" | "tsx" | "js" | "jsx" | "mjs" | "mts" | "cjs" | "cts" + ) } else { false } @@ -147,6 +150,9 @@ pub fn is_supported_ext_fmt(path: &Path) -> bool { | "js" | "jsx" | "mjs" + | "mts" + | "cjs" + | "cts" | "json" | "jsonc" | "md" @@ -163,26 +169,12 @@ pub fn is_supported_ext_fmt(path: &Path) -> bool { /// Checks if the path has a basename and extension Deno supports for tests. pub fn is_supported_test_path(path: &Path) -> bool { - use std::path::Component; - if let Some(Component::Normal(basename_os_str)) = - path.components().next_back() - { - let basename = basename_os_str.to_string_lossy(); - basename.ends_with("_test.ts") - || basename.ends_with("_test.tsx") - || basename.ends_with("_test.js") - || basename.ends_with("_test.mjs") - || basename.ends_with("_test.jsx") - || basename.ends_with(".test.ts") - || basename.ends_with(".test.tsx") - || basename.ends_with(".test.js") - || basename.ends_with(".test.mjs") - || basename.ends_with(".test.jsx") - || basename == "test.ts" - || basename == "test.tsx" - || basename == "test.js" - || basename == "test.mjs" - || basename == "test.jsx" + 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 } @@ -198,6 +190,9 @@ pub fn is_supported_test_ext(path: &Path) -> bool { | "js" | "jsx" | "mjs" + | "mts" + | "cjs" + | "cts" | "md" | "mkd" | "mkdn" @@ -443,6 +438,9 @@ mod tests { assert!(is_supported_ext(Path::new("foo.JS"))); assert!(is_supported_ext(Path::new("foo.JSX"))); assert!(is_supported_ext(Path::new("foo.mjs"))); + assert!(is_supported_ext(Path::new("foo.mts"))); + assert!(is_supported_ext(Path::new("foo.cjs"))); + assert!(is_supported_ext(Path::new("foo.cts"))); assert!(!is_supported_ext(Path::new("foo.mjsx"))); } @@ -466,6 +464,9 @@ mod tests { assert!(is_supported_ext_fmt(Path::new("foo.JS"))); assert!(is_supported_ext_fmt(Path::new("foo.JSX"))); assert!(is_supported_ext_fmt(Path::new("foo.mjs"))); + assert!(is_supported_ext_fmt(Path::new("foo.mts"))); + assert!(is_supported_ext_fmt(Path::new("foo.cjs"))); + assert!(is_supported_ext_fmt(Path::new("foo.cts"))); assert!(!is_supported_ext_fmt(Path::new("foo.mjsx"))); assert!(is_supported_ext_fmt(Path::new("foo.jsonc"))); assert!(is_supported_ext_fmt(Path::new("foo.JSONC"))); @@ -493,6 +494,9 @@ mod tests { 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"))); |