import type { EcoBuildPlugin } from '../build/contracts/build-types.js'; import type { EcoPagesAppConfig } from '../types/internal-types.js'; export interface EcoSourceTransformResult { code: string; map?: unknown; } /** * Bundler-neutral source transform registered on {@link EcoPagesAppConfig.sourceTransforms}. * * @remarks * Prefer this shape over a competing {@link EcoBuildPlugin} `onLoad` handler when * the transform only rewrites module source. Browser/HMR builds run source * transforms after first-wins `onLoad` plugins, so metadata injection and similar * passes still run on rewritten output from boundary/runtime plugins. */ export interface EcoSourceTransform { /** Stable transform name. Also used to dedupe loader plugins in browser builds. */ name: string; /** File-path filter tested against {@link normalizeTransformId | normalized ids}. */ filter: RegExp; /** Runs before default transforms, or after them when set to `post`. */ enforce?: 'pre' | 'post'; transform(code: string, id: string): EcoSourceTransformResult | string | undefined; } export interface EcoViteCompatiblePlugin { name: string; enforce?: 'pre' | 'post'; transform(code: string, id: string): EcoSourceTransformResult | string | undefined; } /** * Normalizes bundler module ids so one transform can serve Ecopages loaders, * Vite, and future bundler adapters. */ export declare function normalizeTransformId(id: string): string; /** * Applies one source transform if the normalized id matches its filter. */ export declare function applySourceTransform(transform: EcoSourceTransform, code: string, id: string): EcoSourceTransformResult | string | undefined; /** * Applies app-owned source transforms in deterministic `pre` → default → `post` order. * * @remarks * Used by the Rolldown plugin bridge after `onLoad` plugins produce final module * contents. Transforms that do not match `filter` are skipped; matching transforms * are chained left-to-right on the current source string. * * @param transforms - App-owned transforms, usually from {@link getAppSourceTransforms}. * @param code - Current module source. * @param id - Module id forwarded to each transform after query/hash normalization. * @returns The transformed source, or the original `code` when no transform matches. */ export declare function applySourceTransforms(transforms: readonly EcoSourceTransform[], code: string, id: string): string; /** * Adapts a source transform into the existing Ecopages build-plugin contract. * * @remarks * Server-oriented builds and loader registration still use this adapter. * Browser/HMR builds should register the transform in `appConfig.sourceTransforms` * instead so the Rolldown bridge can run it after competing `onLoad` plugins. */ export declare function createEcoBuildPluginFromSourceTransform(transform: EcoSourceTransform): EcoBuildPlugin; /** * Adapts a source transform into a Vite-compatible plugin object. * * @remarks * This intentionally returns a plain object shape so core does not need a hard * dependency on `vite` just to author transform primitives. */ export declare function createVitePluginFromSourceTransform(transform: EcoSourceTransform): EcoViteCompatiblePlugin; /** * Returns the app-owned source transforms in stable registration order. */ export declare function getAppSourceTransforms(appConfig: EcoPagesAppConfig): EcoSourceTransform[]; /** * Adapts the app-owned source transforms into Vite-compatible plugin objects. */ export declare function createVitePluginsFromAppSourceTransforms(appConfig: EcoPagesAppConfig): EcoViteCompatiblePlugin[];