Skip to content

fix(polyfill): add missing Bun.file().stat() shim for npm distribution#838

Merged
BYK merged 1 commit intomainfrom
byk/fix/polyfill-bun-file-stat
Apr 23, 2026
Merged

fix(polyfill): add missing Bun.file().stat() shim for npm distribution#838
BYK merged 1 commit intomainfrom
byk/fix/polyfill-bun-file-stat

Conversation

@BYK
Copy link
Copy Markdown
Member

@BYK BYK commented Apr 23, 2026

Summary

  • Fixes CLI-1EA (14 events) and CLI-1EB (420 events, escalating) — both share a single root cause.
  • Commit 9cb0d33 ("refactor(dsn): use Bun stat in regular-file guard", released in 0.29.0) swapped stat from node:fs/promises for Bun.file(path).stat() in isRegularFile(). The Node polyfill in script/node-polyfills.ts (injected at bundle time for the npm distribution) never implemented .stat(), so every DSN auto-detection call throws TypeError: Bun.file(...).stat is not a function on Node.
  • The error is caught by isRegularFile's try/catch but then captured to Sentry (not in isIgnorableFileError's allow-list), so npm users on 0.29.0 silently lose .env DSN detection + .editorconfig project-root detection while spamming our Sentry project with handled TypeErrors.

Fix

Extend BunPolyfill.file(path) with stat: stat.bind(null, path) — aliases stat from node:fs/promises with the path pre-bound. No wrapper closure needed; matches Bun.file().stat()'s zero-arg signature exactly. fs.stat (not lstat) follows symlinks, matching Bun semantics — critical for detecting 1Password symlink → FIFO chains.

Minimal one-line addition to the polyfill + a new stat in the existing top-level node:fs/promises import.

Tests

  • Extended test/script/node-polyfills.test.ts (the existing polyfillFile() reproduction) with 5 new .stat() cases: regular file, directory, non-existent path (ENOENT), symlink following, and parity with native Bun.file().stat().
  • Added test/lib/node-polyfills-file-stat.test.ts — a mirror that lives under the bun run test:unit glob so CI actually runs it (the test/script/ directory is not in any CI test script per AGENTS.md).

All 39 polyfill tests pass; full bun test test/lib is green (4192 pass, 0 fail).

Release

Intended as the content of a 0.29.1 patch release (will cut after merge).

Verification

  • bun run typecheck — clean
  • bun run lint — only pre-existing warning in src/lib/formatters/markdown.ts (not touched)
  • bun test test/lib — 4192 pass, 0 fail
  • bun test test/script/node-polyfills.test.ts test/lib/node-polyfills-file-stat.test.ts — 39 pass

Commit 9cb0d33 (released in 0.29.0) swapped `stat` from
`node:fs/promises` for `Bun.file(path).stat()` in `isRegularFile()`.
The Node polyfill in `script/node-polyfills.ts` (injected at bundle
time for the npm distribution) didn't implement `.stat()`, so every
DSN auto-detection call throws `TypeError: Bun.file(...).stat is not
a function` on Node.

The error is caught by `isRegularFile` but then captured to Sentry
(it's not in `isIgnorableFileError`'s allow-list), so 0.29.0 npm
users silently lose `.env` DSN detection + `.editorconfig` project-
root detection, while spamming our Sentry project with handled
TypeErrors.

Fix: alias `stat` from `node:fs/promises` with the path pre-bound.
`fs.stat` (not `lstat`) follows symlinks — matches
`Bun.file().stat()` semantics, critical for detecting 1Password
`symlink → FIFO` chains.

Tests are colocated with the existing Bun-polyfill reproductions in
`test/script/node-polyfills.test.ts`. A mirror of the regression
lives under `test/lib/` so it runs under `bun run test:unit` (the
`test/script/` directory is outside the CI globs — see AGENTS.md).

Fixes CLI-1EA, CLI-1EB.
@github-actions
Copy link
Copy Markdown
Contributor

Codecov Results 📊

138 passed | Total: 138 | Pass Rate: 100% | Execution Time: 0ms

📊 Comparison with Base Branch

Metric Change
Total Tests
Passed Tests
Failed Tests
Skipped Tests

✨ No test changes detected

All tests are passing successfully.

✅ Patch coverage is 100.00%. Project has 1942 uncovered lines.
❌ Project coverage is 95.3%. Comparing base (base) to head (head).

Coverage diff
@@            Coverage Diff             @@
##          main       #PR       +/-##
==========================================
- Coverage    95.32%    95.30%    -0.02%
==========================================
  Files          284       284         —
  Lines        41349     41348        -1
  Branches         0         0         —
==========================================
+ Hits         39415     39406        -9
- Misses        1934      1942        +8
- Partials         0         0         —

Generated by Codecov Action

@BYK BYK merged commit ab2e073 into main Apr 23, 2026
23 checks passed
@BYK BYK deleted the byk/fix/polyfill-bun-file-stat branch April 23, 2026 20:09
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