Skip to content

fix: preserve ESM in the edge package export - #93

Merged
yokelpole merged 2 commits into
mainfrom
fix/edge-esm-bundle
Oct 15, 2026
Merged

yokelpole merged 2 commits into
mainfrom
fix/edge-esm-bundle

Conversation

@yokelpole

@yokelpole yokelpole commented Oct 15, 2026 •

Copy link
Copy Markdown
Collaborator

Importing @codex-data/sdk/edge in a browser retained GraphQL execution/schema validation and WebSocket server code. Its ESM entry used extensionless internal imports that resolved to CommonJS files. With normal browser resolution, the packed edge bundle measured 280,796 bytes minified.

Build the edge ESM entry as one module, keeping package dependencies external so consumers can tree-shake their ESM exports. The same browser bundle now measures 48,376 bytes, an 83% reduction. This preserves the existing source import conventions.

Add regression tests against a packed SDK archive: enforce a 60 KiB browser budget, reject retained server/generated-operation code, and verify native ESM and CommonJS public imports. pnpm test builds the package first; CI uses that command for both build/type checks and tests.

Validation:

  • pnpm test --runInBand --coverage=false: all 80 tests passed, including socket integration tests and four packed-package checks.
  • Frozen installation, changed-file formatting, and the new test's TypeScript check passed.
  • ESLint: zero errors, 24 pre-existing warnings; the new test has zero warnings.

Bump the package version from 2.4.2 to 2.4.3.

Adversarial consumer review: no actionable findings on the standards or spec axes. Additional checks:

  • Strict TypeScript .mts/.cts consumers under NodeNext and bundler resolution, with skipLibCheck: false.
  • Packed ESM, CommonJS, Webpack, and Vite/Rollup consumers delivered normal and mixed-commitment edge subscriptions over separate authenticated sockets; invalid edge requests rejected before opening a connection. Production browser bundles measured 49,225 bytes (Webpack) and 48,884 bytes (Vite).
  • An independently installed Next.js 16.3.8/Turbopack consumer compiled successfully using the packed SDK 2.4.3.
  • Compared all 36 emitted files against a clean build of main: only edge.mjs differs. CommonJS, declarations, and all other emitted files are byte-for-byte identical.
  • Both GitHub CI runs passed on version-bump commit 9b713da.

Native runtime checks covered Node 20 in CI and Node 24 locally; the declared minimum Node 17.5 was not executed directly.

@yokelpole
yokelpole marked this pull request as ready for review October 15, 2026 18:17
@yokelpole
yokelpole merged commit 33e3aef into main Oct 15, 2026
2 checks passed
@yokelpole
yokelpole deleted the fix/edge-esm-bundle branch October 15, 2026 18:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants