import type { EcoBuildPlugin } from '../build/contracts/build-types.js'; import { type BrowserRuntimeManifest } from '../build/browser/browser-runtime-manifest.js'; import type { EcoPagesAppConfig, IHmrManager } from '../types/internal-types.js'; import type { HmrStrategy } from '../hmr/hmr-strategy.js'; import type { EcoPagesElement } from '../types/public-types.js'; import type { IntegrationRenderer } from '../route-renderer/orchestration/integration-renderer.js'; import { AssetProcessingService } from '../services/assets/asset-processing-service/asset-processing.service.js'; import type { AssetDefinition, ProcessedAsset } from '../services/assets/asset-processing-service/assets.types.js'; import type { StaticExportContext } from '../static-site-generator/static-export-context.js'; import type { RuntimeCapabilityDeclaration } from './runtime-capability.js'; export type { RuntimeCapabilityDeclaration, RuntimeCapabilityTag } from './runtime-capability.js'; export type { EcoBuildLoader, EcoBuildOnLoadArgs, EcoBuildOnLoadResult, EcoBuildOnResolveArgs, EcoBuildOnResolveResult, EcoBuildPlugin, EcoBuildPluginBuilder, } from '../build/contracts/build-types.js'; export type { PageBrowserGraphContribution, PageBrowserGraphContributionContext } from '../types/public-types.js'; export type { StaticExportContext } from '../static-site-generator/static-export-context.js'; export type { HtmlDocumentContribution, HtmlDocumentContributionContext, } from '../route-renderer/orchestration/integration-renderer.js'; /** * Type-erased integration plugin stored in app-level registries. * * Ecopages keeps one heterogeneous integration list, while each plugin and * renderer still owns its framework-specific render payload type internally. */ export type AnyIntegrationPlugin = IntegrationPlugin; export declare const INTEGRATION_PLUGIN_ERRORS: { readonly NOT_INITIALIZED_WITH_APP_CONFIG: "Plugin not initialized with app config"; readonly NOT_INITIALIZED_WITH_ASSET_SERVICE: "Plugin not initialized with asset dependency service"; }; export declare function mergeIntegrationOptions(defaults: TDefaults, overrides: TOverrides): TDefaults & TOverrides; export declare function assertIntegrationInvariant(condition: boolean, message?: string): asserts condition; /** * Base configuration shared by all integration plugins. * * @remarks * Integrations declare their file ownership, optional runtime requirements, and * any global assets or build-time contributions here. Runtime-only side effects * belong in `setup()` rather than the constructor. */ export interface IntegrationPluginConfig { /** * The name of the integration plugin. */ name: string; /** * The extensions that this plugin supports (e.g., ['.kita.js', '.kita.tsx']). */ extensions: string[]; /** * The dependencies that this plugin requires on a global level. * These dependencies will be resolved during the setup process and injected into the global scope of the application. * They are not specific to any particular page or component. */ integrationDependencies?: AssetDefinition[]; /** * Declares runtime-specific requirements that must be satisfied before the * app can start with this integration enabled. */ runtimeCapability?: RuntimeCapabilityDeclaration; /** * JSX import source owned by this integration. * * @remarks * This is primarily used by mixed-JSX flows where host-owned browser bundles * need to preserve the correct JSX runtime for files claimed by the * integration. */ jsxImportSource?: string; } type IntegrationRendererConstructorOptions = { appConfig: EcoPagesAppConfig; assetProcessingService: AssetProcessingService; resolvedIntegrationDependencies: ProcessedAsset[]; rendererModules?: unknown; runtimeOrigin: string; }; type RendererClass = new (options: IntegrationRendererConstructorOptions) => IntegrationRenderer; /** * Base class for framework integrations. * * @remarks * An integration owns three main concerns: * - which file extensions it claims * - which renderer class turns those files into HTML * - which build-time or runtime contributions must be registered for that framework * * Core owns lifecycle ordering. Integrations declare contributions through the * hooks on this class, while `ConfigBuilder.build()` and app startup decide when * those hooks run. Build plugins map to {@link AppBuildManifest} buckets: * `plugins` → `runtimePlugins`, `browserBuildPlugins` → `browserBundlePlugins`, * `browserRuntimeManifest` → client import rewrite map. For page-browser and * document shaping, integrations should prefer the contribution contracts * re-exported from this module: * `PageBrowserGraphContribution` / `PageBrowserGraphContributionContext` and * `HtmlDocumentContribution` / `HtmlDocumentContributionContext`. */ export declare abstract class IntegrationPlugin { readonly name: string; readonly extensions: string[]; abstract renderer: RendererClass; readonly runtimeCapability?: RuntimeCapabilityDeclaration; readonly jsxImportSource?: string; protected integrationDependencies: AssetDefinition[]; protected resolvedIntegrationDependencies: ProcessedAsset[]; protected options?: Record; protected appConfig?: EcoPagesAppConfig; protected assetProcessingService?: AssetProcessingService; protected hmrManager?: IHmrManager; runtimeOrigin: string; /** * Returns build plugins shared by server-oriented and browser-oriented builds. * * @remarks * Collected into {@link AppBuildManifest.runtimePlugins} during config finalization. * MDX loaders, virtual-module resolvers, and other transforms that must run during * route-module transpile belong here—not in {@link browserBuildPlugins}. */ get plugins(): EcoBuildPlugin[]; /** * Returns build plugins that should only apply to browser-oriented bundles. * * @remarks * Browser-only transforms such as runtime import aliasing belong here so they * do not affect server bundles or static-page module generation. */ get browserBuildPlugins(): EcoBuildPlugin[]; /** * Returns shared browser runtime asset declarations owned by this integration. * * @remarks * Core seals these declarations into the app build manifest so app-owned browser * bundle paths can rewrite manifest-owned imports even when a specific build * request does not install an integration-local runtime rewrite plugin. */ get browserRuntimeManifest(): BrowserRuntimeManifest; /** * Creates the integration with static declaration-only configuration. * * @remarks * Constructors are expected to stay side-effect free. Build-manifest * contributions belong in `prepareBuildContributions()` and runtime-only setup * belongs in `setup()`. */ constructor(config: IntegrationPluginConfig); /** * Attaches the finalized app config to the integration. * * Core calls this during config finalization before runtime setup so the * integration can resolve asset paths and other app-owned services later. */ setConfig(appConfig: EcoPagesAppConfig): void; /** * Records the runtime origin used for page-module loading and renderer setup. */ setRuntimeOrigin(runtimeOrigin: string): void; /** * Returns an HMR strategy for this integration, if applicable. * The strategy will be registered with the HmrManager during initialization. * * @returns HmrStrategy instance or undefined if no custom HMR handling needed * * @example * ```typescript * getHmrStrategy(): HmrStrategy { * const context = this.hmrManager!.getDefaultContext(); * return new ReactHmrStrategy({ context, pageMetadataCache, runtimeManifest }); * } * ``` */ getHmrStrategy?(): HmrStrategy | undefined; /** * Attaches the shared HMR manager and registers integration-owned development hooks. * * @remarks * The default implementation registers the optional integration HMR strategy. * Integrations should override this only when they need to extend that shared * behavior rather than replace it. */ setHmrManager(hmrManager: IHmrManager): void; /** * Creates the asset-processing service used for global integration dependencies. */ initializeAssetDefinitionService(): void; /** * Returns processed global assets resolved during `setup()`. */ getResolvedIntegrationDependencies(): ProcessedAsset[]; /** * Creates the shared renderer options owned by core lifecycle setup. */ protected createRendererOptions(options?: { rendererModules?: unknown; }): IntegrationRendererConstructorOptions; /** * Attaches runtime-only services after a renderer instance has been created. */ protected attachRendererRuntimeServices>(renderer: T): T; /** * Instantiates the integration renderer with app-owned services. * * @remarks * Renderers are cheap runtime objects. They receive the finalized app config, * a fresh asset-processing service, integration-global processed assets, and * any renderer module context supplied by the active runtime. */ initializeRenderer(options?: { rendererModules?: unknown; }): IntegrationRenderer; /** * Shapes one dependency batch before core asset processing runs. * * @remarks * Integrations use this to assign grouped-build metadata or other batch-level * policy without teaching core about integration-specific asset graphs. */ prepareAssetDependencies?(dependencies: AssetDefinition[]): AssetDefinition[]; /** * Prepares build-facing contributions before the app build manifest is sealed. * * @remarks * Integrations can override this when runtime or build plugin declarations must * be materialized ahead of runtime startup. Runtime-only side effects stay in * `setup()`. */ prepareBuildContributions(): Promise; /** * Reports whether this integration's build inputs changed since the last * incremental static build. */ didChange(): boolean; /** * Runs integration-specific setup before static page generation begins. * * @remarks * Integrations that need build-scoped SSR preload or worker sessions should * start them here rather than per-page inside the renderer. */ beforeStaticExport?(_context: StaticExportContext): Promise; /** * Releases resources started in {@link beforeStaticExport}. */ afterStaticExport?(_context: StaticExportContext): Promise; /** * Performs runtime-only integration setup after config build has already * sealed manifest contributions. */ setup(): Promise; /** * Releases runtime resources owned by the integration. * * @remarks * Most integrations do not need custom teardown. Override this only for * explicit cleanup such as watchers, compiler handles, or runtime registries * that outlive individual requests. */ teardown(): Promise; }