-
-
Notifications
You must be signed in to change notification settings - Fork 20
fix(js): build bashkit-js for wasm32-wasip1-threads #2141
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adding the wasm target makes the package's existing browser export (
./bashkit.wasi-browser.js) active for browser consumers, but the generated file exports the raw napi bindings only. It does not expose the wrapper API advertised bywrapper.d.ts/README, such asFileSystem,Bash.create, or the wrapper custom-builtin adaptation. Please either route the browser condition through a wrapper that re-exports the public API, or expose this as a separate raw wasm entrypoint with matching types/docs.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rechecked
dd90fc8amerged onto currentorigin/main(df4acc21). This still reproduces:bashkit.wasi-browser.jsexportsBash,BashTool,ScriptedTool,getVersion, and raw__fileSystem*helpers only; it still does not export wrapper API likeFileSystemorBash.create. Sincepackage.jsonroutes the publicbrowsercondition to that generated file whiletypes/README describe the wrapper API, this still looks like a browser-consumer API mismatch.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point! Let me think this through a bit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I prototyped both directions you suggested, verified each end-to-end in headless Chromium against a Vite terminal example (COOP/COEP, wasip1-threads build), and pushed them as single-commit branches on top of this PR so you can compare:
Option A — raw wasm as an opt-in subpath (compare, +58/−2): removes the root
browsercondition entirely and exposes the raw napi surface as@everruns/bashkit/wasm(browser → wasi-browser loader, default → wasi cjs loader), typed by a newwasm.d.tsthat documents exactly what the raw surface does not include. Browser consumers opt in knowingly; the root import never lies. Cost: two documented API surfaces, and noFileSystem/Bash.create/custom builtins in browsers.Option B — wrapper API everywhere (compare, +267/−49): makes
wrapper.tsplatform-neutral so browsers get the same root entrypoint and the same documented API. The platform split lives behind a self-referencing./bindingsubpath export (binding-node.ts: createRequire + AsyncResource;binding-browser.ts: wasm loader + identity binding + TextEncoder for the Buffer uses). Natives compiled out of wasm (__realFileSystem,__importFileSystem,__fileSystemToExternal) throw a descriptive "not available in the wasm build" error. Verified in-browser:FileSystemops,Bash.createwithcustomBuiltins(JS callbacks work through emnapi), andonOutput— with one caveat below. Full ava suite still green on the native path.Caveat that affects both options:
executeWithOutputdeadlocks on the wasm build — zero chunks delivered, hangs forever, reproduced in both browsers and Node WASI (NAPI_RS_FORCE_WASI=1). The per-chunk blocking ThreadsafeFunction round-trip (waiting on the JS callback's return value) doesn't survive the wasm threading model. Option B works around it (supportsStreamingOutputbinding flag; wrapper falls back to plain execute + one final chunk, documented in README); option A would expose it raw. Either way the native fix insrc/lib.rslooks like a separate follow-up.My lean is Option B — it resolves the mismatch you flagged rather than fencing it off, and the browser demo shows the wrapper API genuinely works on wasm. But happy to go either way; whichever you prefer I'll fold into this PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Btw, I am ok closing this PR as well. I was doing it mostly as a nice to do. I am unblocked with #2140 . I understand this adds another layer that needs to be maintained. So it will be your call :) Thanks for the quick reviews
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's postpone then and close for now. I would be ready to return back to it when it would became blocker.