summaryrefslogtreecommitdiff
path: root/cli/util
diff options
context:
space:
mode:
authorAsher Gomez <ashersaupingomez@gmail.com>2024-09-03 17:00:57 +1000
committerGitHub <noreply@github.com>2024-09-03 17:00:57 +1000
commit5f08d634f73fab21c17cc02f3f3bf8e8b531eee8 (patch)
treee105697d4ecb23cad491a04af878bc44edfa66a1 /cli/util
parent2533d68cabb5a38be891a9807c452ca802401d46 (diff)
BREAKING: remove `deno vendor` (#25343)
Diffstat (limited to 'cli/util')
-rw-r--r--cli/util/fs.rs41
-rw-r--r--cli/util/path.rs68
2 files changed, 1 insertions, 108 deletions
diff --git a/cli/util/fs.rs b/cli/util/fs.rs
index 145f9c83b..d723d24e1 100644
--- a/cli/util/fs.rs
+++ b/cli/util/fs.rs
@@ -1,6 +1,5 @@
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
-use std::env::current_dir;
use std::fs::OpenOptions;
use std::io::Error;
use std::io::ErrorKind;
@@ -18,7 +17,6 @@ use deno_config::glob::WalkEntry;
use deno_core::anyhow::anyhow;
use deno_core::anyhow::Context;
use deno_core::error::AnyError;
-pub use deno_core::normalize_path;
use deno_core::unsync::spawn_blocking;
use deno_core::ModuleSpecifier;
use deno_runtime::deno_fs::FileSystem;
@@ -255,18 +253,6 @@ fn canonicalize_path_maybe_not_exists_with_custom_fn(
}
}
-pub fn resolve_from_cwd(path: &Path) -> Result<PathBuf, AnyError> {
- let resolved_path = if path.is_absolute() {
- path.to_owned()
- } else {
- let cwd =
- current_dir().context("Failed to get current working directory")?;
- cwd.join(path)
- };
-
- Ok(normalize_path(resolved_path))
-}
-
/// Collects module specifiers that satisfy the given predicate as a file path, by recursively walking `include`.
/// Specifiers that start with http and https are left intact.
/// Note: This ignores all .git and node_modules folders.
@@ -715,6 +701,7 @@ pub fn specifier_from_file_path(
mod tests {
use super::*;
use deno_core::futures;
+ use deno_core::normalize_path;
use deno_core::parking_lot::Mutex;
use pretty_assertions::assert_eq;
use test_util::PathRef;
@@ -722,24 +709,6 @@ mod tests {
use tokio::sync::Notify;
#[test]
- fn resolve_from_cwd_child() {
- let cwd = current_dir().unwrap();
- assert_eq!(resolve_from_cwd(Path::new("a")).unwrap(), cwd.join("a"));
- }
-
- #[test]
- fn resolve_from_cwd_dot() {
- let cwd = current_dir().unwrap();
- assert_eq!(resolve_from_cwd(Path::new(".")).unwrap(), cwd);
- }
-
- #[test]
- fn resolve_from_cwd_parent() {
- let cwd = current_dir().unwrap();
- assert_eq!(resolve_from_cwd(Path::new("a/..")).unwrap(), cwd);
- }
-
- #[test]
fn test_normalize_path() {
assert_eq!(normalize_path(Path::new("a/../b")), PathBuf::from("b"));
assert_eq!(normalize_path(Path::new("a/./b/")), PathBuf::from("a/b/"));
@@ -757,14 +726,6 @@ mod tests {
}
#[test]
- fn resolve_from_cwd_absolute() {
- let expected = Path::new("a");
- let cwd = current_dir().unwrap();
- let absolute_expected = cwd.join(expected);
- assert_eq!(resolve_from_cwd(expected).unwrap(), absolute_expected);
- }
-
- #[test]
fn test_collect_specifiers() {
fn create_files(dir_path: &PathRef, files: &[&str]) {
dir_path.create_dir_all();
diff --git a/cli/util/path.rs b/cli/util/path.rs
index 16378e30b..804b26f65 100644
--- a/cli/util/path.rs
+++ b/cli/util/path.rs
@@ -145,34 +145,6 @@ pub fn relative_specifier(
Some(to_percent_decoded_str(&text))
}
-/// Gets a path with the specified file stem suffix.
-///
-/// Ex. `file.ts` with suffix `_2` returns `file_2.ts`
-pub fn path_with_stem_suffix(path: &Path, suffix: &str) -> PathBuf {
- if let Some(file_name) = path.file_name().map(|f| f.to_string_lossy()) {
- if let Some(file_stem) = path.file_stem().map(|f| f.to_string_lossy()) {
- if let Some(ext) = path.extension().map(|f| f.to_string_lossy()) {
- return if file_stem.to_lowercase().ends_with(".d") {
- path.with_file_name(format!(
- "{}{}.{}.{}",
- &file_stem[..file_stem.len() - ".d".len()],
- suffix,
- // maintain casing
- &file_stem[file_stem.len() - "d".len()..],
- ext
- ))
- } else {
- path.with_file_name(format!("{file_stem}{suffix}.{ext}"))
- };
- }
- }
-
- path.with_file_name(format!("{file_name}{suffix}"))
- } else {
- path.with_file_name(suffix)
- }
-}
-
#[cfg_attr(windows, allow(dead_code))]
pub fn relative_path(from: &Path, to: &Path) -> Option<PathBuf> {
pathdiff::diff_paths(to, from)
@@ -406,46 +378,6 @@ mod test {
}
#[test]
- fn test_path_with_stem_suffix() {
- assert_eq!(
- path_with_stem_suffix(&PathBuf::from("/"), "_2"),
- PathBuf::from("/_2")
- );
- assert_eq!(
- path_with_stem_suffix(&PathBuf::from("/test"), "_2"),
- PathBuf::from("/test_2")
- );
- assert_eq!(
- path_with_stem_suffix(&PathBuf::from("/test.txt"), "_2"),
- PathBuf::from("/test_2.txt")
- );
- assert_eq!(
- path_with_stem_suffix(&PathBuf::from("/test/subdir"), "_2"),
- PathBuf::from("/test/subdir_2")
- );
- assert_eq!(
- path_with_stem_suffix(&PathBuf::from("/test/subdir.other.txt"), "_2"),
- PathBuf::from("/test/subdir.other_2.txt")
- );
- assert_eq!(
- path_with_stem_suffix(&PathBuf::from("/test.d.ts"), "_2"),
- PathBuf::from("/test_2.d.ts")
- );
- assert_eq!(
- path_with_stem_suffix(&PathBuf::from("/test.D.TS"), "_2"),
- PathBuf::from("/test_2.D.TS")
- );
- assert_eq!(
- path_with_stem_suffix(&PathBuf::from("/test.d.mts"), "_2"),
- PathBuf::from("/test_2.d.mts")
- );
- assert_eq!(
- path_with_stem_suffix(&PathBuf::from("/test.d.cts"), "_2"),
- PathBuf::from("/test_2.d.cts")
- );
- }
-
- #[test]
fn test_to_percent_decoded_str() {
let str = to_percent_decoded_str("%F0%9F%A6%95");
assert_eq!(str, "🦕");