Skip to content

Commit be1e1b4

Browse files
committed
refactor: do not store is_symlink in CachedPathImpl (#850)
`std::fs::metadata` always return `is_symlink: false` so it's confusing and pointless to store it in CachedPathImpl
1 parent 3a9d5e7 commit be1e1b4

File tree

3 files changed

+16
-12
lines changed

3 files changed

+16
-12
lines changed

examples/many.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,7 @@ fn main() {
5252
}
5353
}
5454

55-
// Initialize resolver
5655
let options = ResolveOptions {
57-
alias_fields: vec![vec!["browser".into()]],
58-
// ESM
5956
condition_names: vec!["node".into(), "import".into()],
6057
..ResolveOptions::default()
6158
};

src/cache/cache_impl.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,22 +79,22 @@ impl<Fs: FileSystem> Cache<Fs> {
7979
}
8080

8181
pub(crate) fn is_file(&self, path: &CachedPath, ctx: &mut Ctx) -> bool {
82-
if let Some(meta) = path.meta(&self.fs) {
82+
if path.is_file(&self.fs).is_some_and(|b| b) {
8383
ctx.add_file_dependency(path.path());
84-
meta.is_file
84+
true
8585
} else {
8686
ctx.add_missing_dependency(path.path());
8787
false
8888
}
8989
}
9090

9191
pub(crate) fn is_dir(&self, path: &CachedPath, ctx: &mut Ctx) -> bool {
92-
path.meta(&self.fs).map_or_else(
92+
path.is_dir(&self.fs).map_or_else(
9393
|| {
9494
ctx.add_missing_dependency(path.path());
9595
false
9696
},
97-
|meta| meta.is_dir,
97+
|b| b,
9898
)
9999
}
100100

src/cache/cached_path.rs

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@ use once_cell::sync::OnceCell as OnceLock;
1313
use super::cache_impl::Cache;
1414
use super::thread_local::SCRATCH_PATH;
1515
use crate::{
16-
FileMetadata, FileSystem, PackageJson, ResolveError, ResolveOptions, TsConfig,
17-
context::ResolveContext as Ctx,
16+
FileSystem, PackageJson, ResolveError, ResolveOptions, TsConfig, context::ResolveContext as Ctx,
1817
};
1918

2019
#[derive(Clone)]
@@ -26,7 +25,7 @@ pub struct CachedPathImpl {
2625
pub parent: Option<Weak<CachedPathImpl>>,
2726
pub is_node_modules: bool,
2827
pub inside_node_modules: bool,
29-
pub meta: OnceLock<Option<FileMetadata>>,
28+
pub meta: OnceLock<Option<(/* is_file */ bool, /* is_dir */ bool)>>, // None means not found.
3029
pub canonicalized: OnceLock<Weak<CachedPathImpl>>,
3130
pub node_modules: OnceLock<Option<Weak<CachedPathImpl>>>,
3231
pub package_json: OnceLock<Option<Arc<PackageJson>>>,
@@ -226,8 +225,16 @@ impl CachedPath {
226225
}
227226

228227
impl CachedPath {
229-
pub(crate) fn meta<Fs: FileSystem>(&self, fs: &Fs) -> Option<FileMetadata> {
230-
*self.meta.get_or_init(|| fs.metadata(&self.path).ok())
228+
fn metadata<Fs: FileSystem>(&self, fs: &Fs) -> Option<(bool, bool)> {
229+
*self.meta.get_or_init(|| fs.metadata(&self.path).ok().map(|r| (r.is_file, r.is_dir)))
230+
}
231+
232+
pub(crate) fn is_file<Fs: FileSystem>(&self, fs: &Fs) -> Option<bool> {
233+
self.metadata(fs).map(|r| r.0)
234+
}
235+
236+
pub(crate) fn is_dir<Fs: FileSystem>(&self, fs: &Fs) -> Option<bool> {
237+
self.metadata(fs).map(|r| r.1)
231238
}
232239
}
233240

0 commit comments

Comments
 (0)