"build.json" build_cache.ts
Declarations #
12 declarations
BUILD_CACHE_METADATA_FILENAME #
BUILD_CACHE_VERSION #
"1" BuildCacheMetadata #
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 #
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_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'])
string[]returns
Promise<{ path: string; hash: string; size: number; mtime: number; ctime: number; mode: number; }[]> compute_build_cache_key #
(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
Loggergit_commit?
Optional pre-computed git commit hash (optimization to avoid re-reading)
string | null | undefinedreturns
Promise<{ git_commit: string | null; build_cache_config_hash: string; }> create_build_cache_metadata #
(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
Loggergit_commit?
Optional pre-computed git commit hash (optimization)
string | null | undefinedbuild_dirs?
Optional pre-discovered build directories (optimization to avoid redundant filesystem scans)
string[] | undefinedreturns
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 #
(): 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 #
(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
Loggergit_commit?
Optional pre-computed git commit hash (optimization)
string | null | undefinedreturns
Promise<boolean> load_build_cache_metadata #
(): 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 #
(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
{ 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 | undefinedreturns
Promise<void> validate_build_cache #
(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
{ 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>