@wasmer/wasi
Advanced tools
Comparing version 0.12.0 to 1.0.0
{ | ||
"name": "@wasmer/wasi", | ||
"version": "0.12.0", | ||
"description": "Isomorphic Javascript library for interacting with WASI Modules in Node.js and the Browser. 📚", | ||
"main": "lib/index.cjs.js", | ||
"module": "lib/index.esm.js", | ||
"iife": "lib/index.iife.js", | ||
"typings": "lib/packages/wasi/src/index.d.ts", | ||
"files": [ | ||
"lib" | ||
], | ||
"scripts": { | ||
"precompile": "cd test/rs && make all", | ||
"build": "run-s build:clean build:ts build:prod", | ||
"build:clean": "rm -rf lib", | ||
"build:ts": "tsc -b", | ||
"build:prod": "rollup -c --environment PROD", | ||
"build:dev": "rollup -c --environment DEV", | ||
"dev": "watch \"npm run build:dev\" src", | ||
"test": "jest --config jest.config.js --verbose", | ||
"test:watch": "jest --config jest.config.js --watch --verbose", | ||
"docs": "typedoc src/ --out docs --target es6 --theme minimal --mode file" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/wasmerio/wasmer-js.git" | ||
}, | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"version": "1.0.0", | ||
"main": "dist/Library.cjs.min.js", | ||
"module": "dist/Library.esm.min.js", | ||
"unpkg": "dist/Library.umd.min.js", | ||
"keywords": [ | ||
"wasi", | ||
"webassembly", | ||
"wasm", | ||
"wasmer", | ||
"abi", | ||
"esm", | ||
"es", | ||
"module" | ||
"wasi" | ||
], | ||
"description": "Isomorphic Javascript library for interacting with WASI Modules in Node.js and the Browser.", | ||
"author": "Wasmer Engineering Team <engineering@wasmer.io>", | ||
@@ -46,10 +18,44 @@ "license": "MIT", | ||
}, | ||
"homepage": "https://github.com/wasmerio/wasmer-js/tree/master/packages/wasi", | ||
"dependencies": { | ||
"browser-process-hrtime": "^1.0.0", | ||
"buffer-es6": "^4.9.3", | ||
"path-browserify": "^1.0.0", | ||
"randomfill": "^1.0.4" | ||
"homepage": "https://github.com/wasmerio/wasmer-js", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/wasmerio/wasmer-js" | ||
}, | ||
"gitHead": "539782bfd0693218bacccf7b98d457a378fec182" | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"scripts": { | ||
"build": "wasm-pack build --release --target web; wasm-opt pkg/wasmer_wasi_js_bg.wasm -O2 -o pkg/wasmer_wasi_js_bg.wasm; wasm-strip pkg/wasmer_wasi_js_bg.wasm; rollup -c --environment BUILD:production", | ||
"dev": "rollup -c -w", | ||
"lint": "", | ||
"test": "jest -c jest.config.js", | ||
"test:watch": "npm run test -- --watch", | ||
"test:coverage": "npm run test -- --coverage", | ||
"clean": "rimraf dist coverage", | ||
"prepare": "npm-run-all clean lint build test" | ||
}, | ||
"devDependencies": { | ||
"@babel/core": "~7.16.0", | ||
"@babel/plugin-proposal-object-rest-spread": "~7.16.0", | ||
"@babel/preset-env": "~7.16.0", | ||
"@babel/register": "~7.16.0", | ||
"@rollup/plugin-babel": "~5.3.0", | ||
"@rollup/plugin-commonjs": "~21.0.1", | ||
"@rollup/plugin-node-resolve": "~13.0.6", | ||
"@rollup/plugin-url": "^6.1.0", | ||
"@rollup/plugin-wasm": "^5.1.2", | ||
"@wasm-tool/wasm-pack-plugin": "1.6.0", | ||
"cross-env": "~7.0.3", | ||
"eslint": "~7.18.0", | ||
"jest": "^27.3.1", | ||
"npm-run-all": "~4.1.5", | ||
"rimraf": "~3.0.2", | ||
"rollup": "~2.60.0", | ||
"rollup-plugin-terser": "~7.0.2", | ||
"rollup-plugin-typescript2": "^0.31.0", | ||
"ts-loader": "^9.2.6", | ||
"tslib": "^2.3.1", | ||
"typescript": "^4.5.2" | ||
}, | ||
"browserslist": "> 0.5%, last 2 versions, Firefox ESR, not dead" | ||
} |
217
README.md
@@ -1,90 +0,183 @@ | ||
# `@wasmer/wasi` | ||
# <img height="48" src="https://raw.githubusercontent.com/wasmerio/wasmer/master/assets/logo.png" alt="Wasmer logo" valign="middle"> Wasmer JS [![Wasmer Slack Channel](https://img.shields.io/static/v1?label=chat&message=on%20Slack&color=green)](https://slack.wasmer.io) | ||
Isomorphic Javascript library for interacting with WASI Modules in Node.js and the Browser. 📚 | ||
This repository consists of multiple packages: | ||
* [Wasmer WASI](#wasmer-wasi) | ||
Documentation for Wasmer-JS Stack can be found on the [Wasmer Docs](https://docs.wasmer.io/wasmer-js/wasmer-js). | ||
# Wasmer WASI | ||
## Table of Contents | ||
Isomorphic Javascript library for interacting with WASI Modules in Node.js, the Browser and [Deno](https://deno.land/x/wasm). | ||
The Javascript Package supports: | ||
* [X] WASI (with command args, envs and stdio) | ||
* [X] In-Memory filesystem (MemFS) | ||
- [Features](#features) | ||
- [Installation](#installation) | ||
- [Quick Start](#quick-start) | ||
- [Reference API](#reference-api) | ||
- [Contributing](#contributing) | ||
### NPM | ||
## Features | ||
For instaling `@wasmer/wasi` run this command in your shell: | ||
`@wasmer/wasi` uses the same API than the [future WASI integration in Node](https://github.com/nodejs/wasi), to help transition to it once it becomes available in Node. | ||
```bash | ||
npm install --save @wasmer/wasi | ||
``` | ||
However, `@wasmer/wasi` is focused on: | ||
And then import it in your server or client-side code with: | ||
- Bringing [WASI](https://github.com/webassembly/wasi) to an Isomorphic context (Node.js and the Browser) 🖥️ | ||
- Make it easy to plug in different filesystems (via [wasmfs](https://github.com/wasmerio/wasmer-js/tree/master/packages/wasmfs)) 📂 | ||
- Make it type-safe using [Typescript](http://www.typescriptlang.org/) 👷 | ||
- Pure JavaScript implementation (no Native bindings needed) 🚀 | ||
- ~ 15KB minified + gzipped 📦 | ||
```js | ||
import { init, WASI } from '@wasmer/wasi'; | ||
``` | ||
## Installation | ||
### Deno | ||
For instaling `@wasmer/wasi`, just run this command in your shell: | ||
This package is published in Deno in the `wasm` package, you can import it direclty with: | ||
```bash | ||
npm install --save @wasmer/wasi | ||
```ts | ||
import { init, WASI } from 'https://deno.land/x/wasm/wasi.ts'; | ||
``` | ||
## Quick Start | ||
## Usage | ||
**This quick start is for browsers. For node, WasmFs is not required** | ||
```js | ||
import { WASI } from "@wasmer/wasi"; | ||
import wasiBindings from "@wasmer/wasi/lib/bindings/node"; | ||
import { lowerI64Imports } from "@wasmer/wasm-transformer" | ||
// Use this on the browser | ||
// import wasiBindings from "@wasmer/wasi/lib/bindings/browser"; | ||
// This is needed to load the WASI library first (since is a Wasm module) | ||
await init(); | ||
import { WasmFs } from "@wasmer/wasmfs"; | ||
// Instantiate a new WASI Instance | ||
const wasmFs = new WasmFs(); | ||
let wasi = new WASI({ | ||
args: [], | ||
env: {}, | ||
bindings: { | ||
...wasiBindings, | ||
fs: wasmFs.fs | ||
} | ||
env: { | ||
// 'ENVVAR1': '1', | ||
// 'ENVVAR2': '2' | ||
}, | ||
args: [ | ||
// 'command', 'arg1', 'arg2' | ||
], | ||
}); | ||
const startWasiTask = async () => { | ||
// Fetch our Wasm File | ||
const response = await fetch("./my-wasi-module.wasm"); | ||
const responseArrayBuffer = await response.arrayBuffer(); | ||
const moduleBytes = fetch("https://deno.land/x/wasm/tests/demo.wasm"); | ||
const module = await WebAssembly.compileStreaming(moduleBytes); | ||
// Instantiate the WASI module | ||
await wasi.instantiate(module, {}); | ||
// Instantiate the WebAssembly file | ||
const wasm_bytes = new Uint8Array(responseArrayBuffer).buffer; | ||
const lowered_wasm = await lowerI64Imports(wasm_bytes); | ||
let module = await WebAssembly.compile(lowered_wasm); | ||
let instance = await WebAssembly.instantiate(module, { | ||
...wasi.getImports(module) | ||
}); | ||
// Run the start function | ||
let exitCode = wasi.start(); | ||
let stdout = wasi.getStdoutString(); | ||
// Start the WebAssembly WASI instance! | ||
wasi.start(instance); | ||
// This should print "hello world (exit code: 0)" | ||
console.log(`${stdout}(exit code: ${exitCode})`); | ||
``` | ||
// Output what's inside of /dev/stdout! | ||
const stdout = await wasmFs.getStdOut(); | ||
console.log(stdout); | ||
}; | ||
startWasiTask(); | ||
## API Docs | ||
<!-- Please check the full API documents here: | ||
https://docs.wasmer.io/integrations/js/reference-api --> | ||
### Typescript API | ||
```typescript | ||
export class WASI { | ||
constructor(config: any); | ||
readonly fs: MemFS; | ||
instantiate(module: any, imports: object): void; | ||
// Start the WASI Instance, it returns the status code when calling the start | ||
// function | ||
start(): number; | ||
// Get the stdout buffer | ||
// Note: this method flushes the stdout | ||
getStdoutBuffer(): Uint8Array; | ||
// Get the stdout data as a string | ||
// Note: this method flushes the stdout | ||
getStdoutString(): string; | ||
// Get the stderr buffer | ||
// Note: this method flushes the stderr | ||
getStderrBuffer(): Uint8Array; | ||
// Get the stderr data as a string | ||
// Note: this method flushes the stderr | ||
getStderrString(): string; | ||
// Set the stdin buffer | ||
setStdinBuffer(buf: Uint8Array): void; | ||
// Set the stdin data as a string | ||
setStdinString(input: string): void; | ||
} | ||
export class MemFS { | ||
constructor(); | ||
readDir(path: string): Array<any>; | ||
createDir(path: string): void; | ||
removeDir(path: string): void; | ||
removeFile(path: string): void; | ||
rename(path: string, to: string): void; | ||
metadata(path: string): object; | ||
open(path: string, options: any): JSVirtualFile; | ||
} | ||
export class JSVirtualFile { | ||
lastAccessed(): BigInt; | ||
lastModified(): BigInt; | ||
createdTime(): BigInt; | ||
size(): BigInt; | ||
setLength(new_size: BigInt): void; | ||
read(): Uint8Array; | ||
readString(): string; | ||
write(buf: Uint8Array): number; | ||
writeString(buf: string): number; | ||
flush(): void; | ||
seek(position: number): number; | ||
} | ||
``` | ||
## Reference API | ||
## Building | ||
The Reference API Documentation can be found on the [`@wasmer/wasi` Reference API Wasmer Docs](https://docs.wasmer.io/integrations/js/reference-api/wasmer-wasi). | ||
To build this library you will need to have installed in your system: | ||
## Contributing | ||
* Node.JS | ||
* [Rust][Rust] | ||
* [wasm-pack][wasm-pack] | ||
* [wabt][wabt] (for `wasm-opt`) | ||
* [binaryen][binaryen] (for `wasm-strip`) | ||
This project follows the [all-contributors](https://github.com/kentcdodds/all-contributors) specification. | ||
```sh | ||
npm i | ||
npm run build | ||
``` | ||
Contributions of any kind are welcome! 👍 | ||
## Testing | ||
Build the pkg and run the tests: | ||
```sh | ||
npm run build | ||
npm run test | ||
``` | ||
## Pending things to implement | ||
Currently, the Wasmer WASI implementation is only able to execute WASI packages and read the stdout. | ||
# What is WebAssembly? | ||
Quoting [the WebAssembly site](https://webassembly.org/): | ||
> WebAssembly (abbreviated Wasm) is a binary instruction format for a | ||
> stack-based virtual machine. Wasm is designed as a portable target | ||
> for compilation of high-level languages like C/C++/Rust, enabling | ||
> deployment on the web for client and server applications. | ||
About speed: | ||
> WebAssembly aims to execute at native speed by taking advantage of | ||
> [common hardware | ||
> capabilities](https://webassembly.org/docs/portability/#assumptions-for-efficient-execution) | ||
> available on a wide range of platforms. | ||
About safety: | ||
> WebAssembly describes a memory-safe, sandboxed [execution | ||
> environment](https://webassembly.org/docs/semantics/#linear-memory) […]. | ||
# License | ||
The entire project is under the MIT License. Please read [the | ||
`LICENSE` file][license]. | ||
[license]: https://github.com/wasmerio/wasmer/blob/master/LICENSE | ||
[Rust]: https://www.rust-lang.org/ | ||
[wasm-pack]: https://rustwasm.github.io/wasm-pack/ | ||
[wabt]: https://github.com/WebAssembly/wabt | ||
[binaryen]: https://github.com/WebAssembly/binaryen |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Native code
Supply chain riskContains native code (e.g., compiled binaries or shared libraries). Including native code can obscure malicious behavior.
Found 2 instances in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
Uses eval
Supply chain riskPackage uses dynamic code execution (e.g., eval()), which is a dangerous practice. This can prevent the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
Mixed license
License(Experimental) Package contains multiple licenses.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
7052055
0
0
22556
184
21
32
7
13
- Removedbrowser-process-hrtime@^1.0.0
- Removedbuffer-es6@^4.9.3
- Removedpath-browserify@^1.0.0
- Removedrandomfill@^1.0.4
- Removedbrowser-process-hrtime@1.0.0(transitive)
- Removedbuffer-es6@4.9.3(transitive)
- Removedpath-browserify@1.0.1(transitive)
- Removedrandombytes@2.1.0(transitive)
- Removedrandomfill@1.0.4(transitive)
- Removedsafe-buffer@5.2.1(transitive)