ReviewOS

stacks/stx

Bun-first: `inline-assets.ts` and `app-shell.ts` still use `node:fs` for existence checks where `Bun.file().exists()` is the documented preference

#1715
Closed glennmichael123 opened this 23 days ago · 0 comments
23 days ago

TL;DR

CLAUDE.md item 7 documents the Bun-first preference:

Bun.file().text() replaces fs.readFileSync, Bun.file().exists() replaces fs.existsSync, Bun.write() replaces fs.writeFileSync in async contexts. node:path is retained (no Bun alternative) and node:fs is kept for directory operations.

Two files in packages/stx/src/ still use node:fs for existence checks where the Bun-native API would apply:

1. packages/stx/src/inline-assets.ts:36

import fs from 'node:fs'
// …
if (fs.existsSync(absPath)) { … }

Should be:

if (await Bun.file(absPath).exists()) { … }

The surrounding function is already async (per the surrounding code path) — no signature change needed.

2. packages/stx/src/app-shell.ts:69-77

Same pattern: fs.existsSync(...) inside an async-capable code path. The Bun-native equivalent removes the node:fs import here and is consistent with the rest of the codebase.

Why it matters

  • Codebase consistency: most of the framework already uses Bun.file() for these checks; these two stick out
  • Bundle / startup cost: node:fs shim has overhead in pure-Bun contexts (small but real)
  • CLAUDE.md / agent guidance: agents writing new code in this codebase are told to prefer Bun APIs. Mixed examples in the existing code make that guidance less effective

Proposed fix

Two ~3-line edits per file. Both async-safe since the calling contexts are already async or trivially convertible.

Should be a 10-minute change. Filing as a tracker so it doesn't get forgotten in the background-pile.

Other places in packages/stx/src/ that haven't been audited for Bun-first: any remaining fs.readFileSync (synchronous file read; should be await Bun.file(p).text() in async contexts), any fs.writeFileSync (should be await Bun.write(p, content)). A grep sweep would catch more.

Found during a deep-scan audit.

🤖 Filed via Claude Code

Sign in to comment on this issue.