import type { Plugin, Rolldown } from 'vite'; import type { RuntimeModulesContract } from '../mini-contract.ts'; import { isMiniPolyfillModule, type MiniChunkKind, type MiniModuleClassifier } from '../module/module.ts'; import { type GeneratedSubpackage, type PackageLocation } from './placement.ts'; export type { GeneratedSubpackage, Placement } from './placement.ts'; /** Placement services consumed by the later Mini Program rendering and output hooks. */ export type MiniPlacementPlugin = Plugin & Readonly<{ classifyChunk(chunk: Rolldown.PreRenderedChunk | Rolldown.RenderedChunk): MiniChunkKind; getPackageLocation(chunk: Rolldown.RenderedChunk | Rolldown.OutputChunk): PackageLocation; getPhysicalChunkId(chunk: Rolldown.RenderedChunk | string): string; getSubpackages(): readonly GeneratedSubpackage[]; }>; /** * Rolldown options owned by Mini Program placement. Every field enforces a distinct output invariant. The plugin returns this object * from its config hook, while direct Rolldown integration tests reuse the same value to exercise the identical lifecycle. */ export declare function createPlacementRolldownOptions(classifyChunk: MiniModuleClassifier): { /** * Rolldown owns shared chunk names and collision handling. LTHP adds physical package prefixes * to those names later without copying or replacing the chunks. */ output: { /** * React and Taro form one stable framework boundary shared by the App and every Page capsule. Keeping their framework * dependencies together prevents application edits from invalidating framework chunk identity and makes later * development generations eligible to reuse the unchanged vendor. Application code and other dependencies * use Rolldown's automatic chunking without source-path groups or a blanket external vendor group. */ codeSplitting: { groups: { name: string; test: typeof isMiniPolyfillModule; priority: number; includeDependenciesRecursively: boolean; }[]; }; /** Native shells retain their public routes; capsules live beside them and shared runtime entries live in common/. */ entryFileNames(chunk: Rolldown.PreRenderedChunk): string; /** * Leaves chunk identity and collision handling entirely to Rolldown. This package-neutral physical pattern deliberately * contains no LTHP owner; generateBundle adds only the selected package root to the existing Rolldown filename. */ chunkFileNames: string; }; /** * Keeps every native entry's required exports while allowing Rolldown to add cross-chunk bindings created by natural code * splitting. `strict` can reject those extensions; `exports-only` can merge away native boundaries; `allow-extension` * preserves the shell/capsule contract without forcing source-module placement groups. */ preserveEntrySignatures: 'allow-extension'; }; /** * Creates the Mini Program placement lifecycle owner: * * 1. Its config hook installs package-neutral Rolldown names and entry-signature semantics. * 2. `renderStart` atomically starts a generation in `awaiting-chunks`; no stale placement remains reachable. * 3. Its first pre-order `renderChunk` creates one immutable LTHP placement from the complete tree-shaken graph. * 4. `vpt:mini` asks this plugin only for package ownership and physical relocation. * 5. Its pre-order `generateBundle` assigns each OutputChunk its package-qualified filename and publishes app.json declarations. * * The discriminated state is the only generation-local mutation: `idle → awaiting-chunks → planned → finalized`. Each hook * performs one whole-state transition, so stale graph state, duplicate planning, and partially reset generations are * unrepresentable. */ export declare function createMiniPlacementPlugin(modules: RuntimeModulesContract): MiniPlacementPlugin;