Add Bun as an available runtime #127
Merged
+52
−7
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.
Resolves #119
This PR adds a new JS Runtime called Bun as a new supported external Runtime.
What is Bun?
Bun is a very very fast JS runtime that's meant to be mostly compatible with NodeJS. While not quite a full-drop-in replacement, it often performs significantly faster running equivalent code. For example check out the the test suite
Node
Bun
Why Teach This Dog a New Trick?
It's a good question. With the recent announcement that Rails 8 will be ditching sprockets in favor of propshaft most Rails apps will not really have a need for execJS, so why invest time in supporting another runtime?
Well even though I already am a production propshaft user, I actually have a lot of uses for ExecJS and want to eventually be in a place where I don't have to ship the node runtime to my app.
Some examples of how I use ExecJS in my app
Validating SQLite
Back in the day, Codeschool wrote a really great SQLiite parser in JS. There isn't anything as good in ruby. With the power of ExecJS I could build a simple ~150 line wrapper library that feels as good and responsive as a native Gem.
Scoring Passwords
A few years ago Dropbox created a great JS library for validating password quality called
[zxcvbn](https://github.com/dropbox/zxcvbn)
. While there are great ruby implementations ofzxcvbn
in practice we want to always make sure the warnings we serve to the user in the client-side are the exact same errors we would get on the server-side through an AR validator. The ruby implementations always fell short of that, so simply writing a wrapper with ExecJS for the same lib got the job done easily.Here is where we use it in an AR validator
In conclusion, ExecJS is a great way for me to plumb high-value functionality from the JS ecosystem with very little effort. Under that premise I think it's worthy of getting it in line with what I believe will eventually become most people's default runtime if a few years.
Notable Items
By default Bun runs everything in
strict
mode, currently the only way to force it to run things in sloppy mode is to use code that would only normally be found in a commonjs file likeexports.abc = function(){}
.Bun has an implementation difference where in sloppy mode, you cannot delete the timing functions from the
this
object as they are set toconfigurable: false
. I've filed a bug for this and until it is fixed (if it ever is) we will need to skip the associated test.Bun outputs things a bit differently when you throw an exception during eval and I had to change some tests that had the assumption that the first line of a trace would include a reference to execjs.
I had to update the
uglify.js
fixture to bring it in line with the latest es5 compatibility shim. I sourced the latest and greatest from here.