Skip to content

Commit 367c6e8

Browse files
committed
add cache
1 parent a289067 commit 367c6e8

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

src/cache/cached_path.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,10 @@ pub struct CachedPathImpl {
2828
pub canonicalized: OnceLock<Weak<CachedPathImpl>>,
2929
pub node_modules: OnceLock<Option<Weak<CachedPathImpl>>>,
3030
pub package_json: OnceLock<Option<PackageJsonIndex>>,
31+
/// `tsconfig.json` found at path.
3132
pub tsconfig: OnceLock<Option<Arc<TsConfig>>>,
33+
/// `tsconfig.json` after resolving `references`, `files`, `include` and `extend`.
34+
pub resolved_tsconfig: OnceLock<Option<Arc<TsConfig>>>,
3235
}
3336

3437
impl CachedPathImpl {
@@ -50,6 +53,7 @@ impl CachedPathImpl {
5053
node_modules: OnceLock::new(),
5154
package_json: OnceLock::new(),
5255
tsconfig: OnceLock::new(),
56+
resolved_tsconfig: OnceLock::new(),
5357
}
5458
}
5559
}

src/tsconfig_resolver.rs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,18 @@ impl<Fs: FileSystem> ResolverGeneric<Fs> {
5858
let span = tracing::debug_span!("find_tsconfig", path = ?path);
5959
let _enter = span.enter();
6060
let cached_path = self.cache.value(path);
61-
self.find_tsconfig_impl(&cached_path, &mut Ctx::default()).map(|option_tsconfig| {
62-
option_tsconfig.map(|tsconfig| {
63-
let r = TsConfig::resolve_tsconfig_solution(tsconfig, path);
64-
tracing::debug!(path = ?path, ret = ?r);
65-
r
61+
cached_path
62+
.resolved_tsconfig
63+
.get_or_try_init(|| {
64+
self.find_tsconfig_impl(&cached_path, &mut Ctx::default()).map(|option_tsconfig| {
65+
option_tsconfig.map(|tsconfig| {
66+
let r = TsConfig::resolve_tsconfig_solution(tsconfig, path);
67+
tracing::debug!(path = ?path, ret = ?r);
68+
r
69+
})
70+
})
6671
})
67-
})
72+
.cloned()
6873
}
6974

7075
/// Find tsconfig.json of a path by traversing parent directories.

0 commit comments

Comments
 (0)