/** * @b9g/platform-bun - Bun platform adapter for Shovel * * Provides built-in TypeScript/JSX support and simplified server setup for Bun environments. */ import { type PlatformDefaults, type Handler, type Server, type ServerOptions, type PlatformESBuildConfig, type EntryPoints, ServiceWorkerPool } from "@b9g/platform"; import { type ShovelConfig } from "@b9g/platform/runtime"; export interface BunPlatformOptions { /** Port for development server (default: 7777) */ port?: number; /** Host for development server (default: localhost) */ host?: string; /** Working directory for file resolution */ cwd?: string; /** Number of worker threads (default: 1) */ workers?: number; /** Shovel configuration (caches, directories, etc.) */ config?: ShovelConfig; } /** * Bun ServiceWorkerContainer implementation * Manages ServiceWorker registrations backed by native Web Workers * * Note: In Bun's production model, workers handle their own HTTP servers * via reusePort, so the supervisor doesn't route requests through the pool. * This container is mainly for worker lifecycle management. */ export declare class BunServiceWorkerContainer extends EventTarget implements ServiceWorkerContainer { #private; readonly controller: ServiceWorker | null; oncontrollerchange: ((ev: Event) => unknown) | null; onmessage: ((ev: MessageEvent) => unknown) | null; onmessageerror: ((ev: MessageEvent) => unknown) | null; constructor(platform: BunPlatform); /** * Register a ServiceWorker script * Spawns Web Workers (each with their own HTTP server in production) */ register(scriptURL: string | URL, options?: RegistrationOptions): Promise; /** * Get registration for scope */ getRegistration(scope?: string): Promise; /** * Get all registrations */ getRegistrations(): Promise; /** * Start receiving messages (no-op in server context) */ startMessages(): void; /** * Ready promise - resolves when a registration is active */ get ready(): Promise; /** * Internal: Get worker pool for request handling */ get pool(): ServiceWorkerPool | undefined; /** * Internal: Terminate workers and dispose cache storage */ terminate(): Promise; /** * Internal: Reload workers (for hot reload) */ reloadWorkers(entrypoint: string): Promise; } /** * Bun platform implementation * ServiceWorker entrypoint loader for Bun with native TypeScript/JSX support */ export declare class BunPlatform { #private; readonly name: string; readonly serviceWorker: BunServiceWorkerContainer; constructor(options?: BunPlatformOptions); /** * Get options for testing */ get options(): { port: number; host: string; cwd: string; workers: number; config?: ShovelConfig; }; /** * Create HTTP server using Bun.serve */ createServer(handler: Handler, options?: ServerOptions): Server; /** * Start listening for connections using pool's handlers */ listen(): Promise; /** * Close the server */ close(): Promise; /** * Reload workers for hot reloading (called by CLI) * @param entrypoint - Path to the new entrypoint (hashed filename) */ reloadWorkers(entrypoint: string): Promise; /** * Get entry points for bundling. * * Development mode: * - worker.js: Single worker with HTTP server (develop command manages process) * * Production mode: * - index.js: Supervisor that spawns workers and handles signals * - worker.js: Worker with its own HTTP server (uses reusePort for multi-worker) * * Unlike Node.js, Bun workers each bind their own server with reusePort, * allowing the OS to load-balance across workers without message passing overhead. */ getEntryPoints(userEntryPath: string, mode: "development" | "production"): EntryPoints; /** * Get Bun-specific esbuild configuration * * Note: Bun natively supports import.meta.env, so no define alias is needed. * We use platform: "node" since Bun is Node-compatible for module resolution. */ getESBuildConfig(): PlatformESBuildConfig; /** * Get Bun-specific defaults for config generation * * Provides default directories (server, public, tmp) that work * out of the box for Bun deployments. */ getDefaults(): PlatformDefaults; /** * Dispose of platform resources */ dispose(): Promise; /** * Get the OS temp directory (Bun-specific implementation using node:os) */ tmpdir(): string; } /** * Default export for easy importing */ export default BunPlatform; /** * Platform's default cache implementation. * Re-exported so config can reference: { module: "@b9g/platform-bun", export: "DefaultCache" } */ export { MemoryCache as DefaultCache } from "@b9g/cache/memory";