summaryrefslogtreecommitdiff
path: root/cli/util
diff options
context:
space:
mode:
authorDavid Sherret <dsherret@users.noreply.github.com>2024-09-05 16:22:13 +0200
committerGitHub <noreply@github.com>2024-09-05 14:22:13 +0000
commitc678550a176ce5592d4b6e7ffb918e6926858a45 (patch)
treeeb1a1f7ce99f95bf6e4086a75bc7f3739a5b23a1 /cli/util
parent15fce5b290d7dc3eb503a70bd8a10aaf72a09f5e (diff)
BREAKING: remove "emit" and "map" from deno info output (#25468)
The map field has been empty for years now and we don't want the emit file to be exposed so it allows us to iterate on making the cache faster. Additionally, it's racy/unreliable to rely on this information. Instead, people should emit the TS files themselves using tools like deno_emit, typescript, esbuild, etc. Closes https://github.com/denoland/deno/issues/17703
Diffstat (limited to 'cli/util')
-rw-r--r--cli/util/path.rs27
1 files changed, 27 insertions, 0 deletions
diff --git a/cli/util/path.rs b/cli/util/path.rs
index 804b26f65..6f09cf1ea 100644
--- a/cli/util/path.rs
+++ b/cli/util/path.rs
@@ -42,6 +42,21 @@ pub fn get_extension(file_path: &Path) -> Option<String> {
.map(|e| e.to_lowercase());
}
+pub fn specifier_has_extension(
+ specifier: &ModuleSpecifier,
+ searching_ext: &str,
+) -> bool {
+ let Some((_, ext)) = specifier.path().rsplit_once('.') else {
+ return false;
+ };
+ let searching_ext = searching_ext.strip_prefix('.').unwrap_or(searching_ext);
+ debug_assert!(!searching_ext.contains('.')); // exts like .d.ts are not implemented here
+ if ext.len() != searching_ext.len() {
+ return false;
+ }
+ ext.eq_ignore_ascii_case(searching_ext)
+}
+
pub fn get_atomic_dir_path(file_path: &Path) -> PathBuf {
let rand = gen_rand_path_component();
let new_file_name = format!(
@@ -378,6 +393,18 @@ mod test {
}
#[test]
+ fn test_specifier_has_extension() {
+ fn get(specifier: &str, ext: &str) -> bool {
+ specifier_has_extension(&ModuleSpecifier::parse(specifier).unwrap(), ext)
+ }
+
+ assert!(get("file:///a/b/c.ts", "ts"));
+ assert!(get("file:///a/b/c.ts", ".ts"));
+ assert!(!get("file:///a/b/c.ts", ".cts"));
+ assert!(get("file:///a/b/c.CtS", ".cts"));
+ }
+
+ #[test]
fn test_to_percent_decoded_str() {
let str = to_percent_decoded_str("%F0%9F%A6%95");
assert_eq!(str, "🦕");