[PR #5423] [MERGED] chore: use TypeScript project references #5998

Closed
opened 2026-03-13 12:44:11 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/5423
Author: @ocavue
Created: 10/20/2025
Status: Merged
Merged: 10/20/2025
Merged by: @himself65

Base: canaryHead: ocavue/typescript-build-canary


📝 Commits (2)

  • d8901a7 chore: use TypeScript project references
  • 30c5586 chore: trigger ci

📊 Changes

23 files changed (+179 additions, -71 deletions)

View changed files

📝 package.json (+1 -1)
📝 packages/better-auth/package.json (+51 -0)
📝 packages/better-auth/tsconfig.json (+9 -4)
📝 packages/better-auth/tsdown.config.ts (+1 -1)
📝 packages/cli/tsconfig.json (+6 -4)
packages/cli/tsconfig.test.json (+0 -15)
📝 packages/core/package.json (+11 -0)
📝 packages/core/tsconfig.json (+2 -5)
📝 packages/core/tsdown.config.ts (+1 -1)
📝 packages/expo/package.json (+2 -0)
📝 packages/expo/tsconfig.json (+6 -4)
📝 packages/expo/tsdown.config.ts (+1 -1)
📝 packages/sso/package.json (+2 -0)
📝 packages/sso/tsconfig.json (+6 -4)
📝 packages/sso/tsdown.config.ts (+1 -1)
📝 packages/stripe/package.json (+2 -0)
📝 packages/stripe/tsconfig.json (+9 -4)
📝 packages/stripe/tsdown.config.ts (+1 -1)
📝 packages/telemetry/package.json (+1 -0)
📝 packages/telemetry/tsconfig.json (+6 -7)

...and 3 more files

📄 Description

Use TypeScript project references in tsconfig files

This ensures that each package won't be rebuild by tsc if it doesn't change.

This aims to fix the OOM issue when using tsdown (see also https://github.com/rolldown/tsdown/issues/545 and https://github.com/better-auth/better-auth/pull/5369)

I wrote a simple bash script test_better_auth_memory.sh to test OOM. It use docker to limit the available memory and keep a clean environment between each test.

bash test_better_auth_memory.sh himself65 himself65/2025/10/16/BUG
======================================
Building better-auth in Docker
Repository: https://github.com/himself65/better-auth
Branch: himself65/2025/10/16/BUG
Memory limit: 1.5g
Node version: 24
======================================
...
@better-auth/telemetry:build: > @better-auth/telemetry@1.4.0-beta.11 build /better-auth/packages/telemetry
@better-auth/telemetry:build: > tsdown
@better-auth/telemetry:build:
@better-auth/telemetry:build: ℹ tsdown v0.15.6 powered by rolldown v1.0.0-beta.43
@better-auth/telemetry:build: ℹ Using tsdown config: /better-auth/packages/telemetry/tsdown.config.ts
@better-auth/telemetry:build: ℹ entry: src/index.ts
@better-auth/telemetry:build: ℹ tsconfig: tsconfig.json
@better-auth/telemetry:build: ℹ Build start
@better-auth/telemetry:build: ℹ [CJS] dist/index.cjs  19.82 kB │ gzip: 5.22 kB
@better-auth/telemetry:build: ℹ [CJS] 1 files, total: 19.82 kB
@better-auth/telemetry:build:
@better-auth/telemetry:build: <--- Last few GCs --->
@better-auth/telemetry:build:
@better-auth/telemetry:build: [425:0xffffac220000]     5966 ms: Mark-Compact 1012.0 (1028.6) -> 1009.3 (1037.6) MB, pooled: 0 MB, 207.00 / 0.00 ms  (average mu = 0.110, current mu = 0.037) allocation failure; scavenge might not succeed
@better-auth/telemetry:build: [425:0xffffac220000]     6222 ms: Mark-Compact (reduce) 1017.4 (1037.6) -> 1014.8 (1028.1) MB, pooled: 0 MB, 199.97 / 0.00 ms  (+ 0.3 ms in 126 steps since start of marking, biggest step 0.1 ms, walltime since start of marking 220 ms) (average mu = 0.166,
@better-auth/telemetry:build: FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory

 ERROR  run failed: command  exited (134)
 ELIFECYCLE  Command failed with exit code 134.
bash test_better_auth_memory.sh ocavue ocavue/typescript-build-canary
======================================
Building better-auth in Docker
Repository: https://github.com/ocavue/better-auth
Branch: ocavue/typescript-build-canary
Memory limit: 1.5g
Node version: 24
======================================
...
>>> Build completed successfully!

======================================
Docker build finished
======================================

Update package.json to use custom export condition

Add a new better-auth-dev-source field in exports. This will ensure that the project references function correctly and that the jump-to-definition feature in IDEs can navigate to the .ts file instead of the .d.ts file.

The name better-auth-dev-source is arbitrary. I just chose one that is very unlikely to conflict with other toolchains.

Before:

https://github.com/user-attachments/assets/7fe32de0-4319-489f-9217-fb267f126ba3

After:

https://github.com/user-attachments/assets/d8c30465-a055-45ab-8bd4-e2a9ecfc3833


🔄 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/5423 **Author:** [@ocavue](https://github.com/ocavue) **Created:** 10/20/2025 **Status:** ✅ Merged **Merged:** 10/20/2025 **Merged by:** [@himself65](https://github.com/himself65) **Base:** `canary` ← **Head:** `ocavue/typescript-build-canary` --- ### 📝 Commits (2) - [`d8901a7`](https://github.com/better-auth/better-auth/commit/d8901a72da4cb592f662d90dda797958cdab5bf5) chore: use TypeScript project references - [`30c5586`](https://github.com/better-auth/better-auth/commit/30c55862e0a5ca7db8510b56aa8f5b765b42649e) chore: trigger ci ### 📊 Changes **23 files changed** (+179 additions, -71 deletions) <details> <summary>View changed files</summary> 📝 `package.json` (+1 -1) 📝 `packages/better-auth/package.json` (+51 -0) 📝 `packages/better-auth/tsconfig.json` (+9 -4) 📝 `packages/better-auth/tsdown.config.ts` (+1 -1) 📝 `packages/cli/tsconfig.json` (+6 -4) ➖ `packages/cli/tsconfig.test.json` (+0 -15) 📝 `packages/core/package.json` (+11 -0) 📝 `packages/core/tsconfig.json` (+2 -5) 📝 `packages/core/tsdown.config.ts` (+1 -1) 📝 `packages/expo/package.json` (+2 -0) 📝 `packages/expo/tsconfig.json` (+6 -4) 📝 `packages/expo/tsdown.config.ts` (+1 -1) 📝 `packages/sso/package.json` (+2 -0) 📝 `packages/sso/tsconfig.json` (+6 -4) 📝 `packages/sso/tsdown.config.ts` (+1 -1) 📝 `packages/stripe/package.json` (+2 -0) 📝 `packages/stripe/tsconfig.json` (+9 -4) 📝 `packages/stripe/tsdown.config.ts` (+1 -1) 📝 `packages/telemetry/package.json` (+1 -0) 📝 `packages/telemetry/tsconfig.json` (+6 -7) _...and 3 more files_ </details> ### 📄 Description ## Use [TypeScript project references](https://www.typescriptlang.org/docs/handbook/project-references.html) in tsconfig files This ensures that each package won't be rebuild by `tsc` if it doesn't change. This aims to fix the OOM issue when using `tsdown` (see also https://github.com/rolldown/tsdown/issues/545 and https://github.com/better-auth/better-auth/pull/5369) I wrote a simple bash script [test_better_auth_memory.sh](https://gist.github.com/ocavue/afc44c04e127ac2a0a121a8e5e350a08#file-test_better_auth_memory-sh) to test OOM. It use docker to limit the available memory and keep a clean environment between each test. ```bash bash test_better_auth_memory.sh himself65 himself65/2025/10/16/BUG ====================================== Building better-auth in Docker Repository: https://github.com/himself65/better-auth Branch: himself65/2025/10/16/BUG Memory limit: 1.5g Node version: 24 ====================================== ... @better-auth/telemetry:build: > @better-auth/telemetry@1.4.0-beta.11 build /better-auth/packages/telemetry @better-auth/telemetry:build: > tsdown @better-auth/telemetry:build: @better-auth/telemetry:build: ℹ tsdown v0.15.6 powered by rolldown v1.0.0-beta.43 @better-auth/telemetry:build: ℹ Using tsdown config: /better-auth/packages/telemetry/tsdown.config.ts @better-auth/telemetry:build: ℹ entry: src/index.ts @better-auth/telemetry:build: ℹ tsconfig: tsconfig.json @better-auth/telemetry:build: ℹ Build start @better-auth/telemetry:build: ℹ [CJS] dist/index.cjs 19.82 kB │ gzip: 5.22 kB @better-auth/telemetry:build: ℹ [CJS] 1 files, total: 19.82 kB @better-auth/telemetry:build: @better-auth/telemetry:build: <--- Last few GCs ---> @better-auth/telemetry:build: @better-auth/telemetry:build: [425:0xffffac220000] 5966 ms: Mark-Compact 1012.0 (1028.6) -> 1009.3 (1037.6) MB, pooled: 0 MB, 207.00 / 0.00 ms (average mu = 0.110, current mu = 0.037) allocation failure; scavenge might not succeed @better-auth/telemetry:build: [425:0xffffac220000] 6222 ms: Mark-Compact (reduce) 1017.4 (1037.6) -> 1014.8 (1028.1) MB, pooled: 0 MB, 199.97 / 0.00 ms (+ 0.3 ms in 126 steps since start of marking, biggest step 0.1 ms, walltime since start of marking 220 ms) (average mu = 0.166, @better-auth/telemetry:build: FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory ERROR run failed: command exited (134)  ELIFECYCLE  Command failed with exit code 134. ``` ```bash bash test_better_auth_memory.sh ocavue ocavue/typescript-build-canary ====================================== Building better-auth in Docker Repository: https://github.com/ocavue/better-auth Branch: ocavue/typescript-build-canary Memory limit: 1.5g Node version: 24 ====================================== ... >>> Build completed successfully! ====================================== Docker build finished ====================================== ``` ## Update `package.json` to use custom export condition Add a new `better-auth-dev-source` field in `exports`. This will ensure that the project references function correctly and that the jump-to-definition feature in IDEs can navigate to the `.ts` file instead of the `.d.ts` file. The name `better-auth-dev-source` is arbitrary. I just chose one that is very unlikely to conflict with other toolchains. **Before:** https://github.com/user-attachments/assets/7fe32de0-4319-489f-9217-fb267f126ba3 **After:** https://github.com/user-attachments/assets/d8c30465-a055-45ab-8bd4-e2a9ecfc3833 --- <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-03-13 12:44:11 -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#5998