/** * Unified browser-runtime plugin factory. * * @remarks * Single factory that exposes the union of behaviors for the browser * runtime: * * - `onResolve` for manifest specifiers → mapped public URL, marked external * - `onResolve` for paths starting with `/` whose target is in the manifest's * public path set → marked external * - `onLoad` for JS/TS files → AST-walking import/export rewrite against the * manifest specifier set, with a `code.includes(specifier)` fast path * * The plugin object carries the manifest under `BROWSER_RUNTIME_MANIFEST` so * post-build rewriters can resolve exact and subpath imports without rebuilding * the map by hand. */ import type { EcoBuildPlugin } from '../contracts/build-types.js'; import { type BrowserRuntimeManifest } from './browser-runtime-manifest.js'; /** * Symbol used to attach the browser-runtime manifest to a plugin instance. */ export declare const BROWSER_RUNTIME_MANIFEST: unique symbol; /** * Default name used by `createBrowserRuntimePlugin` when the caller * does not provide one. */ export declare const DEFAULT_BROWSER_RUNTIME_PLUGIN_NAME = "browser-runtime-plugin"; export type CreateBrowserRuntimePluginOptions = { /** Manifest whose specifier → publicPath entries drive the plugin. */ manifest: BrowserRuntimeManifest; /** Stable build plugin name used for deduplication and selective exclusion. */ name?: string; /** * Whether alias `onResolve` results should be marked `external`. * Default `true`. Pass `false` to let the bundler try to bundle the * mapped URL. */ external?: boolean; /** * Enable source-level AST import/export rewrite via the `onLoad` * hook. Default `true`. Set `false` for alias-only consumers * (e.g. `react`/`react-dom` externals in vendor assets). */ rewriteImports?: boolean; /** * Register an `onResolve` for paths starting with `/` whose target * is in the manifest's public path set. Marks them external so the * bundler does not try to resolve them as source modules. Default * `true`. */ matchPublicPaths?: boolean; }; /** * Rewrites static ESM import/export specifiers and string-literal dynamic imports * from manifest-owned runtime specifiers to concrete browser public URLs. * * Exposed for the post-build rewriter and for tests. */ export declare function rewriteBrowserRuntimeImports(code: string, manifest: BrowserRuntimeManifest, filePath?: string): string; export declare function getBrowserRuntimeManifestFromPlugin(plugin: EcoBuildPlugin): BrowserRuntimeManifest | undefined; /** * Returns the exact specifier → publicPath map derived from the plugin manifest. */ export declare function getBrowserRuntimeImportRewriteMap(plugin: EcoBuildPlugin): ReadonlyMap | undefined; export declare function collectBrowserRuntimeManifests(plugins: EcoBuildPlugin[] | undefined): BrowserRuntimeManifest[]; export declare function collectBrowserRuntimeImportRewriteMap(plugins: EcoBuildPlugin[] | undefined): ReadonlyMap; /** * Creates a build plugin that exposes the union of browser-runtime * manifest behaviors (alias resolution, public-path matching, and source * import/export rewrite). See {@link CreateBrowserRuntimePluginOptions} * for per-behavior toggles. * * Returns `null` for an empty manifest so callers can short-circuit * registration without sprinkling `if (plugin)` everywhere. */ export declare function createBrowserRuntimePlugin(options: CreateBrowserRuntimePluginOptions): EcoBuildPlugin | null;