fix(cli): non-fs polyfilled browser worker binding (#2067)
This commit is contained in:
parent
da31e367e1
commit
3e44ae3c16
1 changed files with 21 additions and 9 deletions
|
@ -65,16 +65,13 @@ globalThis.onmessage = function (e) {
|
|||
|
||||
export const createWasiBrowserWorkerBinding = (fs: boolean) => {
|
||||
const fsImport = fs
|
||||
? `import { memfsExported as __memfsExported } from '@napi-rs/wasm-runtime/fs'
|
||||
? `import { instantiateNapiModuleSync, MessageHandler, WASI, createFsProxy } from '@napi-rs/wasm-runtime'
|
||||
import { memfsExported as __memfsExported } from '@napi-rs/wasm-runtime/fs'
|
||||
|
||||
const fs = createFsProxy(__memfsExported)`
|
||||
: '\nconst fs = null'
|
||||
return `import { instantiateNapiModuleSync, MessageHandler, WASI, createFsProxy } from '@napi-rs/wasm-runtime'
|
||||
${fsImport}
|
||||
|
||||
const handler = new MessageHandler({
|
||||
onLoad({ wasmModule, wasmMemory }) {
|
||||
const wasi = new WASI({
|
||||
: `import { instantiateNapiModuleSync, MessageHandler, WASI } from '@napi-rs/wasm-runtime'`
|
||||
const wasiCreation = fs
|
||||
? `const wasi = new WASI({
|
||||
fs,
|
||||
preopens: {
|
||||
'/': '/',
|
||||
|
@ -87,7 +84,22 @@ const handler = new MessageHandler({
|
|||
// eslint-disable-next-line no-console
|
||||
console.error.apply(console, arguments)
|
||||
},
|
||||
})
|
||||
})`
|
||||
: `const wasi = new WASI({
|
||||
print: function () {
|
||||
// eslint-disable-next-line no-console
|
||||
console.log.apply(console, arguments)
|
||||
},
|
||||
printErr: function() {
|
||||
// eslint-disable-next-line no-console
|
||||
console.error.apply(console, arguments)
|
||||
},
|
||||
})`
|
||||
return `${fsImport}
|
||||
|
||||
const handler = new MessageHandler({
|
||||
onLoad({ wasmModule, wasmMemory }) {
|
||||
${wasiCreation}
|
||||
return instantiateNapiModuleSync(wasmModule, {
|
||||
childThread: true,
|
||||
wasi,
|
||||
|
|
Loading…
Reference in a new issue