Skip to content

fix: emit type declarations for the split browser deflate and inflate entries - #331

Open
abd1rahmane wants to merge 1 commit into
nodeca:masterfrom
abd1rahmane:fix/pkgrepro-330
Open

abd1rahmane wants to merge 1 commit into
nodeca:masterfrom
abd1rahmane:fix/pkgrepro-330

Conversation

@abd1rahmane

Copy link
Copy Markdown

The build bundled declarations only from src/index.ts, so the browser subpaths shared one full-surface declaration file. Importing Z_FILTERED from pako/browser/deflate passed the type checker and then failed when Node loaded the module, while pako/browser/inflate had no types condition at all and fell back to implicit any. The declaration build now runs rollup-plugin-dts over each entry and writes dist/pako_deflate.d.ts and dist/pako_inflate.d.ts alongside dist/pako.d.ts, and the exports map points each subpath at its own file.

A consumer on the packed tarball now gets an error for names the entry does not export and resolves the inflate subpath under both nodenext and bundler resolution. Valid imports from either entry still type-check and run unchanged.

Fixes #330

Reproduced against the published tarball before the change: pako@3.0.3. Verification: Before, in a clean consumer on published pako@3.0.3: npx tsc --noEmit --module nodenext --target esnext --strict a.mts exited 0 for Z_FILTERED imported from pako/browser/deflate, and node a.mts exited 1 with SyntaxError: does not provide an export named 'Z_FILTERED'; npx tsc --noEmit --module nodenext --target esnext --strict b.mts exited 1 with TS7016 for pako/browser/inflate. After the change, npm run build emitted dist/pako.d.ts, dist/pako_deflate.d.ts, dist/pako_inflate.d.ts and the same commands against the packed tarball (npm install /tmp/pako-3.0.3.tgz) gave: a.mts exit 1 with TS2459 (Z_FILTERED declares locally but not exported), b.mts exit 0 under both nodenext and esnext/bundler, c.mts (inflate from pako/browser/deflate) exit 1 with TS2305, and a valid-usage file importing deflate/gzip/Deflate from pako/browser/deflate plus inflate/inflateRaw/ungzip/Inflate from pako/browser/inflate type-checked with exit 0 and ran on node with exit 0 printing 13 5 function function function function function. Full suite npm test (eslint, build, tsc --noEmit, node --test) exited 0 with 236 tests passing, 0 failing.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

v3 exports: ./browser/deflate uses full pako.d.ts and ./browser/inflate has no types

1 participant