[PR #8458] [MERGED] fix(telemetry): use conditional exports to replace dynamic import hacks #24888

Closed
opened 2026-04-15 22:36:46 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/8458
Author: @himself65
Created: 3/6/2026
Status: Merged
Merged: 3/6/2026
Merged by: @himself65

Base: canaryHead: worktree-telemetry-conditional-exports


📝 Commits (3)

  • e5d56d9 fix(telemetry): use conditional exports to replace dynamic import hacks
  • 0aec8c9 fix bundler
  • 89b0bdf fix(telemetry): remove unused file and export flagged by knip

📊 Changes

6 files changed (+423 additions, -198 deletions)

View changed files

📝 packages/telemetry/package.json (+1 -0)
📝 packages/telemetry/src/detectors/detect-system-info.ts (+17 -119)
packages/telemetry/src/node.ts (+381 -0)
packages/telemetry/src/utils/import-util.ts (+0 -3)
📝 packages/telemetry/src/utils/package-json.ts (+10 -70)
📝 packages/telemetry/tsdown.config.ts (+14 -6)

📄 Description

Summary

  • Adds a "node" conditional export (./dist/node.mjs) with static top-level imports of node:fs, node:fs/promises, node:os, and node:path
  • The default export (./dist/index.mjs) has no node built-in imports, making it safe for edge runtimes and bundlers like bun build --compile
  • Removes the Function("mm", "return import(mm)") pattern from import-util.ts, package-json.ts, and detect-system-info.ts
  • Both entries expose the same createTelemetry API; the node entry includes full filesystem-based detection (package.json reading, system info, docker/WSL detection)

Relates to #8428

Test plan

  • pnpm build in packages/telemetry succeeds and produces dist/node.mjs and dist/index.mjs
  • dist/node.mjs contains static import fs from "node:fs" etc. at the top
  • dist/index.mjs contains no node: imports and no Function( calls
  • pnpm typecheck passes in packages/telemetry
  • Verify bun build --compile no longer fails on @better-auth/telemetry

🔄 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/8458 **Author:** [@himself65](https://github.com/himself65) **Created:** 3/6/2026 **Status:** ✅ Merged **Merged:** 3/6/2026 **Merged by:** [@himself65](https://github.com/himself65) **Base:** `canary` ← **Head:** `worktree-telemetry-conditional-exports` --- ### 📝 Commits (3) - [`e5d56d9`](https://github.com/better-auth/better-auth/commit/e5d56d919a4deeaefc304cb71fa489386a79689e) fix(telemetry): use conditional exports to replace dynamic import hacks - [`0aec8c9`](https://github.com/better-auth/better-auth/commit/0aec8c959df15b6bf3eb7354c792c88179582d7b) fix bundler - [`89b0bdf`](https://github.com/better-auth/better-auth/commit/89b0bdf11a67367a79ebc3dc3ec1d79744056ce8) fix(telemetry): remove unused file and export flagged by knip ### 📊 Changes **6 files changed** (+423 additions, -198 deletions) <details> <summary>View changed files</summary> 📝 `packages/telemetry/package.json` (+1 -0) 📝 `packages/telemetry/src/detectors/detect-system-info.ts` (+17 -119) ➕ `packages/telemetry/src/node.ts` (+381 -0) ➖ `packages/telemetry/src/utils/import-util.ts` (+0 -3) 📝 `packages/telemetry/src/utils/package-json.ts` (+10 -70) 📝 `packages/telemetry/tsdown.config.ts` (+14 -6) </details> ### 📄 Description ## Summary - Adds a `"node"` conditional export (`./dist/node.mjs`) with **static top-level imports** of `node:fs`, `node:fs/promises`, `node:os`, and `node:path` - The default export (`./dist/index.mjs`) has **no node built-in imports**, making it safe for edge runtimes and bundlers like `bun build --compile` - Removes the `Function("mm", "return import(mm)")` pattern from `import-util.ts`, `package-json.ts`, and `detect-system-info.ts` - Both entries expose the same `createTelemetry` API; the node entry includes full filesystem-based detection (package.json reading, system info, docker/WSL detection) Relates to #8428 ## Test plan - [x] `pnpm build` in `packages/telemetry` succeeds and produces `dist/node.mjs` and `dist/index.mjs` - [x] `dist/node.mjs` contains static `import fs from "node:fs"` etc. at the top - [x] `dist/index.mjs` contains no `node:` imports and no `Function(` calls - [x] `pnpm typecheck` passes in `packages/telemetry` - [x] Verify `bun build --compile` no longer fails on `@better-auth/telemetry` --- <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-15 22:36:46 -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#24888