/** * Makes every published entry `.d.ts` self-contained with respect to its `declare global` blocks. * * Why this exists: a declaration bundler (`vite-plugin-dts` with `bundleTypes`, i.e. api-extractor) * copies the global augmentations of the whole source tree into **every** entry it rolls up — a * component module's `declare global { interface HTMLElementTagNameMap { 'u-x': UX } }` lands in * the main entry too — but it only keeps the declarations that entry itself reaches. The merge * body survives while the class it names does not, so a consumer that type-checks libraries * (`skipLibCheck: false`) fails with `TS2304: Cannot find name 'UX'` just for importing the * package. The same happens when the entry has the name only as a value (a React wrapper `const`), * which surfaces as `TS2749`. * * The fix keeps the augmentation (so `document.querySelector('u-x')` stays typed from any entry) * and points each dangling name at the public entry that exports it: * `'u-x': UX` becomes `'u-x': import('/').UX`. A tag whose class no entry * exports is a composed-only internal, so its map value becomes `HTMLElement` — the most specific * public type there is. Any other dangling name is left as it is: guessing would hide a real * export gap, and the published-declaration compile check is what reports it. * * Call it from the declaration plugin's `afterBuild` hook, after the bundled `.d.ts` files exist. */ export declare function fixPublishedDtsGlobals(packageRoot: string): void; interface DeclarationEntry { /** Export key, `.` or `./sub`. */ key: string; /** Built declaration file, relative to the package root. */ file: string; } /** * Entry declaration files from the manifest's `exports`. A local manifest may point at `./src/…` * because the publish workflow rewrites `src/` to `dist/`; the built file is always under `dist/`. */ export declare function declarationEntries(exportsMap: Record): DeclarationEntry[]; /** * `name → specifier` for every type-capable name an entry exports publicly. The main entry wins * when several entries export the same name. */ export declare function indexExportedTypes(packageName: string, entries: { key: string; source: string; }[]): Map; /** Type-capable names a declaration file exports (`export declare class X` · `export { X }` of a declared `X`). */ export declare function exportedTypeNames(source: string): Set; /** Names a declaration file can use as types: its own type declarations and its imports. */ export declare function localTypeNames(source: string): Set; /** * Global type names from the TypeScript `lib.*.d.ts` the package builds with (`HTMLElement`, * `CustomEvent`, `HTMLDivElement` …). These are never dangling, so they are never rewritten — * a tag mapped to a built-in element type keeps that type. */ export declare function libGlobalNames(packageRoot: string): Set; /** * Rewrites the dangling names inside each top-level `declare global { … }` block — and each * augmentation of a bare module specifier, `declare module 'react' { … }` — of one declaration file * (see `fixPublishedDtsGlobals`). Everything outside those blocks is untouched. */ export declare function resolveDanglingGlobals(source: string, exportedFrom: Map, globals?: Set): string; export {};