refactor: move PackageJson to deno_config (#24348)

This commit is contained in:
David Sherret 2024-06-26 17:24:10 -04:00 committed by GitHub
parent 86e0292733
commit 0da01c0ca6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
28 changed files with 509 additions and 871 deletions

View file

@ -304,6 +304,35 @@ pub trait FileSystem: std::fmt::Debug + MaybeSend + MaybeSync {
}
}
pub struct DenoConfigFsAdapter<'a>(&'a dyn FileSystem);
impl<'a> DenoConfigFsAdapter<'a> {
pub fn new(fs: &'a dyn FileSystem) -> Self {
Self(fs)
}
}
impl<'a> deno_config::fs::DenoConfigFs for DenoConfigFsAdapter<'a> {
fn read_to_string(&self, path: &Path) -> Result<String, std::io::Error> {
use deno_io::fs::FsError;
use std::io::ErrorKind;
self
.0
.read_text_file_lossy_sync(path, None)
.map_err(|err| match err {
FsError::Io(io) => io,
FsError::FileBusy => std::io::Error::new(ErrorKind::Other, "file busy"),
FsError::NotSupported => {
std::io::Error::new(ErrorKind::Other, "not supported")
}
FsError::PermissionDenied(name) => std::io::Error::new(
ErrorKind::PermissionDenied,
format!("requires {}", name),
),
})
}
}
// Like String::from_utf8_lossy but operates on owned values
#[inline(always)]
fn string_from_utf8_lossy(buf: Vec<u8>) -> String {