Skip to content

Commit f39dc87

Browse files
chore: update
1 parent f3c6833 commit f39dc87

File tree

4 files changed

+125
-10
lines changed

4 files changed

+125
-10
lines changed

docs/README.md

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
---
2-
title: QuickJS - Execute JavaScript in a WebAssembly QuickJS Sandbox
3-
description: Run custom javascript inside a webassembly runtime from your Javascript/Typescript application
4-
---
1+
# QuickJS - Execute JavaScript in a WebAssembly QuickJS Sandbox
52

63
This TypeScript package allows you to safely execute JavaScript code within a WebAssembly sandbox using the QuickJS engine. Perfect for isolating and running untrusted code securely, it leverages the lightweight and fast QuickJS engine compiled to WebAssembly, providing a robust environment for code execution.
74

docs/_posts/release.md

Lines changed: 90 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,95 @@
11
---
22
layout: post
3-
title: "Version 1.0.0 of the QuickJS sandbox released"
4-
date: YYYY-MM-DD hh:mm:ss -0000
3+
title: "Announcing QuickJS 1.0.0 - Execute JavaScript in a WebAssembly QuickJS Sandbox"
4+
description: "Version 1.0 of the QuickJS package is released. A TypeScript package that allows you to safely execute JavaScript code within a WebAssembly sandbox using the QuickJS engine."
5+
date: 2024-07-07 12:00:00
56
categories: release
67
---
78

8-
Happy to announce
9+
## Announcing QuickJS 1.0.0 - Execute JavaScript in a WebAssembly QuickJS Sandbox
10+
11+
We are excited to announce the release of **QuickJS 1.0.0**, a TypeScript package that allows you to safely execute JavaScript code within a WebAssembly sandbox using the QuickJS engine. Perfect for isolating and running untrusted code securely, QuickJS leverages the lightweight and fast QuickJS engine compiled to WebAssembly, providing a robust environment for code execution.
12+
13+
### Key Features
14+
15+
- **Security**: Run untrusted JavaScript code in a safe, isolated environment.
16+
- **File System**: Can mount a virtual file system.
17+
- **Custom Node Modules**: Custom node modules are mountable.
18+
- **Fetch Client**: Can provide a fetch client to make http(s) calls.
19+
- **Test-Runner**: Includes a test runner and chai-based `expect`.
20+
- **Performance**: Benefit from the lightweight and efficient QuickJS engine.
21+
- **Versatility**: Easily integrate with existing TypeScript projects.
22+
- **Simplicity**: User-friendly API for executing and managing JavaScript code in the sandbox.
23+
24+
### Full Documentation and Examples
25+
26+
- **[View the full documentation](https://sebastianwessel.github.io/quickjs/)**
27+
- **[Find examples in the repository](https://github.com/sebastianwessel/quickjs/tree/main/example)**
28+
29+
### Basic Usage Example
30+
31+
Here's a simple example of how to use the package:
32+
33+
```typescript
34+
import { quickJS } from '@sebastianwessel/quickjs'
35+
36+
// General setup like loading and init of the QuickJS wasm
37+
// It is a resource-intensive job and should be done only once if possible
38+
const { createRuntime } = await quickJS()
39+
40+
// Create a runtime instance each time a js code should be executed
41+
const { evalCode } = await createRuntime({
42+
allowFetch: true, // inject fetch and allow the code to fetch data
43+
allowFs: true, // mount a virtual file system and provide node:fs module
44+
env: {
45+
MY_ENV_VAR: 'env var value'
46+
},
47+
})
48+
49+
const result = await evalCode(`
50+
import { join } as path from 'path'
51+
52+
const fn = async () => {
53+
console.log(join('src','dist')) // logs "src/dist" on host system
54+
55+
console.log(env.MY_ENV_VAR) // logs "env var value" on host system
56+
57+
const url = new URL('https://example.com')
58+
59+
const f = await fetch(url)
60+
61+
return f.text()
62+
}
63+
64+
export default await fn()
65+
`)
66+
67+
console.log(result) // { ok: true, data: '<!doctype html>\n<html>\n[....]</html>\n' }
68+
```
69+
70+
### Credits
71+
72+
This library is based on:
73+
74+
- [quickjs-emscripten](https://github.com/justjake/quickjs-emscripten)
75+
- [quickjs-emscripten-sync](https://github.com/reearth/quickjs-emscripten-sync)
76+
- [memfs](https://github.com/streamich/memfs)
77+
78+
Tools used:
79+
80+
- [Bun](https://bun.sh)
81+
- [Biome](https://biomejs.dev)
82+
- [Hono](https://hono.dev)
83+
- [poolifier-web-worker](https://github.com/poolifier/poolifier-web-worker)
84+
- [tshy](https://github.com/isaacs/tshy)
85+
- [autocannon](https://github.com/mcollina/autocannon)
86+
87+
### License
88+
89+
This project is licensed under the MIT License.
90+
91+
---
92+
93+
QuickJS 1.0.0 is ideal for developers looking to execute JavaScript code securely within a TypeScript application, ensuring both performance and safety with the QuickJS WebAssembly sandbox. Try it out and let us know what you think!
94+
95+
[Check out QuickJS on GitHub](https://github.com/sebastianwessel/quickjs)

jsr.json

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"$schema": "https://jsr.io/schema/config-file.v1.json",
3+
"name": "@sebastianwessel/quickjs",
4+
"version": "1.0.0",
5+
"description": "A typescript package to execute javascript code in a webassembly quickjs sandbox",
6+
"exports": "./dist/esm/index.js",
7+
"publish": {
8+
"include": ["dist/**/*.js", "dist/**/*.d.ts", "README.md", "package.json"],
9+
"exclude": [
10+
"src",
11+
".github",
12+
".vscode",
13+
".zed",
14+
"!dist",
15+
"!dist/**/*.js",
16+
"!dist/**/*.d.ts",
17+
".tshy",
18+
"vendor",
19+
"docs"
20+
]
21+
}
22+
}

package.json

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,18 @@
1717
"package",
1818
"library"
1919
],
20-
"files": ["dist"],
20+
"files": [
21+
"dist"
22+
],
2123
"tshy": {
22-
"exclude": ["src/**/*.test.ts", "vendor"],
23-
"dialects": ["esm", "commonjs"],
24+
"exclude": [
25+
"src/**/*.test.ts",
26+
"vendor"
27+
],
28+
"dialects": [
29+
"esm",
30+
"commonjs"
31+
],
2432
"exports": {
2533
"./package.json": "./package.json",
2634
".": "./src/index.ts"
@@ -35,6 +43,7 @@
3543
"test:dev": "bun test --watch",
3644
"lint": "bunx @biomejs/biome check",
3745
"lint:fix": "bunx @biomejs/biome check --write",
46+
"postpublish": "npx jsr publish",
3847
"example:basic": "bun example/basic/server.ts",
3948
"example:server": "bun example/server/server.ts",
4049
"example:tests": "bun example/run-tests/index.ts"

0 commit comments

Comments
 (0)