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
#

9 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 @fuz-classes comments, or null if none

type Array<string> | null

diagnostics

Extraction diagnostics, or null if none

type Array<ExtractionDiagnostic> | null

elements

HTML elements found in the file, or null if none

type Array<string> | null

explicit_elements

Elements from @fuz-elements comments, or null if none

type Array<string> | null

explicit_variables

Variables from @fuz-variables comments, or null if none

type Array<string> | null

CSS_CACHE_VERSION
#

css_cache.ts view source

6

CSS cache version. Bump when any of these change: - CachedExtraction schema - extract_css_classes_with_locations() logic or output - ExtractionDiagnostic or SourceLocation structure

v1: Initial version with classes and diagnostics v2: Use null instead of empty arrays, add explicit_classes, elements, css_variables. v3: Add explicit_elements, explicit_variables for @fuz-elements/@fuz-variables comments. v4: Filter incomplete CSS variables in dynamic templates (e.g., var(--prefix_{expr})). v5: Remove css_variables and explicit_variables (now detected via simple regex scan). v6: Re-add explicit_variables for @fuz-variables comments (regex scan misses dynamic templates).

DEFAULT_CACHE_DIR
#

delete_cached_extraction
#

css_cache.ts view source

(deps: CacheDeps, cache_path: string): Promise<void>

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

deps

filesystem deps for dependency injection

cache_path

absolute path to the cache file

type string

returns

Promise<void>

from_cached_extraction
#

css_cache.ts view source

(cached: CachedExtraction): ExtractionData

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

cached

cached extraction data

returns

ExtractionData

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

get_file_cache_path
#

css_cache.ts view source

(file_id: string, cache_dir: string, project_root: string): string

Computes cache path for a file, handling both internal and external paths. Internal files use relative paths mirroring source tree. External files (outside project root) use hashed absolute paths in _external/.

file_id

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

(deps: CacheDeps, 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.

deps

filesystem deps for dependency injection

cache_path

absolute path to the cache file

type string

returns

Promise<CachedExtraction | null>

save_cached_extraction
#

css_cache.ts view source

(deps: CacheDeps, cache_path: string, content_hash: string, extraction: ExtractionData): Promise<void>

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

deps

filesystem deps for dependency injection

cache_path

absolute path to the cache file

type string

content_hash

SHA-256 hash of the source file contents

type string

extraction

extraction data to cache

returns

Promise<void>

Imported by
#