diff options
author | David Sherret <dsherret@users.noreply.github.com> | 2024-09-30 09:33:32 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-09-30 13:33:32 +0000 |
commit | 69ab72002550b5797185b7651de28c700b220bb2 (patch) | |
tree | ce224c0631f42e3ad73e6bd848d1a597d19f1a9f /cli/resolver.rs | |
parent | c8f692057b256dac57342867b7606a74309449fc (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/resolver.rs')
-rw-r--r-- | cli/resolver.rs | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/cli/resolver.rs b/cli/resolver.rs index 211f8aba1..7804261b8 100644 --- a/cli/resolver.rs +++ b/cli/resolver.rs @@ -61,6 +61,46 @@ pub struct ModuleCodeStringSource { pub media_type: MediaType, } +#[derive(Debug, Clone)] +pub struct CliDenoResolverFs(pub Arc<dyn FileSystem>); + +impl deno_resolver::fs::DenoResolverFs for CliDenoResolverFs { + fn read_to_string_lossy(&self, path: &Path) -> std::io::Result<String> { + self + .0 + .read_text_file_lossy_sync(path, None) + .map_err(|e| e.into_io_error()) + } + + fn realpath_sync(&self, path: &Path) -> std::io::Result<PathBuf> { + self.0.realpath_sync(path).map_err(|e| e.into_io_error()) + } + + fn is_dir_sync(&self, path: &Path) -> bool { + self.0.is_dir_sync(path) + } + + fn read_dir_sync( + &self, + dir_path: &Path, + ) -> std::io::Result<Vec<deno_resolver::fs::DirEntry>> { + self + .0 + .read_dir_sync(dir_path) + .map(|entries| { + entries + .into_iter() + .map(|e| deno_resolver::fs::DirEntry { + name: e.name, + is_file: e.is_file, + is_directory: e.is_directory, + }) + .collect::<Vec<_>>() + }) + .map_err(|err| err.into_io_error()) + } +} + #[derive(Debug)] pub struct CliNodeResolver { cjs_resolutions: Arc<CjsResolutionStore>, |