import { Workspace } from './package-files/workspace.js'; export interface PackageJsonInput { /** * Path used to identify this package.json in the hash. Should be a * forward-slash relative path matching the file's location in the * eventual archive (e.g. "package.json" or "packages/cli/package.json"). */ path: string; raw: Buffer; } export interface LockfileInput { /** * Basename of the lockfile (e.g. "package-lock.json"). */ name: string; /** * Raw 32-byte SHA-256 digest of the lockfile contents. */ hash: Buffer; } export interface NpmrcInput { /** * Forward-slash relative path matching the .npmrc's location in the eventual * archive (e.g. ".npmrc" or "packages/app/.npmrc"). */ path: string; /** * Raw 32-byte SHA-256 digest of the .npmrc contents. */ hash: Buffer; } export interface ComposeCacheHashInput { lockfile?: LockfileInput; packageJsons: PackageJsonInput[]; npmrcs?: NpmrcInput[]; excludedFields: string[]; } /** * Encodes a value as JSON in a way that's stable across runs and machines. * * Differences from {@link JSON.stringify}: * - Object keys are sorted (byte-wise / code-point order) before * serialization. This is the load-bearing difference — without it, two * equivalent package.json files written in different key orders would * produce different hashes. * - HTML-significant characters (`<`, `>`, `&`) are escaped as * `\u003c`/`\u003e`/`\u0026`. * - U+2028 and U+2029 are escaped as `\u2028`/`\u2029`. * - No whitespace between tokens. * - Numbers use {@link String}; floating-point edge cases may differ from * other encoders. Package.json content is effectively never numeric * outside config blobs, so this is negligible in practice. */ export declare function stableJsonEncode(value: unknown): string; /** * Parses a package.json, removes the named top-level fields, and re-encodes * the result via {@link stableJsonEncode}. */ export declare function canonicalizePackageJson(raw: Buffer, excludedFields: string[]): Buffer; /** * Combines a lockfile digest and a set of canonicalized package.json * entries into a single SHA-256 hex digest. * * Each record contributes: * uint64-be(label length) || label bytes || * uint64-be(content length) || content bytes * * Records are written in the following order: * 1. The lockfile record (if present), labeled `lockfile:`, * whose content is the raw 32-byte SHA-256 digest of the lockfile. * 2. One record per package.json sorted byte-wise by path, labeled * `package.json:`, whose content is the canonicalized * package.json bytes. * 3. One record per .npmrc sorted byte-wise by path, labeled * `npmrc:`, whose content is the raw 32-byte SHA-256 * digest of the .npmrc contents. */ export declare function composeCacheHash(input: ComposeCacheHashInput): string; /** * Reads the workspace lockfile, every workspace package.json, and every * workspace `.npmrc` (root + member packages) and returns the inputs needed * by {@link composeCacheHash}. * * Paths are normalized to forward slashes and made relative to the * workspace root so that they match what ends up in the bundle archive. * * `.npmrc` is hashed so that repointing a registry (which need not touch the * lockfile) invalidates the bundle cache. Packages without an `.npmrc` * contribute nothing, so a workspace with no `.npmrc` produces a hash * identical to before this input existed. */ export declare function loadWorkspaceCacheHashInputs(workspace: Workspace): Promise<{ lockfile?: LockfileInput; packageJsons: PackageJsonInput[]; npmrcs: NpmrcInput[]; }>; /** * Convenience wrapper that loads workspace inputs and composes the cache * hash with the standard set of excluded package.json fields. */ export declare function computeWorkspaceCacheHash(workspace: Workspace): Promise;