How to use @wasmer/wasi - 6 common examples

To help you get started, we’ve selected a few @wasmer/wasi examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github wasmerio / wasmer-js / packages / cli / src / commands / run.ts View on Github external
}
    let wasiArgs = this.argv.filter((arg: string) => {
      if (arg.startsWith("--dir")) {
        return false;
      }
      return true;
    });
    // wasiArgs = [`wasmer-js run ${wasiArgs[0]}`, ...wasiArgs.splice(1)];

    // If we find a `--`, we try to get only the arguments after
    const indexLimit = wasiArgs.indexOf("--");
    if (indexLimit > 0) {
      wasiArgs = [wasiArgs[0], ...wasiArgs.splice(indexLimit + 1)];
    }

    const wasi = new WASI({
      args: wasiArgs,
      bindings: {
        ...nodeBindings,
        fs
      },
      env: {},
      preopens
    });

    const wasmBytes = fs.readFileSync(args.file);
    const transformedBytes = await lowerI64Imports(wasmBytes);
    const { instance } = await WebAssembly.instantiate(transformedBytes, {
      wasi_unstable: wasi.wasiImport
    });
    wasi.start(instance);
  }
github wasmerio / wasmer-js / examples / wasm-shell / components / wasm-terminal.tsx View on Github external
// @ts-ignore
import WasmTerminal, {
  // @ts-ignore
  fetchCommandFromWAPM
  // @ts-ignore
} from "@wasmer/wasm-terminal";

import { WASI } from "@wasmer/wasi";
import BrowserWASIBindings from "@wasmer/wasi/bindings/browser";
// @ts-ignore
import { lowerI64Imports } from "@wasmer/wasm-transformer";

import welcomeMessage from "./welcome-message";
import { WasmFs } from "@wasmer/wasmfs";

WASI.defaultBindings = BrowserWASIBindings;

const commands = {
  callback: (options: any, wasmFs: any) => {
    let myArr = new Uint8Array(1024);
    let stdin = wasmFs.fs.readSync(0, myArr, 0, 1024, 0);
    return Promise.resolve(
      `Callback Command Working! Options: ${options}, stdin: ${myArr}`
    );
  }
};

let didInitWasmTransformer = false;
const fetchCommandHandler = async (
  commandName: string,
  commandArgs?: Array,
  envEntries?: any[][]
github DigitalArsenal / openssl.js / src / command.js View on Github external
/**
 * ECMAScript Interface to WASM port of OpenSSL (https://www.openssl.org)
 * @module OpenSSL
 * 
 * @license Apache-2.0
 * @copyright 2019 DIGITALARSENAL.IO, INC.
 */

import _WASI from "@wasmer/wasi";
const WASI = isNode ? _WASI.WASI : _WASI; //module issue
import { isNode } from "./isNode.js";

export const run = async args => {
  let _filename;
  try {
    _filename = __filename
  } catch (e) {

  }
  if (isNode && !_filename) {
    const { fileURLToPath } = await import("url"); //SyntaxError: Parenthesized pattern ({fileURLToPath})
    _filename = fileURLToPath(import.meta.url);
  }

  let command = ["openssl"].concat(
    args.command.split(/[\s]{1,}/g).filter(Boolean)
github wasmerio / wasmer-js / packages / wasm-terminal / src / command / wasi-command.ts View on Github external
async run(wasmFs: WasmFs) {
    const wasi = new WASI({
      preopens: {
        "/": "/"
      },
      env: this.options.env,
      args: this.options.args,
      bindings: {
        ...WASI.defaultBindings,
        fs: wasmFs.fs
      }
    });

    let instance = await WebAssembly.instantiate(
      this.options.module as WebAssembly.Module,
      {
        wasi_unstable: wasi.wasiImport
      }
github wasmerio / wasmer-js / examples / wasm-shell / worker.ts View on Github external
import processWorker from "@wasmer/wasm-terminal/workers/process.worker";
import { WASI } from "@wasmer/wasi";
import BrowserWASIBindings from "@wasmer/wasi/bindings/browser";

WASI.defaultBindings = BrowserWASIBindings;

export default processWorker;
github wasmerio / wasmer-js / packages / wasm-terminal / src / command / wasi-command.ts View on Github external
async run(wasmFs: WasmFs) {
    const wasi = new WASI({
      preopens: {
        "/": "/"
      },
      env: this.options.env,
      args: this.options.args,
      bindings: {
        ...WASI.defaultBindings,
        fs: wasmFs.fs
      }
    });

    let instance = await WebAssembly.instantiate(
      this.options.module as WebAssembly.Module,
      {
        wasi_unstable: wasi.wasiImport
      }
    );
    wasi.start(instance);
  }
}

@wasmer/wasi

Isomorphic Javascript library for interacting with WASI Modules in Node.js and the Browser.

MIT
Latest version published 2 years ago

Package Health Score

69 / 100
Full package analysis