summaryrefslogtreecommitdiff
path: root/cli/util/fs.rs
diff options
context:
space:
mode:
authorDavid Sherret <dsherret@users.noreply.github.com>2024-09-30 09:33:32 -0400
committerGitHub <noreply@github.com>2024-09-30 13:33:32 +0000
commit69ab72002550b5797185b7651de28c700b220bb2 (patch)
treece224c0631f42e3ad73e6bd848d1a597d19f1a9f /cli/util/fs.rs
parentc8f692057b256dac57342867b7606a74309449fc (diff)
refactor: move ByonmNpmResolver to deno_resolver (#25937)
Some more slow progress on moving all the resolution code into deno_resolver.
Diffstat (limited to 'cli/util/fs.rs')
-rw-r--r--cli/util/fs.rs35
1 files changed, 2 insertions, 33 deletions
diff --git a/cli/util/fs.rs b/cli/util/fs.rs
index 9734d417e..a021ec19c 100644
--- a/cli/util/fs.rs
+++ b/cli/util/fs.rs
@@ -20,7 +20,6 @@ use deno_core::error::AnyError;
use deno_core::unsync::spawn_blocking;
use deno_core::ModuleSpecifier;
use deno_runtime::deno_fs::FileSystem;
-use deno_runtime::deno_node::PathClean;
use crate::util::path::get_atomic_file_path;
use crate::util::progress_bar::ProgressBar;
@@ -290,48 +289,18 @@ pub fn canonicalize_path(path: &Path) -> Result<PathBuf, Error> {
pub fn canonicalize_path_maybe_not_exists(
path: &Path,
) -> Result<PathBuf, Error> {
- canonicalize_path_maybe_not_exists_with_custom_fn(path, canonicalize_path)
+ deno_path_util::canonicalize_path_maybe_not_exists(path, &canonicalize_path)
}
pub fn canonicalize_path_maybe_not_exists_with_fs(
path: &Path,
fs: &dyn FileSystem,
) -> Result<PathBuf, Error> {
- canonicalize_path_maybe_not_exists_with_custom_fn(path, |path| {
+ deno_path_util::canonicalize_path_maybe_not_exists(path, &|path| {
fs.realpath_sync(path).map_err(|err| err.into_io_error())
})
}
-fn canonicalize_path_maybe_not_exists_with_custom_fn(
- path: &Path,
- canonicalize: impl Fn(&Path) -> Result<PathBuf, Error>,
-) -> Result<PathBuf, Error> {
- let path = path.to_path_buf().clean();
- let mut path = path.as_path();
- let mut names_stack = Vec::new();
- loop {
- match canonicalize(path) {
- Ok(mut canonicalized_path) => {
- for name in names_stack.into_iter().rev() {
- canonicalized_path = canonicalized_path.join(name);
- }
- return Ok(canonicalized_path);
- }
- Err(err) if err.kind() == ErrorKind::NotFound => {
- names_stack.push(match path.file_name() {
- Some(name) => name.to_owned(),
- None => return Err(err),
- });
- path = match path.parent() {
- Some(parent) => parent,
- None => return Err(err),
- };
- }
- Err(err) => return Err(err),
- }
- }
-}
-
/// 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.