Skip to content

refactor: replace bun run with tsx/pnpm across scripts and CI#999

Merged
BYK merged 1 commit into
mainfrom
refactor/phase4-tsx
May 21, 2026
Merged

refactor: replace bun run with tsx/pnpm across scripts and CI#999
BYK merged 1 commit into
mainfrom
refactor/phase4-tsx

Conversation

@BYK
Copy link
Copy Markdown
Member

@BYK BYK commented May 21, 2026

Phase 4: Replace bun run with tsx/pnpm run

Part of the Bun → Node.js migration. Removes Bun as the TypeScript runner for scripts and CI, replacing with tsx and pnpm run.

Changes

Script files (14 converted):

  • Replaced Bun.file().text()readFile() from node:fs/promises
  • Replaced Bun.write()writeFile()
  • Replaced Bun.file().exists()access()
  • Replaced Bun.file().json()JSON.parse(readFile())
  • Replaced new Bun.Glob()tinyglobby
  • Updated shebangs: #!/usr/bin/env bun#!/usr/bin/env tsx
  • generate-api-schema.ts: replaced require.resolve("@sentry/api/package.json") with import.meta.resolve + fileURLToPath (avoids ERR_PACKAGE_PATH_NOT_EXPORTED and ERR_AMBIGUOUS_MODULE_SYNTAX)

ESM require shim (script/require-shim.mjs):

  • Source code uses bare require() for lazy loading (circular dep breaking, optional features). This works natively in Bun and CJS bundles, but fails under tsx/Node ESM (since "type": "module" is set).
  • The shim provides globalThis.require via createRequire, anchored at the project root (package.json).
  • All relative require() calls in src/ are behind runtime-only code paths (DB init, telemetry) that do not execute during tsx script runs.

Worker source refactor (src/lib/scan/grep-worker-source.ts):

  • Replaced import ... with { type: "text" } (Bun-specific) with a wrapper module that uses readFileSync at dev time.
  • At build time, esbuild's text-import-plugin intercepts the module and inlines grep-worker.js as a string constant.
  • Removed the now-dead textImportPlugin from vitest.config.ts.

package.json:

  • Added "tsx" script alias: tsx --import ./script/require-shim.mjs
  • All scripts use pnpm tsx (which invokes the alias)
  • Only build/build:all retain bun run (needs Bun.build() compiler)

CI (.github/workflows/ci.yml):

  • Removed setup-bun from all jobs except build-binary
  • All bun runpnpm run in non-build steps

Documentation:

  • Updated README.md, DEVELOPMENT.md, contributing.md to use pnpm run instead of bun run
  • Updated script JSDoc usage examples in bench.ts, bench-sweep.ts
  • Added docs/pnpm-lock.yaml for docs site build (was using bun.lock)

Tests:

  • Fixed bundle.test.ts and library.test.ts E2E tests: spawn("bun", ...)spawn("pnpm", ...)
  • Fixed concurrent-worker.ts shebang and usage comments

Intentionally kept on Bun

  • script/build.ts — uses Bun.build() (compiler) which has no Node equivalent
  • build-binary CI job retains setup-bun

Testing

  • All CI checks pass (lint, typecheck, unit tests, E2E, build binary, build npm, build docs)
  • tsx confirmed working on Node v22 and v24

Copy link
Copy Markdown
Contributor

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 2 potential issues.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 45bbbf6. Configure here.

Comment thread .github/workflows/ci.yml
Comment thread script/generate-api-schema.ts
@BYK BYK force-pushed the refactor/phase4-tsx branch 3 times, most recently from bb8cd22 to 4ee0ffd Compare May 21, 2026 19:22
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 21, 2026

PR Preview Action v1.8.1

QR code for preview link

🚀 View preview at
https://cli.sentry.dev/_preview/pr-999/

Built to branch gh-pages at 2026-05-21 22:23 UTC.
Preview will be ready when the GitHub Pages deployment is complete.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 21, 2026

Codecov Results 📊

✅ Patch coverage is 100.00%. Project has 4286 uncovered lines.
✅ Project coverage is 81.64%. Comparing base (base) to head (head).

Coverage diff
@@            Coverage Diff             @@
##          main       #PR       +/-##
==========================================
+ Coverage    81.64%    81.64%        —%
==========================================
  Files          328       328         —
  Lines        23344     23343        -1
  Branches     15111     15111         —
==========================================
+ Hits         19058     19057        -1
- Misses        4286      4286         —
- Partials      1613      1613         —

Generated by Codecov Action

@BYK BYK force-pushed the refactor/phase4-tsx branch from 4ee0ffd to eddd2b8 Compare May 21, 2026 19:37
Comment thread src/lib/scan/grep-worker-source.ts
@BYK BYK force-pushed the refactor/phase4-tsx branch from eddd2b8 to 7da073c Compare May 21, 2026 19:50
Comment thread script/require-shim.mjs Outdated
@BYK BYK force-pushed the refactor/phase4-tsx branch 2 times, most recently from d4451d2 to 4f737be Compare May 21, 2026 20:13
- Convert 12 script files from Bun APIs to Node equivalents
  (Bun.file/write/Glob → readFile/writeFile/tinyglobby)
- Update shebangs: bun → tsx in all scripts except build.ts
- Update package.json: bun run → tsx/pnpm run
- Update CI: remove setup-bun from all jobs except build-binary
- build.ts intentionally kept on Bun (uses Bun.build compiler)
@BYK BYK force-pushed the refactor/phase4-tsx branch from 4f737be to 3b981b6 Compare May 21, 2026 22:23
@BYK BYK merged commit 2a62159 into main May 21, 2026
30 checks passed
@BYK BYK deleted the refactor/phase4-tsx branch May 21, 2026 22:34
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.

1 participant