Skip to content

fix(cli): Handle Bun debug IDs and // @bun pragma in sourcemap inject - #1515

Merged
BYK merged 1 commit into
mainfrom
fix/cli-bun-sourcemap-inject
Oct 16, 2026
Merged

BYK merged 1 commit into
mainfrom
fix/cli-bun-sourcemap-inject

Conversation

@sentry-junior

@sentry-junior sentry-junior Bot commented Oct 15, 2026

Copy link
Copy Markdown
Contributor

sentry sourcemap inject broke on bun build --target=bun output in two ways. Both bugs are in the same snippet-insertion path, so they're fixed together.

Bun debug IDs weren't recognized (#1513). Bun writes //# debugId= and the sourcemap's debugId as 32 uppercase hex characters with no dashes. We only matched the hyphenated form, so we minted a second, conflicting ID, appended a second //# debugId= comment, and overwrote Bun's ID in the map. Now both forms are accepted from the JS comment and the sourcemap and normalized to the canonical lowercase hyphenated UUID. That is the ID the snippet registers, the map carries, and the upload uses. Bun's original comment is left alone, and no second comment is added. The runtime-registration check compares normalized IDs too, so a re-run is still a no-op.

The snippet landed above Bun's pragma (#1514). Bun only honors // @bun / // @bun @bun-cjs at the very top of the file, or right after a hashbang (has_bun_pragma). Prepending the snippet above it made CJS bundles silently do nothing and exit 0, and made Bun re-transpile ESM bundles on every start. The pragma line now stays above the snippet, handled the same way as the hashbang. The sourcemap's empty line goes in at the snippet's actual position, not always at line 0. For a header with no mappings, the output is the same as before.

One behavior change for existing users: a pre-existing debug ID in uppercase hyphenated form is now reported and re-emitted in lowercase. It's the same UUID.

I checked this end to end with Bun 1.4.3 using the reproductions from both issues. On main: two conflicting debug IDs, and the CJS bundle prints nothing. With this change: one ID (Bun's, canonicalized), both CJS and ESM bundles run, and a second inject leaves the files byte-identical.

Fixes #1513
Fixes #1514

via byk.

--

View Junior Session [Sentry]

`sentry sourcemap inject` mishandled `bun build --target=bun` output:

- Bun writes debug IDs as 32 uppercase hex chars without dashes. Only
  the hyphenated form was recognized, so a second, conflicting debug ID
  was minted and appended, and Bun's ID in the sourcemap was replaced.
  Both forms are now accepted from the JS comment and the sourcemap and
  normalized to the canonical lowercase hyphenated UUID.
- The runtime snippet was prepended above Bun's `// @bun` pragma, which
  Bun only honors at the top of the file (after an optional hashbang).
  CJS bundles silently stopped running and ESM bundles were
  re-transpiled on every start. The pragma line now stays above the
  snippet, and the sourcemap gains its empty line at the snippet's
  position instead of always at the top.

Fixes #1513
Fixes #1514

Co-Authored-By: Burak Yigit Kaya <burak.kaya@sentry.io>
@vercel

vercel Bot commented Oct 15, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated
sentry-local Skipped Skipped Oct 15, 2026 8:32pm UTC

Request Review

@sentry-junior sentry-junior Bot added the CLI Sentry CLI and CLI documentation label Oct 15, 2026
@BYK
BYK marked this pull request as ready for review October 15, 2026 20:37
@github-actions github-actions Bot added the risk: medium PR risk score: medium label Oct 15, 2026
@BYK
BYK merged commit 5a136e5 into main Oct 16, 2026
27 checks passed
@BYK
BYK deleted the fix/cli-bun-sourcemap-inject branch October 16, 2026 19:37

This branch was previously deployed

1 inactive deployment
Preview — 3ea9cc02 Deployed Oct 15, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLI Sentry CLI and CLI documentation risk: medium PR risk score: medium

Projects

None yet

1 participant