mirror of
https://github.com/CopilotKit/CopilotKit.git
synced 2026-09-14 16:26:20 +08:00
84dea7bfbb
`src/polyfills.ts` is five side-effect-only imports. The `sideEffects` globs only matched `./dist/**`, and rolldown matches that field against SOURCE paths while bundling, so every `src/polyfills/*.ts` was declared pure and dropped. Every published version through 1.69.2 shipped a 195-byte barrel installing nothing but streaming fetch, so an app following the documented setup died on its first runtime call with `Property 'ReadableStream' doesn't exist`. `dist/index.mjs` and `dist/headless.mjs` lost the same imports, so the package's advertised auto-install on first import did not happen either. Add matching `./src/**` globs. The barrel goes 195B to 362B with all five imports, and `headless.mjs` now leads with `import "./polyfills.mjs"`. `src/__tests__/polyfills.test.ts` stayed green throughout this, because it imports the source, which is never bundled and so is never tree-shaken. Add `scripts/verify-polyfill-barrel.mjs`, which checks `dist/` instead. It clears the nine globals first (Node ships them natively and Hermes does not, so asserting they are merely "defined" would pass on an empty barrel), then executes the CJS barrel in a child realm and checks the ESM barrel structurally. ESM cannot be executed here: the encoding polyfill takes a named import from CommonJS `text-encoding`, which Metro rewrites to a require() but bare Node ESM rejects. The check runs from `build`, so a dead barrel fails the build rather than reaching npm. Also document the `ReadableStream doesn't exist` symptom in troubleshooting, where only the inverse case (a polyfill *conflict*) was covered before. Verified: reverting the sideEffects change and rebuilding turns the check red in both formats, 5 of 5 groups; restoring it turns it green. A behavioural check on the packed tarball installs all nine globals. 289 vitest + 26 script tests pass. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>