Repository navigation
fix: emit type declarations for the split browser deflate and inflate entries - #331
Open
abd1rahmane wants to merge 1 commit into
Open
abd1rahmane wants to merge 1 commit into
abd1rahmane wants to merge 1 commit into
Conversation
This branch has not been deployed
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.
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.mtsexited 0 for Z_FILTERED imported from pako/browser/deflate, andnode a.mtsexited 1 with SyntaxError: does not provide an export named 'Z_FILTERED';npx tsc --noEmit --module nodenext --target esnext --strict b.mtsexited 1 with TS7016 for pako/browser/inflate. After the change,npm run buildemitted 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 printing13 5 function function function function function. Full suitenpm test(eslint, build, tsc --noEmit, node --test) exited 0 with 236 tests passing, 0 failing.