[PR #8884] [MERGED] perf(build): reduce published package sizes #16524

Closed
opened 2026-04-13 10:33:31 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/8884
Author: @gustavovalverde
Created: 4/1/2026
Status: Merged
Merged: 4/1/2026
Merged by: @gustavovalverde

Base: mainHead: chore/optimize-build-output


📝 Commits (2)

  • 3f74eee perf(build): reduce published package sizes by 59% and fix dependency bundling
  • 18e6964 fix(core): pack dev-source files

📊 Changes

39 files changed (+60 additions, -111 deletions)

View changed files

📝 docs/package.json (+2 -2)
📝 packages/api-key/package.json (+1 -0)
📝 packages/api-key/tsdown.config.ts (+0 -4)
📝 packages/better-auth/package.json (+1 -0)
📝 packages/better-auth/tsdown.config.ts (+0 -1)
📝 packages/cli/tsdown.config.ts (+0 -2)
📝 packages/core/package.json (+3 -1)
📝 packages/core/tsdown.config.ts (+1 -1)
📝 packages/drizzle-adapter/package.json (+1 -0)
📝 packages/drizzle-adapter/tsdown.config.ts (+1 -1)
📝 packages/electron/package.json (+1 -0)
📝 packages/electron/tsdown.config.ts (+0 -8)
📝 packages/expo/package.json (+1 -0)
📝 packages/expo/tsdown.config.ts (+1 -10)
📝 packages/i18n/package.json (+1 -0)
📝 packages/i18n/tsdown.config.ts (+0 -4)
📝 packages/kysely-adapter/package.json (+1 -0)
📝 packages/kysely-adapter/tsdown.config.ts (+1 -1)
📝 packages/memory-adapter/package.json (+1 -0)
📝 packages/memory-adapter/tsdown.config.ts (+1 -1)

...and 19 more files

📄 Description

Summary

The main better-auth package went from 740 KB compressed / 4.2 MB unpacked to 327 KB / 2.2 MB, a 56% reduction. @better-auth/core dropped from 1.4 MB to 509 KB (64%). File count across the two packages fell from 1,056 to 648.

Three categories of change, all targeting what consumers download from npm.

Source maps removed from all packages

Every tsdown config had sourcemap: true. The resulting .mjs.map files contained full original TypeScript source in sourcesContent and accounted for 42% of the main package's tarball (2.4 MB of 5.7 MB in dist). No major TypeScript library (Hono, Zod v4, UnJS) ships source maps to npm; several security researchers have flagged published source maps as an unintentional source code leak vector. Removed from all 19 packages.

Dependency bundling fixed, canonical tsdown pattern established

3 packages had real bundling bugs where shared dependencies were inlined instead of externalized:

  • telemetry: @better-auth/utils and @better-fetch/fetch were dependencies (bundled), now peerDependencies (external). Consumers no longer get duplicate copies.
  • scim: @better-auth/utils and better-call moved to peerDependencies.
  • sso: @better-auth/utils removed from dependencies (already a peer), @better-fetch/fetch moved to peerDependencies.

Redundant neverBundle entries (listing packages that are already peerDependencies, which tsdown auto-externalizes) removed from api-key, i18n, passkey, oauth-provider, stripe, electron, and expo. treeshake: true added to 9 library packages that were missing it.

Package metadata improvements

  • sideEffects: false added to all 18 publishable packages, enabling downstream bundlers to tree-shake unused imports.
  • @better-auth/core files field narrowed from ["dist", "src"] to ["dist", "src/utils", "!src/**/*.test.ts"], publishing only the utils source needed for the dev-source wildcard export while excluding test files. Reduces core's tarball from 1.4 MB to 509 KB.

docs/package.json

  • lint:fix script updated to use workspace root biome binary (@biomejs/biome was removed as a direct dependency in #8881).
  • lucide-react bumped from ^0.575.0 to ^1.7.0 to align with the lucide-react@1.7.0 pulled transitively by fumadocs-ui@16.7.9, avoiding duplicate versions in the bundle.

Size comparison

Package Before After
better-auth (compressed) 740 KB 327 KB
better-auth (unpacked) 4.2 MB / 678 files 2.2 MB / 451 files
@better-auth/core (unpacked) 1.4 MB / 378 files 509 KB / 197 files

Verification

  • pnpm build: 20/20 packages pass
  • pnpm typecheck + pnpm typecheck:dist: pass
  • pnpm lint:packages (publint + attw): 39/39 pass
  • Runtime smoke test (importing every package's dist entry point with Node.js): 23/23 pass
  • vitest test suite: identical results to baseline (all failures are pre-existing)

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/better-auth/better-auth/pull/8884 **Author:** [@gustavovalverde](https://github.com/gustavovalverde) **Created:** 4/1/2026 **Status:** ✅ Merged **Merged:** 4/1/2026 **Merged by:** [@gustavovalverde](https://github.com/gustavovalverde) **Base:** `main` ← **Head:** `chore/optimize-build-output` --- ### 📝 Commits (2) - [`3f74eee`](https://github.com/better-auth/better-auth/commit/3f74eee218b7366b3d67862e23c97f3df3beaea1) perf(build): reduce published package sizes by 59% and fix dependency bundling - [`18e6964`](https://github.com/better-auth/better-auth/commit/18e69646d7c59932555043ed2958fe974f65a62a) fix(core): pack dev-source files ### 📊 Changes **39 files changed** (+60 additions, -111 deletions) <details> <summary>View changed files</summary> 📝 `docs/package.json` (+2 -2) 📝 `packages/api-key/package.json` (+1 -0) 📝 `packages/api-key/tsdown.config.ts` (+0 -4) 📝 `packages/better-auth/package.json` (+1 -0) 📝 `packages/better-auth/tsdown.config.ts` (+0 -1) 📝 `packages/cli/tsdown.config.ts` (+0 -2) 📝 `packages/core/package.json` (+3 -1) 📝 `packages/core/tsdown.config.ts` (+1 -1) 📝 `packages/drizzle-adapter/package.json` (+1 -0) 📝 `packages/drizzle-adapter/tsdown.config.ts` (+1 -1) 📝 `packages/electron/package.json` (+1 -0) 📝 `packages/electron/tsdown.config.ts` (+0 -8) 📝 `packages/expo/package.json` (+1 -0) 📝 `packages/expo/tsdown.config.ts` (+1 -10) 📝 `packages/i18n/package.json` (+1 -0) 📝 `packages/i18n/tsdown.config.ts` (+0 -4) 📝 `packages/kysely-adapter/package.json` (+1 -0) 📝 `packages/kysely-adapter/tsdown.config.ts` (+1 -1) 📝 `packages/memory-adapter/package.json` (+1 -0) 📝 `packages/memory-adapter/tsdown.config.ts` (+1 -1) _...and 19 more files_ </details> ### 📄 Description ## Summary The main `better-auth` package went from **740 KB compressed / 4.2 MB unpacked** to **327 KB / 2.2 MB**, a 56% reduction. `@better-auth/core` dropped from 1.4 MB to 509 KB (64%). File count across the two packages fell from 1,056 to 648. Three categories of change, all targeting what consumers download from npm. ### Source maps removed from all packages Every tsdown config had `sourcemap: true`. The resulting `.mjs.map` files contained full original TypeScript source in `sourcesContent` and accounted for 42% of the main package's tarball (2.4 MB of 5.7 MB in dist). No major TypeScript library (Hono, Zod v4, UnJS) ships source maps to npm; several security researchers have flagged published source maps as an unintentional source code leak vector. Removed from all 19 packages. ### Dependency bundling fixed, canonical tsdown pattern established 3 packages had real bundling bugs where shared dependencies were inlined instead of externalized: - **telemetry**: `@better-auth/utils` and `@better-fetch/fetch` were `dependencies` (bundled), now `peerDependencies` (external). Consumers no longer get duplicate copies. - **scim**: `@better-auth/utils` and `better-call` moved to `peerDependencies`. - **sso**: `@better-auth/utils` removed from `dependencies` (already a peer), `@better-fetch/fetch` moved to `peerDependencies`. Redundant `neverBundle` entries (listing packages that are already `peerDependencies`, which tsdown auto-externalizes) removed from api-key, i18n, passkey, oauth-provider, stripe, electron, and expo. `treeshake: true` added to 9 library packages that were missing it. ### Package metadata improvements - `sideEffects: false` added to all 18 publishable packages, enabling downstream bundlers to tree-shake unused imports. - `@better-auth/core` files field narrowed from `["dist", "src"]` to `["dist", "src/utils", "!src/**/*.test.ts"]`, publishing only the utils source needed for the `dev-source` wildcard export while excluding test files. Reduces core's tarball from 1.4 MB to 509 KB. ### docs/package.json - `lint:fix` script updated to use workspace root biome binary (`@biomejs/biome` was removed as a direct dependency in #8881). - `lucide-react` bumped from `^0.575.0` to `^1.7.0` to align with the `lucide-react@1.7.0` pulled transitively by `fumadocs-ui@16.7.9`, avoiding duplicate versions in the bundle. ## Size comparison | Package | Before | After | |---|---|---| | `better-auth` (compressed) | 740 KB | **327 KB** | | `better-auth` (unpacked) | 4.2 MB / 678 files | **2.2 MB / 451 files** | | `@better-auth/core` (unpacked) | 1.4 MB / 378 files | **509 KB / 197 files** | ## Verification - `pnpm build`: 20/20 packages pass - `pnpm typecheck` + `pnpm typecheck:dist`: pass - `pnpm lint:packages` (publint + attw): 39/39 pass - Runtime smoke test (importing every package's dist entry point with Node.js): 23/23 pass - `vitest` test suite: identical results to baseline (all failures are pre-existing) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
GiteaMirror added the pull-request label 2026-04-13 10:33:31 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#16524