Skip to content

fix: publish correct esm and cjs type declarations#224

Merged
MylesBorins merged 1 commit into
mainfrom
fix/types-publish-layout
May 21, 2026
Merged

fix: publish correct esm and cjs type declarations#224
MylesBorins merged 1 commit into
mainfrom
fix/types-publish-layout

Conversation

@MylesBorins
Copy link
Copy Markdown
Owner

@MylesBorins MylesBorins commented May 21, 2026

Summary

fixes: #220

This fixes the package’s published type layout for dual ESM/CommonJS consumers.

Previously, the package only published a single ESM-flavored declaration entry, which could lead to incorrect or incomplete type resolution for CommonJS consumers and was flagged by external tooling.

What changed

  • Generate ESM declarations from lib/ into types/
  • Generate CommonJS declarations from the Rollup CJS build in dist/lib/ into dist/types/
  • Update package.json conditional exports so:
    • import resolves to types/index.d.mts
    • require resolves to dist/types/index.d.ts
  • Update type fixtures/tests to validate both ESM and CJS consumers
  • Document the type generation and publish layout in README.md and AGENTS.md
  • Add a files whitelist so npm only publishes the runtime, declarations, docs, and examples

Why

This package ships separate ESM and CommonJS runtime entry points, so the published type metadata should match that layout as well. Generating CJS declarations from the Rollup-produced CJS tree keeps the declaration output aligned with the actual CommonJS runtime shape while avoiding hand-maintained type wrappers.

Validation

  • npm test
  • npm pack --dry-run
  • Installed the packed tarball into a fresh consumer project and verified:
    • ESM runtime import works
    • CJS runtime require works
    • ESM TypeScript resolution works
    • CJS TypeScript resolution works

Notes

This keeps JSDoc in the ESM source as the single source of truth. The CJS declarations are generated from the built CommonJS output rather than maintained separately by hand.

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 0600c6e8b8

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread test/fixtures/types/test-cjs-types.ts Outdated
@MylesBorins MylesBorins force-pushed the fix/types-publish-layout branch from 0600c6e to 2a4dbd5 Compare May 21, 2026 03:40
Fix the published type layout for dual ESM/CommonJS consumers.

Generate ESM declarations from lib/ into types/ and generate CommonJS
declarations from the Rollup CJS output in dist/lib/ into dist/types/.
Update package exports so import resolves to types/index.d.mts and
require resolves to dist/types/index.d.ts.

Also update the type fixtures to validate both module systems, document
the type generation and publish layout in README.md and AGENTS.md, and
add a files whitelist so npm only publishes the runtime, declarations,
docs, and examples.
@MylesBorins MylesBorins force-pushed the fix/types-publish-layout branch from 2a4dbd5 to 2fa9f8a Compare May 21, 2026 03:44
@MylesBorins MylesBorins merged commit cf3e92a into main May 21, 2026
15 checks passed
@MylesBorins MylesBorins deleted the fix/types-publish-layout branch May 21, 2026 03:46
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.

issue with types resolution on npmjs.com

1 participant