fix(cli): missing files in created wasi package (#1894)
This commit is contained in:
parent
ffbaba3a9b
commit
9b8dab6b63
9 changed files with 35 additions and 61 deletions
|
@ -137,7 +137,7 @@ export async function collectArtifacts(userOptions: ArtifactsOptions) {
|
|||
)}] to [${colors.yellowBright(wasiDir)}]`,
|
||||
)
|
||||
await writeFileAsync(
|
||||
join(wasiDir, `wasi-worker-browser.js`),
|
||||
join(wasiDir, `wasi-worker-browser.mjs`),
|
||||
await readFileAsync(browserWorkerFile),
|
||||
)
|
||||
}
|
||||
|
|
|
@ -88,10 +88,16 @@ export async function createNpmDirs(userOptions: CreateNpmDirsOptions) {
|
|||
scopedPackageJson.os = [target.platform]
|
||||
} else {
|
||||
const entry = `${binaryName}.wasi.cjs`
|
||||
scopedPackageJson.files.push(entry, `wasi-worker.mjs`)
|
||||
scopedPackageJson.main = entry
|
||||
// @ts-expect-error
|
||||
scopedPackageJson.browser = `${binaryName}.wasi-browser.js`
|
||||
scopedPackageJson.files.push(
|
||||
entry,
|
||||
// @ts-expect-error
|
||||
scopedPackageJson.browser,
|
||||
`wasi-worker.mjs`,
|
||||
`wasi-worker-browser.mjs`,
|
||||
)
|
||||
let needRestrictNodeVersion = true
|
||||
if (scopedPackageJson.engines?.node) {
|
||||
try {
|
||||
|
|
|
@ -27,7 +27,7 @@ const __sharedMemory = new WebAssembly.Memory({
|
|||
shared: true,
|
||||
})
|
||||
|
||||
let __wasmFile = await fetch(__wasmUrl).then((res) => res.arrayBuffer())
|
||||
const __wasmFile = await fetch(__wasmUrl).then((res) => res.arrayBuffer())
|
||||
|
||||
const {
|
||||
instance: __napiInstance,
|
||||
|
|
|
@ -55,15 +55,20 @@ export const WASI_WORKER_BROWSER_TEMPLATE = `import { instantiateNapiModuleSync,
|
|||
import { WASI } from '@tybys/wasm-util'
|
||||
import { Volume, createFsFromVolume } from 'memfs-browser'
|
||||
|
||||
const fs = createFsFromVolume(Volume.fromJSON({
|
||||
'/': null
|
||||
}))
|
||||
const fs = createFsFromVolume(
|
||||
Volume.fromJSON({
|
||||
'/': null,
|
||||
}),
|
||||
)
|
||||
|
||||
const handler = new MessageHandler({
|
||||
onLoad({ wasmModule, wasmMemory }) {
|
||||
const wasi = new WASI({
|
||||
fs,
|
||||
print: function() { console.log.apply(console, arguments) }
|
||||
print: function () {
|
||||
// eslint-disable-next-line no-console
|
||||
console.log.apply(console, arguments)
|
||||
},
|
||||
})
|
||||
return instantiateNapiModuleSync(wasmModule, {
|
||||
childThread: true,
|
||||
|
@ -73,14 +78,14 @@ const handler = new MessageHandler({
|
|||
...importObject.env,
|
||||
...importObject.napi,
|
||||
...importObject.emnapi,
|
||||
memory: wasmMemory
|
||||
memory: wasmMemory,
|
||||
}
|
||||
}
|
||||
},
|
||||
})
|
||||
}
|
||||
},
|
||||
})
|
||||
|
||||
globalThis.onmessage = function(e) {
|
||||
globalThis.onmessage = function (e) {
|
||||
handler.handle(e)
|
||||
}
|
||||
`
|
||||
|
|
4
examples/napi/index.d.ts
vendored
4
examples/napi/index.d.ts
vendored
|
@ -498,10 +498,6 @@ export function runScript(script: string): unknown
|
|||
|
||||
export function setSymbolInObj(symbol: symbol): object
|
||||
|
||||
export interface Shared {
|
||||
value: number
|
||||
}
|
||||
|
||||
export const enum Status {
|
||||
Pristine = 'Pristine',
|
||||
Loading = 'Loading',
|
||||
|
|
|
@ -27,7 +27,7 @@ const __sharedMemory = new WebAssembly.Memory({
|
|||
shared: true,
|
||||
})
|
||||
|
||||
let __wasmFile = await fetch(__wasmUrl).then((res) => res.arrayBuffer())
|
||||
const __wasmFile = await fetch(__wasmUrl).then((res) => res.arrayBuffer())
|
||||
|
||||
const {
|
||||
instance: __napiInstance,
|
||||
|
@ -57,7 +57,6 @@ const {
|
|||
})
|
||||
|
||||
function __napi_rs_initialize_modules(__napiInstance) {
|
||||
__napiInstance.exports['__napi_register__Shared_struct_0']?.()
|
||||
__napiInstance.exports['__napi_register__DEFAULT_COST_0']?.()
|
||||
__napiInstance.exports['__napi_register__TYPE_SKIPPED_CONST_1']?.()
|
||||
__napiInstance.exports['__napi_register__get_words_2']?.()
|
||||
|
|
|
@ -70,7 +70,6 @@ const { instance: __napiInstance, module: __wasiModule, napiModule: __napiModule
|
|||
})
|
||||
|
||||
function __napi_rs_initialize_modules(__napiInstance) {
|
||||
__napiInstance.exports['__napi_register__Shared_struct_0']?.()
|
||||
__napiInstance.exports['__napi_register__DEFAULT_COST_0']?.()
|
||||
__napiInstance.exports['__napi_register__TYPE_SKIPPED_CONST_1']?.()
|
||||
__napiInstance.exports['__napi_register__get_words_2']?.()
|
||||
|
|
|
@ -1,36 +0,0 @@
|
|||
import { instantiateNapiModuleSync, MessageHandler } from '@emnapi/core'
|
||||
import { WASI } from '@tybys/wasm-util'
|
||||
import { Volume, createFsFromVolume } from 'memfs-browser'
|
||||
|
||||
const fs = createFsFromVolume(
|
||||
Volume.fromJSON({
|
||||
'/': null,
|
||||
}),
|
||||
)
|
||||
|
||||
const handler = new MessageHandler({
|
||||
onLoad({ wasmModule, wasmMemory }) {
|
||||
const wasi = new WASI({
|
||||
fs,
|
||||
print: function () {
|
||||
console.log.apply(console, arguments)
|
||||
},
|
||||
})
|
||||
return instantiateNapiModuleSync(wasmModule, {
|
||||
childThread: true,
|
||||
wasi,
|
||||
overwriteImports(importObject) {
|
||||
importObject.env = {
|
||||
...importObject.env,
|
||||
...importObject.napi,
|
||||
...importObject.emnapi,
|
||||
memory: wasmMemory,
|
||||
}
|
||||
},
|
||||
})
|
||||
},
|
||||
})
|
||||
|
||||
globalThis.onmessage = function (e) {
|
||||
handler.handle(e)
|
||||
}
|
|
@ -2,15 +2,20 @@ import { instantiateNapiModuleSync, MessageHandler } from '@emnapi/core'
|
|||
import { WASI } from '@tybys/wasm-util'
|
||||
import { Volume, createFsFromVolume } from 'memfs-browser'
|
||||
|
||||
const fs = createFsFromVolume(Volume.fromJSON({
|
||||
'/': null
|
||||
}))
|
||||
const fs = createFsFromVolume(
|
||||
Volume.fromJSON({
|
||||
'/': null,
|
||||
}),
|
||||
)
|
||||
|
||||
const handler = new MessageHandler({
|
||||
onLoad({ wasmModule, wasmMemory }) {
|
||||
const wasi = new WASI({
|
||||
fs,
|
||||
print: function() { console.log.apply(console, arguments) }
|
||||
print: function() {
|
||||
// eslint-disable-next-line no-console
|
||||
console.log.apply(console, arguments)
|
||||
},
|
||||
})
|
||||
return instantiateNapiModuleSync(wasmModule, {
|
||||
childThread: true,
|
||||
|
@ -20,11 +25,11 @@ const handler = new MessageHandler({
|
|||
...importObject.env,
|
||||
...importObject.napi,
|
||||
...importObject.emnapi,
|
||||
memory: wasmMemory
|
||||
memory: wasmMemory,
|
||||
}
|
||||
}
|
||||
},
|
||||
})
|
||||
}
|
||||
},
|
||||
})
|
||||
|
||||
globalThis.onmessage = function(e) {
|
||||
|
|
Loading…
Reference in a new issue