fix: ship .d.mts and .d.cts for dual ESM/CJS TypeScript consumers - #15
Merged
Conversation
Copy whatever .d.ts vite-plugin-dts actually rolled up instead of hardcoding the entry name, resolve dist relative to the config file rather than process.cwd(), and fail the build explicitly if no declaration was emitted. Keeps both package hooks identical and survives an entry rename without silently shipping broken exports.
Add attw --pack for both packages as a root check:exports script and run it in CI after the build, so an exports/declaration mismatch like the TS1479 regression fails the pipeline instead of surfacing in consumers. Verified the check fails when the require condition points back at the ESM-flavoured .d.ts.
Member
|
Reviewed and verified this end to end, then pushed two follow-up commits. Verification, independent of the PR description:
Pushed:
All 424 tests, lint, and format checks still pass after both commits. |
Merged
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.
fix: ship .d.mts and .d.cts for dual ESM/CJS TypeScript consumers
Base:
main. Patch release4.2.1for both packages.Problem
Both packages set
"type": "module"and publish dual.mjs/.cjsbuilds, but ship a single.d.tsthat theimportandrequireexport conditions both point at. UndermoduleResolution: "Node16", TypeScript reads that lone declaration as ESM-only, so any consumer emittingrequire()calls fails:Runtime
require()of the.cjsbuild already works, and so do Jest suites that skip the CJS emit. This is purely a type declaration packaging gap, and any CJS plus Node16 consumer hits it.Reported by MetaMask in MetaMask/core#8497, where it blocks their migration off the unmaintained SpruceID packages. The same failure reproduces on a clean
mainin MetaMask/core#10049, so it is not specific to that branch.Fix
Emit
.d.mtsand.d.ctsalongside the existing.d.ts, and point each export condition at the declaration whose module format matches the JavaScript it describes.The rolled-up declaration is copied in
vite-plugin-dts'safterBuildhook, which runs once, after the files are on disk. Copying verbatim is safe here: both public surfaces use named exports rather thanexport =, and neither declaration contains relative imports.Both packages need the change.
controller-utilsandprofile-sync-controllerare separate consumer entry points, andsiwe.d.ctsitself imports@signinwithethereum/siwe-parserunder therequirecondition, so fixing only one leaves the other broken.Root
"types"is unchanged as a node10 fallback.Verification
Reproduced against published 4.2.0, then confirmed fixed, in the MetaMask/core repro:
controller-utilssrc/siwe.ts:2:31profile-sync-controllerflow-siwe.ts:1:29For
profile-sync-controllerthe full error sets before and after are identical except that single TS1479. The other errors in that clone are pre-existing unbuilt project reference noise, unrelated to this change.Also checked:
module: Node16fails on both imports against published 4.2.0 and type checks cleanly against this build, so the test genuinely detects the bug.exportsrewrite.arethetypeswrongreports no problems across node10, node16 from CJS, node16 from ESM, and bundler for both packages. Run manually against the packed tarballs rather than wired into CI, to keep this change small..mjs,.cjs,.d.ts,.d.mts, and.d.ctsfor both packages on the first run.Release notes
Patch
4.2.1. No API, parsing, or verification behaviour changes. MetaMask already depends on^4.2.0, so they pick this up with a lockfile refresh and no manifest edit.