Preview2 Shim
WASI Preview2 implementations for Node.js & browsers.
Node.js support is fully tested and conformant against the Wasmtime test suite.
Browser support is considered experimental, and not currently suitable for production applications.
Features
WASI Shim object for easy instantiation
An default instantiation object can be used via the WASIShim
class in @bytecodealliance/preview2-shim/instantiation
:
import { WASIShim } from '@bytecodealliance/preview2-shim/instantiation';
import type {
VersionedWASIImportObject,
WASIImportObject,
} from '@bytecodealliance/preview2-shim/instantiation';
const shim = new WASIShim();
const unversioned: WASIImportObject = shim.getImportObject();
unversioned satisfies WASIImportObject;
unversioned satisfies VersionedWASIImportObject<''>;
const versioned: VersionedWASIImportObject<'0.2.3'> = shim.getImportObject({
asVersion: '0.2.3',
});
versioned satisfies VersionedWASIImportObject<'0.2.3'>;
The import object generated by getImportObject
can be easily used in instantiate()
calls
produced by jco transpile
(with --instantiation=async
):
import { WASIShim } from '@bytecodealliance/preview2-shim/instantiation';
import { instantiate } from './dist/transpiled/component.js';
const loader = async (path: string) => {
const buf = await readFile(`./dist/transpiled/${path}`);
return await WebAssembly.compile(buf.buffer as ArrayBuffer);
};
const component = await instantiate(loader, new WASIShim().getImportObject());
License
This project is licensed under the Apache 2.0 license with the LLVM exception.
See LICENSE for more details.
Contribution
Unless you explicitly state otherwise, any contribution intentionally submitted
for inclusion in this project by you, as defined in the Apache-2.0 license,
shall be licensed as above, without any additional terms or conditions.