Ruby bindings for Boa — what we built and how we'd like to contribute back #5258
rubys
started this conversation in
Show and tell
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Title: Ruby bindings for Boa — what we built and how we'd like to contribute back
I've been experimenting with embedding Boa in Ruby via Rust (using magnus/rb-sys for the FFI layer). The result is boax, a proof of concept that lets Ruby call JavaScript through proxy objects:
It supports ES module loading (via oxc_resolver against
node_modules/), CommonJS require, and npm packages like lodash-es, date-fns, uuid, and chalk load and run correctly.Along the way, we implemented several things that probably shouldn't live in a Ruby gem long-term, and I wanted to open a conversation about where they might belong.
Node.js built-in modules
We implemented 13 Node.js modules as Boa synthetic modules:
path,fs,util,events,process,os,buffer,crypto,stream,querystring,string_decoder,assert, andurl. These are pure Rust (or JS evaluated at init time), with no Ruby dependency. They exist so that npm packages thatimportNode built-ins don't fail at load time.The implementations are pragmatic —
fswrapsstd::fs,cryptowrapssha2/hmac/getrandom,pathwrapsstd::path,streamis an MVP without backpressure. They're not complete Node.js compatibility, but they cover the subset that popular npm packages actually use.These feel like they'd be useful to anyone embedding Boa, not just Ruby. A
boa_nodecrate (or additions toboa_runtime) would let Deno-like projects, CLI tools, or other embedders share the same implementations rather than each writing their ownpath.join.Intl gaps
We hit the
unimplementederror inNumberFormatfor currency and percent styles. Rather than just polyfilling around it, I looked at the Boa source and submitted #5257 to fix percent formatting. It was a small change —multiply_pow10(2)and appending the percent sign — and it was a good way to learn how Boa's Intl code is structured.Currency formatting looks similarly approachable: a
currency_digits()lookup table to fix the constructor, plus symbol/placement wrapping around the existingDecimalFormatteroutput. I'd be happy to work on that as a follow-up PR if the percent one looks reasonable.Web Crypto
We added
crypto.getRandomValuesas a global (wrappinggetrandom) because packages likeuuidexpect it. This is a Web API in the same category asURLandTextEncoderthatboa_runtimealready provides. Would a PR adding it toboa_runtimebe welcome?No urgency
None of this is blocking us. The proof of concept works as-is, and the polyfills serve their purpose. This is more about wanting to contribute the generally-useful pieces back rather than maintaining them in a Ruby-specific gem. I'm happy to work at whatever pace makes sense for the project.
The boax source is available if anyone wants to see the full implementation. I wrote about the motivation in a blog post as well.
Beta Was this translation helpful? Give feedback.
All reactions