summaryrefslogtreecommitdiff
path: root/runtime/fs_util.rs
diff options
context:
space:
mode:
authorDavid Sherret <dsherret@users.noreply.github.com>2023-05-10 20:06:59 -0400
committerGitHub <noreply@github.com>2023-05-10 20:06:59 -0400
commit28aa489de9cd4f995ec2fc02e2c9d224e89f4c01 (patch)
treeb316937a47fe9c8f9f6768bc13b9a686c07cf42f /runtime/fs_util.rs
parent5fd74bfa1c5ed514c3e19fdb2e8590fe251d3ee6 (diff)
feat(compile): unstable npm and node specifier support (#19005)
This is the initial support for npm and node specifiers in `deno compile`. The npm packages are included in the binary and read from it via a virtual file system. This also supports the `--node-modules-dir` flag, dependencies specified in a package.json, and npm binary commands (ex. `deno compile --unstable npm:cowsay`) Closes #16632
Diffstat (limited to 'runtime/fs_util.rs')
-rw-r--r--runtime/fs_util.rs25
1 files changed, 12 insertions, 13 deletions
diff --git a/runtime/fs_util.rs b/runtime/fs_util.rs
index eb4a2f899..204b0e4e8 100644
--- a/runtime/fs_util.rs
+++ b/runtime/fs_util.rs
@@ -3,23 +3,17 @@
use deno_core::anyhow::Context;
use deno_core::error::AnyError;
pub use deno_core::normalize_path;
-use std::env::current_dir;
-use std::io::Error;
use std::path::Path;
use std::path::PathBuf;
-/// Similar to `std::fs::canonicalize()` but strips UNC prefixes on Windows.
-pub fn canonicalize_path(path: &Path) -> Result<PathBuf, Error> {
- Ok(deno_core::strip_unc_prefix(path.canonicalize()?))
-}
-
#[inline]
pub fn resolve_from_cwd(path: &Path) -> Result<PathBuf, AnyError> {
if path.is_absolute() {
Ok(normalize_path(path))
} else {
- let cwd =
- current_dir().context("Failed to get current working directory")?;
+ #[allow(clippy::disallowed_methods)]
+ let cwd = std::env::current_dir()
+ .context("Failed to get current working directory")?;
Ok(normalize_path(cwd.join(path)))
}
}
@@ -28,21 +22,26 @@ pub fn resolve_from_cwd(path: &Path) -> Result<PathBuf, AnyError> {
mod tests {
use super::*;
+ fn current_dir() -> PathBuf {
+ #[allow(clippy::disallowed_methods)]
+ std::env::current_dir().unwrap()
+ }
+
#[test]
fn resolve_from_cwd_child() {
- let cwd = current_dir().unwrap();
+ let cwd = current_dir();
assert_eq!(resolve_from_cwd(Path::new("a")).unwrap(), cwd.join("a"));
}
#[test]
fn resolve_from_cwd_dot() {
- let cwd = current_dir().unwrap();
+ let cwd = current_dir();
assert_eq!(resolve_from_cwd(Path::new(".")).unwrap(), cwd);
}
#[test]
fn resolve_from_cwd_parent() {
- let cwd = current_dir().unwrap();
+ let cwd = current_dir();
assert_eq!(resolve_from_cwd(Path::new("a/..")).unwrap(), cwd);
}
@@ -66,7 +65,7 @@ mod tests {
#[test]
fn resolve_from_cwd_absolute() {
let expected = Path::new("a");
- let cwd = current_dir().unwrap();
+ let cwd = current_dir();
let absolute_expected = cwd.join(expected);
assert_eq!(resolve_from_cwd(expected).unwrap(), absolute_expected);
}