mirror of
https://github.com/CopilotKit/CopilotKit.git
synced 2026-09-14 16:26:20 +08:00
2c531ffab9
CR-loop final polish (non-behavioral): - tsdown-exports.test.ts: the "maps over fallback-array targets" case left an unspied console.warn (b.mjs has no adjacent declaration) leaking to stderr. Wrap it in withWarnSpy and assert the warning fired — the declaration-less element is reported, not silently dropped. - tsdown-exports.d.mts / validate-package-exports-types.ts: cross-reference the two hand-mirrored ExportsEntry definitions so they cannot drift silently. No source behavior change; 36 tests pass, validate:exports exits 0. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
31 lines
1.2 KiB
TypeScript
31 lines
1.2 KiB
TypeScript
/**
|
|
* A value in a package.json `exports` map: a target path, `null` (blocks a
|
|
* subpath), a fallback array, or a nested conditions object.
|
|
*
|
|
* Mirror of `ExportsEntry` in `scripts/validate-package-exports-types.ts`;
|
|
* the two are hand-kept in sync (a `.d.mts` declaration and a `.ts` script
|
|
* cannot share one source without coupling the build helper to the validator).
|
|
*/
|
|
export type ExportsEntry =
|
|
| string
|
|
| null
|
|
| ExportsEntry[]
|
|
| { [condition: string]: ExportsEntry };
|
|
|
|
/**
|
|
* Post-process tsdown's generated `exports` map so every condition target
|
|
* (`import`/`require`/…) and bare-string target that points at emitted
|
|
* JavaScript gains a matching `types` condition. See `tsdown-exports.mjs` and
|
|
* CopilotKit issue #3324.
|
|
*
|
|
* `ctx.pkg` is intentionally `unknown` (the runtime reads `pkg.packageJsonPath`):
|
|
* tsdown's public `PackageJson` type omits `packageJsonPath`, and a
|
|
* `{ packageJsonPath?: string }` shape is an all-optional "weak type" that
|
|
* `PackageJson` cannot satisfy — so tightening it breaks `customExports`
|
|
* assignability (check-types) at the call sites. Do not narrow it.
|
|
*/
|
|
export declare function withTypesConditions(
|
|
exports: Record<string, ExportsEntry>,
|
|
ctx: { pkg: unknown },
|
|
): Record<string, ExportsEntry>;
|