Bringing JavaScript and TypeScript to Suborbital

One of Suborbital’s missions is to make WebAssembly far more accessible to many more people than ever before. Today, Suborbital is pleased to announce that JavaScript and TypeScript are joining the ranks of Go, Rust, AssemblyScript, Grain, and Swift as supported languages in our entire ecosystem. When developing cloud applications, it’s important that your team can build using the languages and tools they’re familiar with, so adding JavaScript to Suborbital’s arsenal became something highly requested by our community. I’m extremely pleased that we’ve been able to collaborate with several other open source projects to create a first-class experience, incorporating JavaScript and its expansive ecosystem into Suborbital.

At a first glance, running JavaScript in WebAssembly might seem a bit counter-intuitive—aren’t JS and Wasm supposed to exist in harmony? Why not just run JavaScript directly? WebAssembly has a number of useful properties that we wouldn’t get from a traditional JavaScript engine, particularly when it comes to security and portability. Like the other languages Atmo supports, we can tightly control what system resources—like networking and the filesystem—the JavaScript code can access. This is especially handy when using Atmo to securely run untrusted code, or even avoid surprises in your own code and its myriad of dependencies. Additionally, since the full JavaScript runtime is contained within the generated Wasm binary, there are no external dependencies—it’s equally easy to run that Atmo Runnable on your local machine, in your cloud infrastructure, or at the edge with Sat.

As with any of our supported languages, a new JavaScript Runnable can be created via the subo CLI tool with the command subo create runnable <name> --lang js and a new TypeScript Runnable can be created with --lang ts. Running subo build for that Runnable will bundle your JS and produce a self-contained WebAssembly module ready to serve requests. JavaScript Runnables can live side-by-side with those written in other languages, making true polyglot application development a breeze.

The JavaScript to WebAssembly conversion process is done by a tool called Javy, a project started by our friends at Shopify. While loading a full JavaScript engine might be slow to start up, Javy uses the Wizer project to fully pre-initialize the module—it initializes the JS engine and loads up your JS code so it can run at a moment's notice. It's able to achieve the same single-digit millisecond startup time you expect from languages natively compiled to WebAssembly. With a few tweaks, we got it to work with the full suite of Suborbital projects—including Atmo and Sat—but we decided to take it a step further. We believe the WebAssembly ecosystem will continue to thrive if tools like these are easy to use and adhere to standards, so we decided to use WebAssembly Interface Types to handle translation between JavaScript data and WebAssembly data. The wit-bindgen project can take a file containing the definition of an interface and generate the necessary glue code to move back and forth between high- and low-level types. Between wit-bindgen and a few Rust macros, we made it so anyone can easily use host functions provided by a runtime from their JavaScript code. We’re excited to continue working with the Shopify team to make this even better!

One phenomenal thing about the JavaScript ecosystem is its sheer abundance of available packages to download from npm. Whether it’s a rock-solid toolbelt like lodash or an HTML parser like cheerio, we can now tap into a full suite of tools, all from WebAssembly. To really put JS-in-Wasm through its paces, we built an Atmo app to serve a fully dynamic website with server-side rendered React and all. Stay tuned for a full write-up on how it works, but if you’re curious and want to try it for yourself, we’ve already open sourced the example project.

Our vision is a world powered by WebAssembly. Languages like JavaScript and TypeScript are used by an enormous number of developers, and support for them in Atmo and Sat is a step forward in our journey to bringing cloud native WebAssembly to all kinds of developers. We have some fantastic new docs, so I encourage you to try out our new languages. We’re excited to hear what you think!