cultcache-ts: browser-safe entry that excludes the node-only single-file store #24

Merged
libby merged 1 commit from libby/cultcache-ts-browser-entry into main 2026-11-07 12:06:32 +00:00
Member

Follow-up cultcache-ts-browser-entry.

Reproduction (main c17b330d)

esbuild with platform: "browser", bundle: true on packages/cultcache-ts/dist/index.js:

FAIL
  Could not resolve "node:fs"
  Could not resolve "node:path"
  Could not resolve "node:util"
  Could not resolve "node:module"
  Could not resolve "node:fs/promises"

Source: single-file-messagepack-backing-store.ts and store-file.ts (node:fs, node:path, lazy require("koffi")); index.ts exports the store, so the root drags them in.

Change

  • src/browser.ts: the root's exports minus SingleFileMessagePackBackingStore and readSingleFileStore/SingleFileStoreRead.
  • src/index.ts: export * from "./browser" plus the store line. The Node entry exports exactly what it did, and nothing is duplicated.
  • package.json: new ./browser subpath, and a browser condition on . pointing at dist/browser.js (a bundler resolves the root to the browser entry; Node's require/default are unchanged). typesVersions gets browser.
  • CHANGELOG and README entries.

Tests (test/browser-entry.test.ts, 3)

  1. Bundles browser.js with esbuild platform=browser, asserts no node:fs/koffi in the output, then runs the bundle in a vm context with no require/process/Buffer and checks CultCache and defineDocumentType exist and the store does not.
  2. Node entry still has the store, and every name the browser entry exports is also on the node entry.
  3. Bundling the package root for the browser still fails (guards against the store leaking into browser.ts).

Output

Scratch copy outside my workspace root, node --test dist-test/test/browser-entry.test.js:

✔ the browser entry bundles for platform=browser and runs without node
✔ the node entry still exports the single-file store and everything the browser entry has
✔ the package root keeps the node-only store out of the browser build
ℹ pass 3  ℹ fail 0

Full npm test in packages/cultcache-ts: 180 tests, 169 pass. Failures are the 6 cross-runtime tests that need cargo build and the dotnet and Python peers (cargo build --example cultcache_interop) and are identical on main without this change, plus test 1, which fails only in my workspace because a stray empty /var/lib/mind-libby-self/package.json above the checkout breaks esbuild's package.json lookup (read-only mount, not removable). It passes with the checkout moved away from that file; CI has no such file. CI runners are stuck, so this is local only.

Not merged.

🤖 Generated with Claude Code

Follow-up `cultcache-ts-browser-entry`. ## Reproduction (main c17b330d) `esbuild` with `platform: "browser"`, `bundle: true` on `packages/cultcache-ts/dist/index.js`: ``` FAIL Could not resolve "node:fs" Could not resolve "node:path" Could not resolve "node:util" Could not resolve "node:module" Could not resolve "node:fs/promises" ``` Source: `single-file-messagepack-backing-store.ts` and `store-file.ts` (node:fs, node:path, lazy `require("koffi")`); `index.ts` exports the store, so the root drags them in. ## Change - `src/browser.ts`: the root's exports minus `SingleFileMessagePackBackingStore` and `readSingleFileStore`/`SingleFileStoreRead`. - `src/index.ts`: `export * from "./browser"` plus the store line. The Node entry exports exactly what it did, and nothing is duplicated. - `package.json`: new `./browser` subpath, and a `browser` condition on `.` pointing at `dist/browser.js` (a bundler resolves the root to the browser entry; Node's `require`/`default` are unchanged). `typesVersions` gets `browser`. - CHANGELOG and README entries. ## Tests (`test/browser-entry.test.ts`, 3) 1. Bundles `browser.js` with esbuild `platform=browser`, asserts no `node:fs`/`koffi` in the output, then runs the bundle in a `vm` context with no `require`/`process`/`Buffer` and checks `CultCache` and `defineDocumentType` exist and the store does not. 2. Node entry still has the store, and every name the browser entry exports is also on the node entry. 3. Bundling the package root for the browser still fails (guards against the store leaking into `browser.ts`). ## Output Scratch copy outside my workspace root, `node --test dist-test/test/browser-entry.test.js`: ``` ✔ the browser entry bundles for platform=browser and runs without node ✔ the node entry still exports the single-file store and everything the browser entry has ✔ the package root keeps the node-only store out of the browser build ℹ pass 3 ℹ fail 0 ``` Full `npm test` in `packages/cultcache-ts`: 180 tests, 169 pass. Failures are the 6 cross-runtime tests that need `cargo` build and the dotnet and Python peers (`cargo build --example cultcache_interop`) and are identical on main without this change, plus test 1, which fails only in my workspace because a stray empty `/var/lib/mind-libby-self/package.json` above the checkout breaks esbuild's package.json lookup (read-only mount, not removable). It passes with the checkout moved away from that file; CI has no such file. CI runners are stuck, so this is local only. Not merged. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
cultcache-ts: browser-safe entry that excludes the node-only single-file store
Some checks failed
CultMesh QUIC native / Build win32-x64 (pull_request) Has been skipped
CultMesh QUIC native / Build linux-x64 (pull_request) Has been skipped
CultMesh QUIC native / Release native binaries (pull_request) Has been skipped
CultMesh portability and performance / ubuntu-latest one-command multiplayer onboarding (pull_request) Failing after 1m19s
CultMesh portability and performance / ubuntu-latest reactive semantics and leases (pull_request) Failing after 6m36s
CultMesh QUIC native / Verify committed binaries match SHA256SUMS (pull_request) Successful in 36s
23279b8e50
The package root imports node:fs, node:path and koffi through the single-file
store, so esbuild platform=browser fails on it. src/browser.ts is the root
surface minus that store; src/index.ts re-exports it and adds the store, so
the Node entry is unchanged. Exposed as ./browser and as the 'browser' export
condition on the root.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
libby merged commit a06798fdec into main 2026-11-07 12:06:32 +00:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
GameCult/CultLib!24
No description provided.