diff --git a/crates/oxc_resolver/src/file_system.rs b/crates/oxc_resolver/src/file_system.rs index a676d8d26..fb625d101 100644 --- a/crates/oxc_resolver/src/file_system.rs +++ b/crates/oxc_resolver/src/file_system.rs @@ -1,6 +1,8 @@ use std::{ fs, io, + ops::Deref, path::{Path, PathBuf}, + sync::Arc, }; /// File System abstraction used for `ResolverGeneric`. @@ -94,3 +96,25 @@ impl FileSystem for FileSystemOs { dunce::canonicalize(path) } } + +/// Impl FileSystem for Arc when T satisfies FileSystem, it is useful when the user wants to share the filesystem into multiple threads. +impl FileSystem for Arc +where + T: FileSystem, +{ + fn read_to_string(&self, path: &Path) -> io::Result { + self.deref().read_to_string(path) + } + + fn metadata(&self, path: &Path) -> io::Result { + self.deref().metadata(path) + } + + fn symlink_metadata(&self, path: &Path) -> io::Result { + self.deref().symlink_metadata(path) + } + + fn canonicalize(&self, path: &Path) -> io::Result { + self.deref().canonicalize(path) + } +}