Publish valid ESM types for dual output packages#120
Merged
Conversation
There was a problem hiding this comment.
Pull request overview
This PR updates ts-toolkit’s packaging workflow to publish valid TypeScript declarations for dual ESM/CJS outputs and adds an arethetypeswrong export/types validation step to generated templates and this repo’s build.
Changes:
- Emit conditional
exportsentries with per-conditiontypesfor dual-output packages. - Add a build step to validate published artifacts with
@arethetypeswrong/cli(attw --pack dist), including wiring it into templates and devDependencies. - Add utilities + tests to generate
.d.mts/.d.ctssiblings and rewrite relative specifiers for ESM declaration resolution.
Reviewed changes
Copilot reviewed 5 out of 6 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| src/util/copy-package-json-from-config.ts | Builds new exports shapes and emits dual declaration siblings with ESM-specifier rewriting. |
| src/util/copy-package-json-from-config.spec.ts | Adds tests for conditional exports shapes and declaration emission/rewriting. |
| src/init/check-packages.ts | Ensures @arethetypeswrong/cli is installed in initialized Node projects. |
| src/init/add-scripts.ts | Adds build:* script to run attw against the packed dist output in templates. |
| package.json | Bumps version and adds attw build script + devDependency. |
| package-lock.json | Locks new @arethetypeswrong/cli dependency tree and updates version metadata. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
tristanmenzel
approved these changes
Apr 24, 2026
Contributor
Author
4 tasks
cuzzlor
added a commit
that referenced
this pull request
Apr 28, 2026
* fix(types): rewrite .d.mts relative specifiers to .mjs
`emitDualDeclarations` was producing `.d.mts` files whose relative
specifiers ended in `.js`. Under TS's node16+ ESM resolver, a `.js`
specifier in a `.d.mts` is paired with the adjacent `.d.ts`, which —
in a dual-published package whose root `package.json` has
`"type": "commonjs"` — is treated as CJS-flavoured. Strict ESM
consumers then surface type-resolution errors against an otherwise
valid package.
`rewriteSpecifier` is only ever called for the `.d.mts` branch, so the
extension it emits should be `.mjs`, which pairs with the `.d.mts`
twin and keeps the resolution chain in ESM throughout.
The `.d.cts` branch is unaffected — those remain content-identical
copies of the source `.d.ts`, which CJS resolution handles via
extensionless specifiers.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
* test+docs: cover .mjs rewrite cases and document dual-decl emission
Tests
- Add focused unit test for the file case (was only exercised via the
integration test): `from './foo'` → `from './foo.mjs'` when `./foo.d.ts`
exists.
- Add test for resolving when only the `.d.mts` twin is present alongside
the source, exercising the second branch of `rewriteSpecifier`.
- Add test that runs all three module-specifier shapes through one pass
(`from '...'`, bare `import '...'`, dynamic `import('...')`).
Docs
- Add a `## copy-package-json` subsection covering dual-declaration
emission, the per-condition `exports` shape, and the `.mjs` rewrite
rules with the rationale for `.mjs` over `.js`.
- The original feature (PR #120) shipped without README coverage; this
fills that gap alongside the specifier-extension fix.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
* chore(release): 5.0.0-beta.1
Publishes the .d.mts specifier-extension fix so downstream packages can
drop their local workarounds (e.g. graphql-apollo-server's
build:4a-fix-dmts post-step).
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
* chore(audit): bump postcss to 8.5.10 to fix GHSA-qx2v-qp2m-jg93
Resolves the moderate XSS advisory (PostCSS Stringify Output unescaped
`</style>`) reaching us via vitest > vite > postcss in dev. Within the
existing semver range; no package.json change, lockfile-only.
Surfaced by the PR check on #121.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
* docs+test: cover the .d.mts adjacency case for directory specifiers
Addresses Copilot review comments on #121. `rewriteSpecifier` already
resolves both `.d.ts` and `.d.mts` adjacents in the directory branch,
but the README bullet and the source-comment example only mentioned
`.d.ts`. Updated both to spell out either form.
Also adds a sibling unit test covering the case where only an
`index.d.mts` is present in a directory (matching the existing
"only a .d.mts twin alongside the source" test for the file case).
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
* use interop: 'auto' as default for rollup CJS output
* fix default rollup external function to correctly switch between local and imported module code
---------
Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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
https://arethetypeswrong.github.io/?p=%40makerx%2Fexpress-msal%40%5E2.0.0-beta.0
More details
https://github.com/arethetypeswrong/arethetypeswrong.github.io/blob/main/docs/problems/FalseCJS.md
Solution