Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,14 @@ impl<Fs: Send + Sync + FileSystem> Cache<Fs> {
self.tsconfigs.clear();
}

/// Clear the path cache without clearing the tsconfig cache.
///
/// This is useful for HMR (Hot Module Replacement) scenarios where tsconfig.json
/// doesn't change during development, but file system state may change.
pub fn clear_without_tsconfig(&self) {
self.paths.clear();
}

pub fn value(&self, path: &Path) -> CachedPath {
let hash = {
let mut hasher = FxHasher::default();
Expand Down
15 changes: 15 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,21 @@ impl<Fs: FileSystem + Send + Sync> ResolverGeneric<Fs> {
}
}

/// Clear the underlying cache without clearing tsconfig cache.
///
/// This is useful for HMR (Hot Module Replacement) scenarios where tsconfig.json
/// doesn't change during development, but file system state may change.
/// Preserving the tsconfig cache avoids re-parsing tsconfig.json on every HMR update,
/// which can cause intermittent module resolution failures with tsconfig path aliases.
pub fn clear_cache_without_tsconfig(&self) {
self.cache.clear_without_tsconfig();
#[cfg(feature = "yarn_pnp")]
{
self.pnp_manifest_content_cache.clear();
self.pnp_manifest_path_cache.clear();
}
}

/// Resolve `specifier` at an absolute path to a `directory`.
///
/// A specifier is the string passed to require or import, i.e. `require("specifier")` or `import "specifier"`.
Expand Down