css_cache.ts

Cache infrastructure for incremental CSS class extraction.

Provides per-file caching with content hash validation to avoid re-extracting classes from unchanged files.

Declarations
#

8 declarations

view source

CachedExtraction
#

css_cache.ts view source

CachedExtraction

Cached extraction result for a single file. Uses null instead of empty arrays to avoid allocation overhead.

v

Cache version - invalidates cache when bumped

type number

content_hash

SHA-256 hash of the source file contents

type string

classes

Classes as [name, locations] tuples, or null if none

type Array<[string, Array<SourceLocation>]> | null

explicit_classes

Classes from

type Array<string> | null

diagnostics

Extraction diagnostics, or null if none

type Array<ExtractionDiagnostic> | null

compute_hash
#

css_cache.ts view source

(content: string): Promise<string>

Computes SHA-256 hash of content using Web Crypto API.

content

type string

returns

Promise<string>

DEFAULT_CACHE_DIR
#

delete_cached_extraction
#

css_cache.ts view source

(cache_path: string): Promise<void>

Deletes a cached extraction file. Silently succeeds if the file doesn't exist.

cache_path

- Absolute path to the cache file

type string

returns

Promise<void>

from_cached_extraction
#

css_cache.ts view source

(cached: CachedExtraction): { classes: Map<string, SourceLocation[]> | null; explicit_classes: Set<string> | null; diagnostics: ExtractionDiagnostic[] | null; }

Converts a cached extraction back to the runtime format. Preserves null semantics (null = empty).

cached

- Cached extraction data

returns

{ classes: Map<string, SourceLocation[]> | null; explicit_classes: Set<string> | null; diagnostics: ExtractionDiagnostic[] | null; }

get_cache_path
#

css_cache.ts view source

(source_path: string, cache_dir: string, project_root: string): string

Computes the cache file path for a source file. Cache structure mirrors source tree: src/lib/Foo.svelte.fuz/cache/css/src/lib/Foo.svelte.json

source_path

- Absolute path to the source file

type string

cache_dir

- Absolute path to the cache directory

type string

project_root

- Normalized project root (must end with /)

type string

returns

string

load_cached_extraction
#

css_cache.ts view source

(cache_path: string): Promise<CachedExtraction | null>

Loads a cached extraction result from disk. Returns null if the cache is missing, corrupted, or has a version mismatch. This makes the cache self-healing: any error triggers re-extraction.

cache_path

- Absolute path to the cache file

type string

returns

Promise<CachedExtraction | null>

save_cached_extraction
#

css_cache.ts view source

(cache_path: string, content_hash: string, classes: Map<string, SourceLocation[]> | null, explicit_classes: Set<string> | null, diagnostics: ExtractionDiagnostic[] | null): Promise<...>

Saves an extraction result to the cache. Uses atomic write (temp file + rename) for crash safety. Converts empty arrays to null to avoid allocation overhead on load.

cache_path

- Absolute path to the cache file

type string

content_hash

- SHA-256 hash of the source file contents

type string

classes

- Extracted classes with their locations, or null if none

type Map<string, SourceLocation[]> | null

explicit_classes

- Classes from

type Set<string> | null

diagnostics

- Extraction diagnostics, or null if none

type ExtractionDiagnostic[] | null

returns

Promise<void>

Imported by
#