Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
}
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);
}
// @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[][]
/**
* 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)
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
}
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;
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);
}
}