Repository navigation
fix(types): resolve the package under nodenext for both ESM and CJS - #296
Open
nikolas-sapa wants to merge 1 commit into
Open
nikolas-sapa wants to merge 1 commit into
nikolas-sapa wants to merge 1 commit into
Conversation
Bundle the emitted declarations into one self-contained index.d.ts so nothing references sibling files without an extension, and give each exports condition its own types file: index.d.ts next to index.js for import, index.d.cts next to index.cjs for require. api-extractor needs a JS TypeScript compiler to follow lib symbols, so it is pointed at @typescript/old; the typescript package here is the native port and ships no lib files it can read. Fixes mbret#271
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.
Fixes #271
What was wrong
Under
moduleResolution: "nodenext"(ornode16) the package's types were unusable:dist/index.d.tsre-exported through extensionless paths and directories (export * from './lib/binding/useObserve'), which nodenext refuses to follow, so every export looked missing (TS2305).requirecondition points at./dist/index.cjs, so TypeScript looks for./dist/index.d.cts. There was none, and withexportspresent the top-leveltypesfield is not read (TS7016).Fix
dist/index.d.tswith no relative imports, viavite-plugin-dts'sbundleTypes(api-extractor under the hood).exportscondition gets its owntypes:index.d.tsforimport,index.d.ctsforrequire(emitted by copying the bundled declarations in a smallcloseBundlestep — the file has no relative imports, so the copy is valid for both).@microsoft/api-extractoris added as a dev dependency. ItstypescriptCompilerFolderis pointed at@typescript/old(the JS compiler, already pulled in by@typescript/typescript6) because thetypescriptpackage here is the native port and ships nolib.*.d.tsfiles api-extractor can follow — without this it fails withUnable to follow symbol for "Promise".A side effect of bundling:
npm packnow ships 8 files instead of 113 — the test/playground declarations from #283 (main.d.ts,tests/,*.test.d.ts) are gone.Verified
npm run check,npm run build,npm run test:ci(318 tests) — all green.{ module: "nodenext", moduleResolution: "nodenext", strict: true, noEmit: true }:import { useObserve } from "reactjrx"now compiles from bothesm.mtsandcjs.cts(previouslyTS2305/TS7016+TS2834, reproduced against the pre-fix build).moduleResolution: "bundler"consumers unaffected — still resolves.npx @arethetypeswrong/cli --pack .reports no problems for node10, node16 CJS, node16 ESM, and bundler.Nothing breaks: deep
reactjrx/dist/*imports were already unreachable through theexportsmap.