Skip to content

Conversation

@vdiez
Copy link
Contributor

@vdiez vdiez commented Dec 8, 2025

Summary

  • Introduce a new FsCache singleton in the shared package that consolidates file system caching across the codebase
  • Migrate sourceFileContentCache to use FsCache for file contents (keeping parsed AST cache separate)
  • Migrate tsconfigContentCache to use FsCache with separate tracking for missing-but-fallback tsconfig files
  • Update IncrementalCompilerHost to use FsCache and track known content per host instance for proper change detection

This is the first step toward unifying all FS-related caches into a single source of truth.

Architecture

┌─────────────────────────────────────────────────────────────────┐
│                     Analysis Layer                               │
│  (analyzeWithProgram, analyzeWithIncrementalProgram, rules)     │
└─────────────────────────────────────────────────────────────────┘
                              │
                              ▼
┌─────────────────────────────────────────────────────────────────┐
│                    Program Cache                                 │
│  (ProgramCacheManager - ts.Program instances)                   │
└─────────────────────────────────────────────────────────────────┘
                              │
                              ▼
┌─────────────────────────────────────────────────────────────────┐
│                  Parsed Content Cache                            │
│  - parsedSourceFileCache (ASTs)                                 │
│  - programOptionsCache (parsed tsconfig options)                │
│  - dependenciesCache (parsed package.json deps)                 │
└─────────────────────────────────────────────────────────────────┘
                              │
                              ▼
┌─────────────────────────────────────────────────────────────────┐
│                      FS Cache Layer (NEW)                        │
│  Single source of truth for all file system access:            │
│  - File contents (source, tsconfig, package.json, etc.)        │
│  - File existence / directory listing                           │
│  - Invalidation based on baseDir change or fsEvents            │
└─────────────────────────────────────────────────────────────────┘
                              │
                              ▼
┌─────────────────────────────────────────────────────────────────┐
│                    File System (node:fs)                         │
└─────────────────────────────────────────────────────────────────┘

Test plan

  • All program tests pass (110 tests)
  • tsconfigs tests pass (5 tests)
  • TypeScript type checking passes

Future work

The following caches can be migrated in subsequent PRs:

  • Package.json reading (MinimatchCache and related)
  • File discovery caches (closestPatternCache, patternInParentsCache)
  • Unified invalidation logic across all caches

🤖 Generated with Claude Code

Introduce a new FsCache singleton in shared package that consolidates
file system caching across the codebase. This is the first step toward
unifying all FS-related caches into a single source of truth.

Changes:
- Create FsCache class with file content, directory listing, and path
  type caching
- Migrate sourceFileContentCache to use FsCache for file contents while
  keeping parsedSourceFileCache (ASTs) separate
- Migrate tsconfigContentCache to use FsCache, with separate tracking
  for missing-but-fallback tsconfig files
- Update IncrementalCompilerHost to use FsCache and track known content
  per host instance for proper change detection
- Update tests to reflect the new unified caching approach

The FsCache provides:
- Centralized file content caching with BOM stripping
- Directory listing caching
- File existence checking with caching
- Invalidation APIs for fsEvents and baseDir changes
- Preloading API for HTTP request data

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@hashicorp-vault-sonar-prod hashicorp-vault-sonar-prod bot changed the title Add centralized FsCache layer for file system operations JS-984 Add centralized FsCache layer for file system operations Dec 8, 2025
@hashicorp-vault-sonar-prod
Copy link

hashicorp-vault-sonar-prod bot commented Dec 8, 2025

JS-984

@vdiez vdiez changed the base branch from master to typescript-program-caching December 8, 2025 14:06
@vdiez vdiez force-pushed the typescript-program-caching branch from 88dcae3 to 3d797a0 Compare December 8, 2025 14:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant