chore: 🤖 make FileSystem trait object safe (#1157)

This commit is contained in:
IWANABETHATGUY 2023-11-05 23:40:08 +08:00 committed by GitHub
parent 3b88f748fd
commit 7c8342d6be
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 9 additions and 6 deletions

View file

@ -25,7 +25,7 @@ pub struct Cache<Fs> {
tsconfigs: DashMap<PathBuf, Arc<TsConfig>, BuildHasherDefault<FxHasher>>,
}
impl<Fs: FileSystem> Cache<Fs> {
impl<Fs: FileSystem + Default> Cache<Fs> {
pub fn new(fs: Fs) -> Self {
Self { fs, ..Self::default() }
}
@ -215,7 +215,7 @@ impl CachedPathImpl {
.map(|r| r.unwrap_or_else(|| self.path.clone().to_path_buf()))
}
pub fn module_directory<Fs: FileSystem>(
pub fn module_directory<Fs: FileSystem + Default>(
&self,
module_name: &str,
cache: &Cache<Fs>,
@ -224,7 +224,10 @@ impl CachedPathImpl {
cached_path.is_dir(&cache.fs).then(|| cached_path)
}
pub fn cached_node_modules<Fs: FileSystem>(&self, cache: &Cache<Fs>) -> Option<CachedPath> {
pub fn cached_node_modules<Fs: FileSystem + Default>(
&self,
cache: &Cache<Fs>,
) -> Option<CachedPath> {
self.node_modules.get_or_init(|| self.module_directory("node_modules", cache)).clone()
}

View file

@ -4,7 +4,7 @@ use std::{
};
/// File System abstraction used for `ResolverGeneric`.
pub trait FileSystem: Default + Send + Sync {
pub trait FileSystem: Send + Sync {
/// See [std::fs::read_to_string]
///
/// # Errors

View file

@ -134,13 +134,13 @@ struct ResolveContextImpl {
depth: u8,
}
impl<Fs: FileSystem> Default for ResolverGeneric<Fs> {
impl<Fs: FileSystem + Default> Default for ResolverGeneric<Fs> {
fn default() -> Self {
Self::new(ResolveOptions::default())
}
}
impl<Fs: FileSystem> ResolverGeneric<Fs> {
impl<Fs: FileSystem + Default> ResolverGeneric<Fs> {
pub fn new(options: ResolveOptions) -> Self {
#[cfg(feature = "tracing-subscriber")]
tracing_subscriber::init();