diff options
author | David Sherret <dsherret@users.noreply.github.com> | 2024-07-25 19:08:14 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-07-25 19:08:14 -0400 |
commit | 3bf147fe287ac779b20d318daba56b336f356adf (patch) | |
tree | 3b5bfe2a1ad918b275a2cd08f7dcc05f90a180ab /ext/node_resolver/env.rs | |
parent | 0cf7f268a7df7711ac6ab8c2c67b4d7abf454fcd (diff) |
refactor: decouple node resolution from deno_core (#24724)
Diffstat (limited to 'ext/node_resolver/env.rs')
-rw-r--r-- | ext/node_resolver/env.rs | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/ext/node_resolver/env.rs b/ext/node_resolver/env.rs new file mode 100644 index 000000000..b520ece0f --- /dev/null +++ b/ext/node_resolver/env.rs @@ -0,0 +1,39 @@ +// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. + +use std::path::Path; +use std::path::PathBuf; + +use crate::sync::MaybeSend; +use crate::sync::MaybeSync; + +pub struct NodeResolverFsStat { + pub is_file: bool, + pub is_dir: bool, + pub is_symlink: bool, +} + +pub trait NodeResolverEnv: std::fmt::Debug + MaybeSend + MaybeSync { + fn is_builtin_node_module(&self, specifier: &str) -> bool; + + fn realpath_sync(&self, path: &Path) -> std::io::Result<PathBuf>; + + fn stat_sync(&self, path: &Path) -> std::io::Result<NodeResolverFsStat>; + + fn exists_sync(&self, path: &Path) -> bool; + + fn is_file_sync(&self, path: &Path) -> bool { + self + .stat_sync(path) + .map(|stat| stat.is_file) + .unwrap_or(false) + } + + fn is_dir_sync(&self, path: &Path) -> bool { + self + .stat_sync(path) + .map(|stat| stat.is_dir) + .unwrap_or(false) + } + + fn pkg_json_fs(&self) -> &dyn deno_package_json::fs::DenoPkgJsonFs; +} |