import MagicString from 'magic-string'; import type { ResolvedSite } from './resolve-schema.js'; export interface GenerateSourceInput { source: string; resolved: ResolvedSite[]; /** * Optional diagnostic callback. Called with an error message (never * an Error object) when an internal invariant is violated — e.g., the * insertion-point scanner's Babel re-parse fails even though scanJsx * already parsed the same source successfully. Wired to the plugin's * logger at the call site so these land in the buildEnd summary * instead of being lost. */ onWarn?: (message: string) => void; } export interface GenerateSourceOutput { /** The transformed source (or the original, if there was nothing to do). */ code: string; /** Hi-res sourcemap from magic-string, suitable for Vite. */ map: ReturnType; /** Number of sites actually rewritten (== `resolved.length`). */ rewritten: number; } export declare function generateSource(input: GenerateSourceInput): GenerateSourceOutput; /** * Find the byte offset at which to insert generated imports. The target * is "immediately after the last thing that must come first": the file's * shebang, its leading string directives (`'use client'`, `'use strict'`), * and any existing top-level `import` statements. If none of those exist, * the result is byte 0 (the file starts with user code and the generated * imports go at the very top). * * Uses Babel's parser — the same dependency scan-jsx and resolve-schema * already rely on — so directive detection, multi-line imports, * TypeScript-specific forms (`import type`), side-effect-only imports, * BOM handling, and escape sequences inside string literals are all * handled by the production-grade parser instead of a hand-rolled * textual walker. * * On parse failure (e.g. the user is mid-save with broken syntax) we * warn via `onWarn` and return 0. This is defense-in-depth: `scanJsx`'s * upstream parse normally filters broken sources before this code runs, * but a future Babel plugin-flag drift between the two parsers could * make them disagree, and silent corruption is worse than a warn line. * * `onWarn` MUST NOT throw — exceptions in the callback would kill the * transform and turn a recoverable warning into a hard build failure. * Any throw is caught and ignored below. */ export declare function findImportInsertionPoint(source: string, onWarn?: (message: string) => void): number; //# sourceMappingURL=generate-source.d.ts.map