Skip to content

feat(p2-shim): add buffered input stream helper for browser cli stdin - #2236

Merged
vados-cosmonic merged 1 commit into
bytecodealliance:mainfrom
eduardomourar:fix-browser-cli-buffered-stdin
Oct 13, 2026
Merged

vados-cosmonic merged 1 commit into
bytecodealliance:mainfrom
eduardomourar:fix-browser-cli-buffered-stdin

Conversation

@eduardomourar

@eduardomourar eduardomourar commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Every host feeding a guest a fixed stdin buffer hand-rolls the same bounded InputStreamHandler, and it's easy to get the "closed" transition or u64 length truncation subtly wrong.

Changes

  • Adds bufferedInputStream(bytes) in a new src/browser/helpers/cli.ts, so hosts can pass it straight to createCli({ stdin }) (or _setStdin) instead of hand-rolling it.
  • The helper is browser-only (it builds on the browser io pollables), so it is exposed from an explicit browser/helpers/cli subpath export rather than the platform-neutral ./* wildcard. This keeps convenience helpers separate from the shim's implementation and the underscore-prefixed configuration surface, and makes the browser-only nature visible in the import path:
import { bufferedInputStream } from "@bytecodealliance/preview2-shim/browser/helpers/cli";

Node consumers now get the Node typings

The . and ./* exports had a top-level types pointing at the browser .d.ts ahead of the node block. TypeScript under nodenext includes node in its condition set but stops at the first matching condition, so Node consumers were typed against the browser build. The types entries are now nested under node and default with no top-level types key, which oxfmt's package.json sorting leaves alone. Verified with a consumer project: moduleResolution: nodenext resolves dist/nodejs/*.d.ts, moduleResolution: bundler resolves dist/browser/*.d.ts, and Node runtime resolution is unchanged. The same hunk is in #2237 so the two merge cleanly in either order.

vados-cosmonic
vados-cosmonic previously approved these changes Oct 11, 2026

@vados-cosmonic vados-cosmonic left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM 🚀

@vados-cosmonic
vados-cosmonic added this pull request to the merge queue Oct 11, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to a conflict with the base branch Oct 11, 2026
@vados-cosmonic

Copy link
Copy Markdown
Collaborator

Hey @eduardomourar on second thought here -- would you mind moving this helper actually to a different file and exporting them from a new export like ...helpers/cli?

I want to improve the DX here like you have done but I'd like to separate the helpers from the actual implementation-specific code

@vados-cosmonic
vados-cosmonic force-pushed the fix-browser-cli-buffered-stdin branch 4 times, most recently from 2f16185 to fa46c19 Compare October 13, 2026 14:58
vados-cosmonic
vados-cosmonic previously approved these changes Oct 13, 2026
@vados-cosmonic
vados-cosmonic force-pushed the fix-browser-cli-buffered-stdin branch from fa46c19 to 460f567 Compare October 13, 2026 15:18
@vados-cosmonic
vados-cosmonic merged commit 7daa67c into bytecodealliance:main Oct 13, 2026
16 checks passed
@jco-release-bot

Copy link
Copy Markdown
Collaborator

🎉 The code in this PR was made available in the following release:
https://github.com/bytecodealliance/jco/releases/tag/preview2-shim-v0.29.0

@eduardomourar
eduardomourar deleted the fix-browser-cli-buffered-stdin branch October 13, 2026 18:58
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.

3 participants