import { type RollupBundleLike } from "../module-graph.js"; /** * The Rollup plugin-context slice this uses: `getModuleInfo` for a module's resolved imports, and `error` * to fail the build. Typed structurally so the file needs no `rollup`/`vite` type dependency. */ interface RollupPluginContext { getModuleInfo(id: string): { readonly importedIds?: readonly string[]; readonly dynamicallyImportedIds?: readonly string[]; } | null; /** * Takes an `Error`, never a string. * * Handed a string, rolldown synthesizes its own error type and calls `Error.captureStackTrace` on a * plain object - which Bun rejects with "First argument must be an Error object", and THAT becomes the * build failure. The guard still fires, but its message is replaced by an internal one naming nothing, * so a real client leak reports as a stack-trace complaint. Passing an Error skips that construction * entirely and the message survives. */ error(error: Error): never; } /** The minimal Rollup plugin shape this returns - `generateBundle` bound to the plugin context. */ export interface LeakGuardPlugin { readonly name: string; /** * The finding that failed the build, or `undefined` when the bundle was clean. * * Recorded as well as thrown because the throw does not reliably survive. A plugin error is handed to * the bundler, which builds its own error to report it, and on some Bun + rolldown combinations that * construction itself fails (`Error.captureStackTrace` rejecting a non-Error) - so what surfaces is an * internal complaint naming neither the leaked module nor its import chain. A caller that owns the * build can read this afterwards and raise the real message from its own code, where nothing can * rewrite it. A leak is the one failure that must stay legible: the whole point is naming what * reached the browser. */ leak?: string; generateBundle(this: RollupPluginContext, options: unknown, bundle: RollupBundleLike): void; } /** * A Vite/Rollup plugin that fails the build when server-only code or a `node:` builtin reaches the client * bundle - the same two guards, and the same error messages, as nifra's Bun production build. */ export declare function viteLeakGuard(): LeakGuardPlugin; export {}; //# sourceMappingURL=vite-leak-guard.d.ts.map