Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@wasmer/wasi

Package Overview
Dependencies
Maintainers
1
Versions
44
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@wasmer/wasi - npm Package Compare versions

Comparing version 0.12.0 to 1.0.0

Cargo.lock

88

package.json
{
"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"
}

@@ -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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc