diff options
author | David Sherret <dsherret@users.noreply.github.com> | 2023-11-29 09:32:23 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-11-29 09:32:23 -0500 |
commit | 9ac405d587ca1465debd4a65a09324b7a6b2c04f (patch) | |
tree | b3cc4adb3ddf06dc5d380c39f9e8a82c24b25655 /cli/util/fs.rs | |
parent | 7e56a0466fc9964ca5dd3533bb65c00cd1bac4dc (diff) |
feat(compile): support "bring your own node_modules" in deno compile (#21377)
Not tested thoroughly. This is a good start.
Closes #21350
Diffstat (limited to 'cli/util/fs.rs')
-rw-r--r-- | cli/util/fs.rs | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/cli/util/fs.rs b/cli/util/fs.rs index 33eb3af9d..4881d0815 100644 --- a/cli/util/fs.rs +++ b/cli/util/fs.rs @@ -6,6 +6,7 @@ pub use deno_core::normalize_path; use deno_core::unsync::spawn_blocking; use deno_core::ModuleSpecifier; use deno_runtime::deno_crypto::rand; +use deno_runtime::deno_fs::FileSystem; use deno_runtime::deno_node::PathClean; use std::borrow::Cow; use std::env::current_dir; @@ -187,11 +188,20 @@ 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_fs(path, canonicalize_path) + canonicalize_path_maybe_not_exists_with_custom_fn(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| { + 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(); |