Releases: sebastianwessel/quickjs
v1.3.0
What's Changed:
Features:
- feat: Typescript support - Run Typescript in the QuickJS sandbox #20 by @sebastianwessel in #21
- feat: Add compileOnly functionality #16 by @sebastianwessel in #18
- feat: Improve node compatibility #14 by @sebastianwessel in #15
- feat: Extend test runner result with summary and global passed flag #17 by @sebastianwessel in #25
Fixes:
- fix: Fails to run on Node.js due to use of the "using" keyword #23 by @sebastianwessel in #24
- fix: Improve setTimeout and setInterval #7 by @sebastianwessel in #26
Full Changelog: v1.2.0...v1.3.0
v1.2.0
What's Changed
- bug: Testrunner does not return the Errors in the response #11 by @sebastianwessel in #12
- feat: Improve custom virtual file system and module loader to allow r… by @sebastianwessel in #13
Full Changelog: 1.1.1...v1.2.0
1.1.1
Fixes type exports in published packages
v1.1.0
What's Changed
- feat: abstract the fetch client #1 by @sebastianwessel in #3
- chore: Improve doc and code cleanup by @sebastianwessel in #5
- fix: custom module should now work by @sebastianwessel
Version 1.0
Announcing QuickJS 1.0.0 - Execute JavaScript in a WebAssembly QuickJS Sandbox
I'm 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.
Key Features
- Security: Run untrusted JavaScript code in a safe, isolated environment.
- File System: Can mount a virtual file system.
- Custom Node Modules: Custom node modules are mountable.
- Fetch Client: Can provide a fetch client to make http(s) calls.
- Test-Runner: Includes a test runner and chai-based
expect
. - Performance: Benefit from the lightweight and efficient QuickJS engine.
- Versatility: Easily integrate with existing TypeScript projects.
- Simplicity: User-friendly API for executing and managing JavaScript code in the sandbox.
Full Documentation and Examples
Basic Usage Example
Here's a simple example of how to use the package:
import { quickJS } from '@sebastianwessel/quickjs'
// General setup like loading and init of the QuickJS wasm
// It is a resource-intensive job and should be done only once if possible
const { createRuntime } = await quickJS()
// Create a runtime instance each time a js code should be executed
const { evalCode } = await createRuntime({
allowFetch: true, // inject fetch and allow the code to fetch data
allowFs: true, // mount a virtual file system and provide node:fs module
env: {
MY_ENV_VAR: 'env var value'
},
})
const result = await evalCode(`
import { join } as path from 'path'
const fn = async () => {
console.log(join('src','dist')) // logs "src/dist" on host system
console.log(env.MY_ENV_VAR) // logs "env var value" on host system
const url = new URL('https://example.com')
const f = await fetch(url)
return f.text()
}
export default await fn()
`)
console.log(result) // { ok: true, data: '<!doctype html>\n<html>\n[....]</html>\n' }
Credits
This library is based on:
Tools used:
License
This project is licensed under the MIT License.
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!