/** * Cloudflare Workers bundler implementation using esbuild-wasm. * * This bundler is designed for Cloudflare Workers/Durable Objects where: * - WASM must be imported statically (wrangler bundles it) * - Dynamic imports from CDN are not supported * - The WASM module is provided by the user at initialization * * @example * ```ts * import "sandlot/workers/polyfill"; // Must be first! * import { WorkersBundler } from "sandlot/workers"; * import * as esbuild from "esbuild-wasm"; * import esbuildWasm from "esbuild-wasm/esbuild.wasm"; * * const bundler = new WorkersBundler({ * esbuild, * wasmModule: esbuildWasm, * }); * await bundler.initialize(); * ``` */ import type { IBundler, BundleOptions, BundleResult } from "../types"; import { type EsbuildInstance } from "../core/bundler-utils"; /** * Minimal esbuild module interface needed for Workers. * This matches the shape of `import * as esbuild from "esbuild-wasm"`. */ export interface EsbuildModule extends EsbuildInstance { initialize(options: { wasmModule: WebAssembly.Module; worker?: boolean; }): Promise; stop(): Promise; } export interface WorkersBundlerOptions { /** * The esbuild-wasm module. * Import it with: `import * as esbuild from "esbuild-wasm";` */ esbuild: EsbuildModule; /** * The pre-compiled WebAssembly.Module for esbuild. * Import it with: `import esbuildWasm from "esbuild-wasm/esbuild.wasm";` * * Wrangler handles .wasm imports natively in ES modules. */ wasmModule: WebAssembly.Module; /** * Base URL for CDN imports. * npm imports like "lodash" are rewritten to "{cdnBaseUrl}/lodash@{version}". * @default "https://esm.sh" */ cdnBaseUrl?: string; } /** * Bundler implementation for Cloudflare Workers using esbuild-wasm. * * Unlike browser/node bundlers, this requires: * 1. Static import of esbuild-wasm module * 2. Static import of the WASM binary * 3. Both passed to the constructor * * This is necessary because Workers require WASM to be imported statically * so wrangler can bundle it with the worker. * * @example * ```ts * import "sandlot/workers/polyfill"; * import { WorkersBundler } from "sandlot/workers"; * import * as esbuild from "esbuild-wasm"; * import esbuildWasm from "esbuild-wasm/esbuild.wasm"; * * const bundler = new WorkersBundler({ * esbuild, * wasmModule: esbuildWasm, * }); * * // Initialize must be called before bundling * await bundler.initialize(); * * const result = await bundler.bundle({ * fs: myFilesystem, * entryPoint: "/src/index.ts", * }); * ``` */ export declare class WorkersBundler implements IBundler { private esbuild; private wasmModule; private cdnBaseUrl; private initialized; constructor(options: WorkersBundlerOptions); /** * Initialize the esbuild WASM module. * Must be called before bundle(). * * In Durable Objects, call this in constructor with blockConcurrencyWhile: * ```ts * constructor(ctx, env) { * super(ctx, env); * ctx.blockConcurrencyWhile(async () => { * await this.bundler.initialize(); * }); * } * ``` */ initialize(): Promise; /** * Dispose of the esbuild WASM service. * Call this when you're done with the bundler to free resources. */ dispose(): Promise; bundle(options: BundleOptions): Promise; } //# sourceMappingURL=bundler.d.ts.map