microsoft/vscode-oniguruma

Webpack Usage?

zevisert opened this issue · 7 comments

I'm trying to bundle my extension into a single file, as recommended by the vscode extension docs.

I'm running into problems with this library's requirement of calling loadWASM to instantiate a wasm module. I can already use webpack 5's built-in wasm module loader, but there's no way for me to provide an instantiated wasm module back to this library.

It would be great if I could set onigBinding myself.

Or better yet, it would be great to be able to pass my own WASMLoader; then regardless of how consumers of this package are bundling, they always have a way to provide their own WebAssembly.WebAssemblyInstantiatedSource, even if it's just by Promise.resolve.

The idea of loadWASM was that the embedder can control how they want to load the WASM. Either by passing in an ArrayBuffer or a browser Response for streaming compilation of the WASM.

If that is not sufficient and you want to allow passing in a WASMLoader ((importObject: Record<string, Record<string, WebAssembly.ImportValue>> | undefined) => Promise<WebAssembly.WebAssemblyInstantiatedSource>), then PR welcome. It can probably be added as an optional in the IOptions

I think that'd work great, I'll come up with a PR in the next few days!

Could someone kindly clarify how to get the URL to onig.wasm?

Do I need to hack it with require.getConfig().baseUrl?

^ "Solved" that:

A working webpack+typescript config if one cannot use fetch or import the wasm - zikaari/onigasm#2 (comment).

Hopefully this puts any and all environment limitation issues to rest

I was able to load the .wasm file using VSCode's built-in file system manager

const uri = vscode.Uri.joinPath(context.extensionUri, 'node_modules', 'vscode-oniguruma', 'release', 'onig.wasm');
const wasm = await vscode.workspace.fs.readFile(uri);
const options: vscodeOniguruma.IDataOptions = {
	data: wasm,
	print(string: string) {
		console.log(string);
	}
}
await vscodeOniguruma.loadWASM(options);

(make sure the node module is packaged in the extension. or just copy the onig.wasm file)

"dependencies": { "vscode-oniguruma": "1.7.0" }