export type FatalProcessHandler = "uncaughtException" | "unhandledRejection"; export type FatalProcessListener = (...args: unknown[]) => void; /** * The slice of `process` this needs, so a test can emit a crash without arming * the real handlers and taking the runner down with them. */ export type FatalProcessHost = { off: (event: string, handler: FatalProcessListener) => void; on: (event: string, handler: FatalProcessListener) => void; }; export type FatalErrorMeta = { error: { kind: string; message: string; stack?: string; }; }; export type FatalProcessBarrierHooks = { isNonFatal?: (handler: FatalProcessHandler, reason: unknown) => boolean; /** * Runs after the fatal-exit line is written and before `exit(1)`. The server * path uses this for graceful shutdown. The early/preload path leaves it * unset. */ onFatal?: (handler: FatalProcessHandler, reason: unknown) => void | Promise; }; export type FatalProcessBarrierOptions = FatalProcessBarrierHooks & { exit?: (code: number) => void; isWarm?: boolean; log?: (message: string, meta?: FatalErrorMeta) => void; process?: FatalProcessHost; }; type BarrierState = { fatalHandled: boolean; hooks: { exit: (code: number) => void; isNonFatal?: FatalProcessBarrierHooks["isNonFatal"]; isWarm: boolean; log: (message: string, meta?: FatalErrorMeta) => void; onFatal?: FatalProcessBarrierHooks["onFatal"]; }; off: () => void; }; /** * Armed state lives on `globalThis`, not in a module-level WeakMap: the * packaged CLI loads TWO copies of this file (bin/run.js imports the * node_modules export; createDevServer uses the esbuild-bundled copy). A * per-module map would make the second call register a new listener pair * instead of attaching `isNonFatal` / `onFatal`, and the early copy would * `exit(1)` on recoverable Vite/socket errors before shutdown ran. */ declare global { var __superblocksFatalProcessBarrierArmed: WeakMap | undefined; } /** * Arm process-level crash handlers once per host. A second call on the same * host is a no-op for listeners and updates hooks when the caller supplies them * (preload arms early; `createDevServer` later attaches shutdown). Shared * across the node_modules and esbuild copies of this module. */ export declare function installFatalProcessBarrier(options?: FatalProcessBarrierOptions): () => void; export declare function isFatalProcessHandled(host?: FatalProcessHost): boolean; /** Exit code graceful shutdown should use so a crash is not reported as 0. */ export declare function fatalAwareExitCode(host?: FatalProcessHost): number; /** * Child/warm entry: arm before oclif/`dev()` so a startup crash still writes * `event=dev_server_fatal_exit`. Safe to call again later from createDevServer. */ export declare function installEarlyFatalProcessBarrier(): void; export {}; //# sourceMappingURL=fatal-process-barrier.d.mts.map