build_cache.ts

Declarations
#

12 declarations

view source

BUILD_CACHE_METADATA_FILENAME
#

BUILD_CACHE_VERSION
#

BuildCacheMetadata
#

build_cache.ts view source

ZodObject<{ version: ZodString; git_commit: ZodNullable<ZodString>; build_cache_config_hash: ZodString; timestamp: ZodString; outputs: ZodArray<...>; }, $strict>

Metadata stored in .gro/ directory to track build cache validity. Schema validates structure at load time to catch corrupted cache files.

BuildOutputEntry
#

build_cache.ts view source

ZodObject<{ path: ZodString; hash: ZodString; size: ZodNumber; mtime: ZodNumber; ctime: ZodNumber; mode: ZodNumber; }, $strict>

Metadata about a single build output file. Includes cryptographic hash for validation plus filesystem stats for debugging and optimization.

collect_build_outputs
#

build_cache.ts view source

(build_dirs: string[]): Promise<{ path: string; hash: string; size: number; mtime: number; ctime: number; mode: number; }[]>

Collects information about all files in build output directories. Returns an array of entries with path, hash, size, mtime, ctime, and mode.

Files are hashed in parallel for performance. For very large builds (10k+ files), this may take several seconds but ensures complete cache validation.

build_dirs

Array of output directories to scan (e.g., ['build', 'dist', 'dist_server'])

type string[]

returns

Promise<{ path: string; hash: string; size: number; mtime: number; ctime: number; mode: number; }[]>

compute_build_cache_key
#

build_cache.ts view source

(config: GroConfig, log: Logger, git_commit?: string | null | undefined): Promise<{ git_commit: string | null; build_cache_config_hash: string; }>

Computes the cache key components for a build. This determines whether a cached build can be reused.

config

Gro config (build_cache_config_hash is already computed during config load)

log

Logger

type Logger

git_commit?

Optional pre-computed git commit hash (optimization to avoid re-reading)

type string | null | undefined
optional

returns

Promise<{ git_commit: string | null; build_cache_config_hash: string; }>

create_build_cache_metadata
#

build_cache.ts view source

(config: GroConfig, log: Logger, git_commit?: string | null | undefined, build_dirs?: string[] | undefined): Promise<{ version: string; git_commit: string | null; build_cache_config_hash: string; timestamp: string; outputs: { ...; }[]; }>

Creates build cache metadata after a successful build. Automatically discovers all build output directories (build/, dist/, dist_*).

config

Gro config

log

Logger

type Logger

git_commit?

Optional pre-computed git commit hash (optimization)

type string | null | undefined
optional

build_dirs?

Optional pre-discovered build directories (optimization to avoid redundant filesystem scans)

type string[] | undefined
optional

returns

Promise<{ version: string; git_commit: string | null; build_cache_config_hash: string; timestamp: string; outputs: { path: string; hash: string; size: number; mtime: number; ctime: number; mode: number; }[]; }>

discover_build_output_dirs
#

build_cache.ts view source

(): Promise<string[]>

Discovers all build output directories in the current working directory. Returns an array of directory names that exist: build/, dist/, dist_*

returns

Promise<string[]>

is_build_cache_valid
#

build_cache.ts view source

(config: GroConfig, log: Logger, git_commit?: string | null | undefined): Promise<boolean>

Main function to check if the build cache is valid. Returns true if the cached build can be used, false if a fresh build is needed.

config

Gro config

log

Logger

type Logger

git_commit?

Optional pre-computed git commit hash (optimization)

type string | null | undefined
optional

returns

Promise<boolean>

load_build_cache_metadata
#

build_cache.ts view source

(): Promise<{ version: string; git_commit: string | null; build_cache_config_hash: string; timestamp: string; outputs: { path: string; hash: string; size: number; mtime: number; ctime: number; mode: number; }[]; } | null>

Loads build cache metadata from .gro/ directory. Invalid or corrupted cache files are automatically deleted.

returns

Promise<{ version: string; git_commit: string | null; build_cache_config_hash: string; timestamp: string; outputs: { path: string; hash: string; size: number; mtime: number; ctime: number; mode: number; }[]; } | null>

save_build_cache_metadata
#

build_cache.ts view source

(metadata: { version: string; git_commit: string | null; build_cache_config_hash: string; timestamp: string; outputs: { path: string; hash: string; size: number; mtime: number; ctime: number; mode: number; }[]; }, log?: Logger | undefined): Promise<...>

Saves build cache metadata to .gro/ directory. Errors are logged but don't fail the build (cache is optional).

metadata

type { version: string; git_commit: string | null; build_cache_config_hash: string; timestamp: string; outputs: { path: string; hash: string; size: number; mtime: number; ctime: number; mode: number; }[]; }

log?

type Logger | undefined
optional

returns

Promise<void>

validate_build_cache
#

build_cache.ts view source

(metadata: { version: string; git_commit: string | null; build_cache_config_hash: string; timestamp: string; outputs: { path: string; hash: string; size: number; mtime: number; ctime: number; mode: number; }[]; }): Promise<...>

Validates that a cached build is still valid by checking stats and hashing outputs. Uses size as a fast negative check before expensive hashing. This is comprehensive validation to catch manual tampering or corruption.

metadata

type { version: string; git_commit: string | null; build_cache_config_hash: string; timestamp: string; outputs: { path: string; hash: string; size: number; mtime: number; ctime: number; mode: number; }[]; }

returns

Promise<boolean>

Depends on
#

Imported by
#