wasmer-pack 0.7.1

A code generator that lets you treat WebAssembly modules like native dependencies.
Documentation
---
source: crates/wasmer-pack/src/js/mod.rs
expression: "files[\"package/src/bindings/index.js\"].utf8_contents().unwrap()"
---
const fs = require("fs/promises");
const { WasmerPack: _WasmerPack } = require("./wasmer-pack/wasmer-pack.js");
const { addBrowserToImports: _WasmerPack__addBrowserToImports } = require("./wasmer-pack/browser.js");

class Bindings {
    constructor() {
        this._cache = {}
    }

    /** Lazily fetch and compile the WebAssembly module */
    async _getModule(filename) {
        if (filename in this._cache) {
            return this._cache[filename];
        }

        const wasm = await fs.readFile(`${__dirname}/${filename}`);
        this._cache[filename] = await WebAssembly.compile(wasm);
        return this._cache[filename];
    }
    async wasmer_pack(browser, options) {
        const wrapper = new _WasmerPack();
        const module = await this._getModule("wasmer-pack/wasmer_pack_wasm.wasm");
        const imports = options?.imports || {};
        _WasmerPack__addBrowserToImports(
            browser,
            name => wrapper.exports[name],
        );

        await wrapper.instantiate(module, imports);

        return wrapper;
    }
}

module.exports = { Bindings };