import { CodegenMode } from "../core/codegen/context.js"; import { HoistOptions } from "./hoist.js"; import { BuildStats, TransformOptions } from "./types.js"; import { TransformSourceMap } from "./transform.js"; //#region src/unplugin/pool.d.ts /** The subset of TransformOptions that survives structured cloning. */ interface PoolTransformOptions { mode: CodegenMode; runtimeId?: string | undefined; zodCompat?: boolean | undefined; compact?: boolean | undefined; verbose?: boolean | undefined; autoDiscover?: boolean | undefined; hoist?: boolean | HoistOptions | undefined; } /** Main → worker. */ type PoolRequest = { type: "transform"; seq: number; code: string; id: string; options: PoolTransformOptions; } | { type: "invalidate"; seq: number; }; /** * What a worker observed while transforming one file: the output plus the * signals the main thread's disk-cache bookkeeping needs, which arrive as * callbacks in the in-process path and cannot cross a thread boundary. */ interface PoolTransformResult { output: { code: string; map: TransformSourceMap | null; } | null; discoveryRan: boolean; substantialWork: boolean; uncacheable: boolean; stats: BuildStats | null; /** * First-party modules this worker executed since its last report, or `null` * when the worker cannot track them (Bun/Deno native import). */ newModulePaths: string[] | null; } /** Worker → main. */ type PoolResponse = { type: "result"; seq: number; result: PoolTransformResult; } | { type: "error"; seq: number; name: string; message: string; stack?: string | undefined; } | { type: "invalidated"; seq: number; }; /** * Raised when the pool itself failed — a worker that would not spawn, or one * that died mid-task (OOM is the realistic case; each worker holds a full * module graph). Distinct from a transform's own error, which is rethrown with * its original identity, because the caller's response differs: an * infrastructure failure is worth retrying on the bundler thread, a schema * that cannot compile is not. */ declare class PoolUnavailableError extends Error { constructor(message: string, options?: { cause?: unknown; }); } /** * Resolve `parallel` to a worker count. `false`/`undefined` disable the pool. * * `true` leaves one core for the bundler itself — it is still parsing, * resolving and generating chunks while transforms run — and then caps at * {@link MAX_AUTO_WORKERS}. */ declare function resolvePoolSize(parallel: boolean | number | undefined): number; /** Strip the callbacks from TransformOptions; what remains is cloneable. */ declare function poolTransformOptions(options: TransformOptions): PoolTransformOptions; /** Terminate every live transform pool. */ declare function disposeAllPools(): Promise; /** * A lazily grown pool of transform workers. * * Not a general-purpose executor: it knows the transform protocol, and it * knows that a broadcast invalidation has to be ordered ahead of every * subsequent transform on every worker (per-worker message delivery is FIFO, * so posting the broadcast before any later task is sufficient — and the only * ordering guarantee available, since a worker mid-transform cannot be * interrupted). */ declare class TransformPool { private readonly size; private readonly entry; private readonly workers; private readonly queue; /** In-flight requests by seq, so a worker exit can reject exactly its own. */ private readonly inflight; private readonly executedModules; /** A worker reported it cannot track executed modules — the union is unusable. */ private moduleTrackingUnavailable; private seq; private disposed; /** Worker deaths since the last successful result; trips MAX_CONSECUTIVE_FAILURES. */ private consecutiveFailures; /** Set once the breaker trips: every later run() rejects without spawning. */ private brokenPool; private constructor(); /** * Build a pool of `size` workers, or return null when workers are * unavailable in this installation (the entry could not be located). Callers * treat null as "run in-process". */ static create(size: number): TransformPool | null; /** Transform one file on a worker. Rejects with the transform's own error, or PoolUnavailableError. */ run(code: string, id: string, options: PoolTransformOptions): Promise; /** * Drop every worker's executed-module cache, so the next discovery re-runs * changed schema graphs. Mirrors the loader's invalidateModuleCache() for * the in-process path; called from watchChange. * * Fire-and-forget: the broadcast is posted to every live worker before any * later transform can be, and per-worker FIFO delivery does the rest. A * transform ALREADY executing in a worker keeps its pre-change module cache * — the same window the in-process path has, where invalidation lands * between awaits — and the main thread's own result cache is cleared * alongside, so the file is recomputed either way. */ invalidate(): void; /** * Union of the first-party modules every worker has executed, or null when * any worker cannot track them. Synchronous, because DiskCache.flushDeferred * runs from `buildEnd` and from a process 'exit' hook, where only * synchronous work is allowed — which is why workers push deltas rather than * answering a query. */ firstPartyModulePaths(): string[] | null; /** Terminate every worker. Pending and queued tasks reject. */ dispose(): Promise; /** Hand a task to an idle worker, grow the pool, or queue it. */ private dispatch; private send; private spawn; private onMessage; /** * A worker died — OOM while holding a large module graph is the realistic * cause. Its task fails with PoolUnavailableError so the caller can retry * in-process, and the worker is dropped from the pool; the next dispatch * spawns a replacement. */ private onWorkerGone; private drain; private recordModulePaths; } //#endregion export { PoolRequest, PoolResponse, PoolTransformOptions, PoolTransformResult, PoolUnavailableError, TransformPool, disposeAllPools, poolTransformOptions, resolvePoolSize }; //# sourceMappingURL=pool.d.ts.map