Add exports map with ESM-flavoured type declarations for node16/nodenext - #1525
Open
markedwards wants to merge 1 commit into
Open
Add exports map with ESM-flavoured type declarations for node16/nodenext#1525markedwards wants to merge 1 commit into
markedwards wants to merge 1 commit into
Conversation
`moduleResolution: node16`/`nodenext` consumers currently fall back to the CommonJS build and read `dist/index.d.ts` in a CommonJS context, so named imports/types resolve incorrectly. Add an `exports` map with per-condition types and emit a `dist/index.d.mts` (read as ESM) alongside the existing `dist/index.d.ts`. The `.d.mts` is a second output of the existing `rollup-plugin-dts` step — identical bundled declarations, no copy step, no new dependency. Additive: `main`/`module`/`typings` retained; the `require` condition still points at the unchanged `dist/index.d.ts`; `"./*": "./*"` preserves deep imports (e.g. `locales`). Safe as a patch release.
|
@markedwards is attempting to deploy a commit to the Kevin Vandy OSS Team on Vercel. A member of the Team first needs to authorize it. |
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
Under TypeScript's
moduleResolution: node16/nodenext(the modern default for ESM projects),material-react-tableresolves to the wrong type shape.Two things combine:
exportsfield. The package shipsmain(CJS) andmodule(ESM), butnodenextignoresmodule, so it falls back to the CJS build.dist/index.d.ts. Undernode16/nodenext, a.d.tsfile is interpreted as CommonJS when the package has no"type": "module"— regardless of which resolution condition reached it. Sodist/index.d.ts(correct for the ESM build) is read in a CommonJS context and named imports/types resolve incorrectly.Fix
Add an
exportsmap with per-condition types, and emit an ESM-flavoured declaration file so ESM consumers get ESM-interpreted types:dist/index.d.mtsis produced as a second output of the existingrollup-plugin-dtsstep — the same bundled declarations, just written with the.d.mtsextension so it's read as ESM:No source changes, no new dependencies, no copy step — the declaration bundler emits both files in the same pass.
Backwards compatibility
Additive, no breaking change:
main,module,typingsare retained, so legacy resolvers and bundlers behave exactly as before.requirecondition still points at the unchangeddist/index.d.ts, so CommonJS consumers are unaffected."./*": "./*"preserves every existing deep import (e.g.material-react-table/locales/...), so theexportsmap restricts nothing that resolved before.The only change is that
moduleResolution: node16/nodenextconsumers now get correct types. Safe as a patch release.The build was not run in this PR. The resulting artifact shape (
dist/index.d.mts+ theexportsmap) was validated by applying the equivalent change to an installed3.2.1and type-checking a realnodenextconsumer — types resolve correctly. Therollup-plugin-dtschange is a standard second output writing the same bundled declarations to a.d.mts.