Skip to content

Publish native ESM alongside CommonJS - #456

Draft
robgruen wants to merge 2 commits into
mainfrom
dev/robgruen/dual-module-publishing
Draft

robgruen wants to merge 2 commits into
mainfrom
dev/robgruen/dual-module-publishing

Conversation

@robgruen

Copy link
Copy Markdown
Contributor

Summary

Closes #120.

  • Publish native ESM JavaScript and declarations in dist/esm alongside the existing CommonJS output in dist.
  • Add conditional import/require exports and format-specific declarations for typechat, typechat/ts, typechat/zod, and typechat/interactive.
  • Use explicit .js relative imports and compiler imports that work in both module formats.
  • Build the library before workspace examples, document both consumption styles, and run the test suite in Node.js CI.

Compatibility

  • Preserve existing CommonJS output paths and public APIs.
  • Keep the ES2021 JavaScript target and existing Node.js >=22.19.0 requirement unchanged.
  • Add no dependencies.

Validation

Validated on Node.js 22.19.0:

  • npm test: 145 tests passed, including new package compatibility checks.
  • Clean dependency restoration and npm run build-all: all workspace examples built.
  • Actual npm tarball: all four entry points loaded with both native import and CommonJS require.
  • ESM/CommonJS named export parity and behavior checks for translation, TypeScript/Zod validation, programs, and interactive input.
  • Format-specific declaration resolution under both node16 and nodenext, including negative type checks.
  • Core and interactive entry points load without optional peer dependencies.

Add conditional exports and format-specific declarations for every public entry point, preserving existing CommonJS paths and the ES2021 target. Include package compatibility tests, documentation, and CI validation.

Closes #120.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@robgruen
robgruen marked this pull request as draft October 13, 2026 15:31
Retain typed default exports for all four ESM entry points without changing the CommonJS export shape. Add runtime and declaration regression coverage and document compatibility.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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.

Distribute as ESM

1 participant