wasmerio / winterjs

Winter is coming... ❄️
https://winterjs.org/
MIT License
3.04k stars 53 forks source link
Wasmer logo

WinterJS is blazing-fast JavaScript server that runs Service Workers scripts according to the Winter Community Group specification.

WinterJS is able to handle up to 100,000 reqs/s in a single laptop (see Benchmark).


Note: WinterJS is not officially endorsed by WinterCG, despite sharing "Winter" in their name. There are many runtimes supporting WinterCG, WinterJS being one among those.

Running WinterJS with Wasmer

The WinterJS server is published in Wasmer as wasmer/winterjs.

You can run the HTTP server locally with:

wasmer run wasmer/winterjs --net --mapdir=tests:tests tests/simple.js

Where simple.js is:

addEventListener('fetch', (req) => {
  req.respondWith(new Response('hello'));
});

Building from source

WinterJS needs to build SpiderMonkey from source as part of its own build process. Please follow the steps outlined here to make sure you are ready to build SpiderMonkey: https://github.com/wasmerio/mozjs/blob/master/README.md.

You also need to do this before installing WinterJS with cargo install, which builds WinterJS from the source instead of downloading pre-built binaries.

Also, when building WinterJS in debug mode, you need to have NodeJS and npm installed and run npm install beforehand. This is required since debug builds of WinterJS also build the TypeScript code in src/builtins/internal_js_modules. Release builds use the existing, pre-compiled *.js sources in that directory. This was done to simplify installing WinterJS with cargo install. If you update the TypeScript sources, make sure to update the *.js sources by building at least once in debug mode and commit the updated *.js files.

Once you can build SpiderMonkey, you simply need to run cargo build as usual to build WinterJS itself.

Running WinterJS Natively

You can install WinterJS natively with:

cargo install --git https://github.com/wasmerio/winterjs winterjs

Once you have WinterJS installed, you can simply do:

winterjs tests/simple.js

And then access the server in https://localhost:8080/

How WinterJS works

WinterJS is powered by SpiderMonkey, Spiderfire and hyper to bring a new level of awesomeness to your Javascript apps.

WinterJS is using the WASIX standard to compile to WebAssembly. Please note that compiling to WASIX is currently a complex process. We recommend using precompiled versions from wasmer/winterjs, but please open an issue if you need to compile to WASIX locally.

Limitations

WinterJS is fully compliant with the WinterCG spec, although the runtime itself is still a work in progress. For more information, see the API Compatibility section below.

WinterCG API Compatibility

This section will be updated as APIs are added/fixed. If an API is missing from this section, that means that it is still not implemented.

You can check a more detailed list here: https://runtime-compat.unjs.io/

The following words are used to describe the status of an API:

API Status Notes
console βœ… Stable
fetch βœ… Stable
URL βœ… Stable
URLSearchParams βœ… Stable
Request βœ… Stable
Headers βœ… Stable
Response βœ… Stable
Blob βœ… Stable
File βœ… Stable
FormData βœ… Stable
TextDecoder βœ… Stable
TextDecoderStream βœ… Stable
TextEncoder βœ… Stable
TextEncoderStream βœ… Stable
ReadableStream and supporting types βœ… Stable
WritableStream and supporting types βœ… Stable
TransformStream and supporting types πŸ”Ά Partial Back-pressure is not implemented
atob βœ… Stable
btoa βœ… Stable
performance.now() βœ… Stable
performance.timeOrigin βœ… Stable
crypto βœ… Stable
crypto.subtle πŸ”Ά Partial Only HMAC, MD5 and SHA algorithms are supported

Other supported APIs

The following (non-WinterCG) APIs are implemented and accessible in WinterJS:

API Status Notes
Service Workers Caches API βœ… Stable Accessible via caches. caches.default (similar to Cloudflare workers) is also available.
The current implementation is memory-backed, and cached responses will not persist between multiple runs of WinterJS.