fix: resolve CJS type declarations via exports require condition#29
Merged
Conversation
Split the exports["."] entry into import/require condition blocks so require resolves the CommonJS declarations (./dist/index.d.cts) that tsup already emits, instead of the ESM ./dist/index.d.ts. Fixes the "Masquerading as ESM" (FalseESM) finding from @arethetypeswrong/cli for TypeScript consumers using require() under node16/nodenext module resolution. publint and attw --pack are now clean across all resolution modes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Both
publintand@arethetypeswrong/cliflag the package exports:exports["."]had a single"types": "./dist/index.d.ts"(ESM declarations) alongside"require": "./dist/index.cjs". TypeScript consumers using CommonJS undernode16/nodenextmodule resolution got "Masquerading as ESM" (FalseESM) — the types claim ESM but the runtime file is CJS.The build (tsup) already emits
./dist/index.d.cts; it just wasn't wired up.Fix
Split the
exports["."]conditions so each runtime format resolves matching declarations:./package.jsonexport and top-levelmain/module/types(node10 resolution) unchanged. No build changes needed.Also adds a CHANGELOG entry under the unreleased 3.0.5 section.
Verification
npm run build— emitsindex.js,index.cjs,index.d.ts,index.d.ctsnpx publint— All good!npx @arethetypeswrong/cli --pack .— No problems found, all green including node16-from-CJS (previously 🥸 FalseESM)require()andimportload the full API, andtsc --module node16 --moduleResolution node16 --strict --skipLibCheckpasses for both.ctsand.mtsconsumersnpm run ci— typecheck, lint, 358/358 tests passNote (pre-existing, out of scope)
With
skipLibCheck: false, node16 CJS consumers still hit TS1479 insidedist/index.d.ctsbecause it imports types from@opencode-ai/sdk/v2, which is ESM-only upstream (norequirecondition; that's also whyindex.cjsloads it via dynamicimport()at runtime). Invisible to standard configs (skipLibCheck: true) and not fixable in this package's exports.