Skip to content

fix: refactor exports structure in package.json - #117

Merged
shahradelahi merged 5 commits into
shahradelahi:mainfrom
Socialpranker:fix/116-cjs-types
Aug 2, 2026
Merged

shahradelahi merged 5 commits into
shahradelahi:mainfrom
Socialpranker:fix/116-cjs-types

Conversation

@Socialpranker

Copy link
Copy Markdown
Contributor

Closes #116.

dist/index.d.cts is built by tsup on every release, but it never reaches
consumers: files excluded it explicitly, and the exports map carried no
types condition at all. A CommonJS project on moduleResolution: nodenext
therefore resolved to dist/index.cjs with no declarations beside it and
silently typed the whole API as any.

The change is limited to package.json:

  • add types to both export conditions, listed first so it is matched before
    the runtime entry
  • split the ESM/CJS branches into import / require so each points at its
    own declaration file
  • drop "!dist/**/*.d.cts" from files

Verification

@arethetypeswrong/cli --pack ., the tool used in the issue:

before after
node10 🟢 🟢
node16 (from CJS) ❌ No types 🟢 (CJS)
node16 (from ESM) 🟢 (ESM) 🟢 (ESM)
bundler 🟢 🟢

I also packed the tarball and installed it into a scratch CommonJS project
with "module": "nodenext". Before the change tsc --noEmit reported

error TS7016: Could not find a declaration file for module '@litehex/node-vault'.
  '.../dist/index.cjs' implicitly has an 'any' type.

and after it exits 0, with require('@litehex/node-vault') still resolving to
dist/index.cjs at runtime.

pnpm test is 41/41 against a local dev Vault, and typecheck, eslint and
format:check are clean.

The exports map carried no `types` condition, and `index.d.cts` was
excluded from the published files, so a CommonJS consumer on
`moduleResolution: nodenext` resolved to `dist/index.cjs` with no
declarations and fell back to `any` for the whole API.

tsup already emits `dist/index.d.cts`, so this only needs the export
conditions to point at it and the file to ship.
@changeset-bot

changeset-bot Bot commented Aug 1, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 9095cac

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@litehex/node-vault Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@Papaskas

Papaskas commented Aug 2, 2026

Copy link
Copy Markdown

Thanks for the quick turnaround — the split into import/require branches and the before/after attw table are exactly right.

Since the diff matches the "Proposed fix" section of #116, would you be open to adding a co-author trailer to the commit? It would look like this:
Co-authored-by: Papaskas 78373247+Papaskas@users.noreply.github.com

It needs to be the last line of the commit message, separated by a blank line. Entirely up to you — happy either way, and thanks again for picking this up.

@shahradelahi
shahradelahi self-requested a review August 2, 2026 17:08
@shahradelahi shahradelahi changed the title fix: publish CJS type declarations fix: refactor exports structure in package.json Aug 2, 2026
@shahradelahi

Copy link
Copy Markdown
Owner

Contents of dist/index.d.cts and dist/index.d.ts are exactly the same.

@shahradelahi
shahradelahi merged commit 01ae08e into shahradelahi:main Aug 2, 2026
4 checks passed
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.

No types for CommonJS consumers: exports map has no "types" condition and index.d.cts is not published

3 participants