Skip to content

Conversation

@tani
Copy link
Contributor

@tani tani commented Aug 14, 2025

This PR restructures the export pattern to enable better tree-shaking by creating dedicated namespace files:

  • Added as/as.ts: Exports type utilities (Optional, Readonly, Unoptional, Unreadonly) as named exports
  • Added is/is.ts: Exports all type predicates (Any, Array, ArrayOf, etc.) as named exports
  • Updated mod.ts: Now exports both namespace (* as is) and individual exports (*) patterns

Benefits

  • Enables tree-shaking when importing specific functions (e.g., import { is } from 'unknownutil')
  • Maintains backward compatibility with existing wildcard imports
  • Reduces bundle size for consumers who only need specific utilities

Test

$ cat test.ts
import { is } from "./mod.ts";

is.Any(1);
$ deno run -A npm:tsdown ./test.ts
ℹ tsdown v0.14.1 powered by rolldown v1.0.0-beta.32
ℹ entry: test.ts
ℹ Build start
ℹ dist/test.mjs  0.42 kB │ gzip: 0.28 kB
ℹ 1 files, total: 0.42 kB
✔ Build complete in 25ms
$ cat tist/test.mjs
//#region ../is/any.ts
/**
* Assume `x is `any` and always return `true` regardless of the type of `x`.
*
* Use {@linkcode [is/unknown].isUnknown|isUnknown} to assume that a value is `unknown`.
*
* import { is } from "@core/unknownutil";
*
* const a = "a";
* if (is.Any(a)) {
*   const _: any = a;
* }
*/
function isAny(_x) {
        return true;
}

//#endregion
//#region test.ts
isAny(1);

//#endregion
export {  };%

@codecov
Copy link

codecov bot commented Aug 14, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.88%. Comparing base (e377132) to head (2ecdb1a).
⚠️ Report is 3 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #136      +/-   ##
==========================================
- Coverage   99.89%   99.88%   -0.01%     
==========================================
  Files          52       54       +2     
  Lines         954      903      -51     
  Branches      120      120              
==========================================
- Hits          953      902      -51     
  Misses          1        1              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@lambdalisue
Copy link
Member

lgtm!

@lambdalisue lambdalisue merged commit 6ad122d into jsr-core:main Aug 14, 2025
5 checks passed
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.

2 participants