UNPKG

process-rerun

Version:

The purpose of this library is - build simple and flexible interface for parallel command execution with rerun (on fail) possibility

39 lines (38 loc) 1.89 kB
type TSharedCache = { [scope: string]: unknown[]; }; type TSharedCacheVia = 'arg' | 'env'; declare const SHARED_CACHE_ENV_VAR = "PROCESS_RERUN_CACHE"; /** * Stores an entity published by a command on its stdout (see `getCache` in ./exec) * into the shared cache, grouped by scope. Every published entity is appended, so a * scope accumulates a list of entities across commands. */ declare function addToSharedCache(cache: TSharedCache, published: { scope: string; data: any; }): void; /** * A command can request entities produced by earlier commands via a * --use-shared-cache={"<scope>": <amount>, ...} * argument, where each key is a cache scope and each number is how many entities * to take from that scope. The requested entities are removed (consumed) from the * shared cache and returned grouped by scope. Returns `undefined` when the command * does not carry the argument. */ declare function collectSharedCache(cache: TSharedCache, cmd: string): TSharedCache | undefined; /** * Resolves the --use-shared-cache argument of a command against the shared cache. * * When entities were gathered they are delivered to the child according to `via`: * - `'arg'` (default): the argument is rewritten in place into --cache='<json>' so the * child reads the entities from its argv; * - `'env'`: the argument is removed and a `PROCESS_RERUN_CACHE='<json>'` assignment is * prepended to the command so the child reads the entities from its environment. * * When nothing could be gathered the --use-shared-cache argument is stripped so the child * never sees it. Commands without the argument are returned unchanged. */ declare function applySharedCache(cache: TSharedCache, cmd: string, via?: TSharedCacheVia): string; export { addToSharedCache, collectSharedCache, applySharedCache, SHARED_CACHE_ENV_VAR }; export type { TSharedCache, TSharedCacheVia };