fix(cli): wrong wasm file name with --platform flag ()

This commit is contained in:
LongYinan 2023-11-08 20:08:28 +08:00 committed by GitHub
parent 6ec46b749e
commit 8ddd35c788
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 40 additions and 39 deletions

View file

@ -481,7 +481,7 @@ class Builder {
})
}
await this.copyArtifact()
const dest = await this.copyArtifact()
// only for cdylib
if (this.cdyLibName) {
@ -505,7 +505,7 @@ class Builder {
const jsOutput = await this.writeJsBinding(idents)
const wasmOutput = await this.writeWasiBinding(
wasiRegisterFunctions,
jsOutput?.path ?? 'index',
dest ?? 'index.wasm',
idents,
)
if (jsOutput) {
@ -543,6 +543,7 @@ class Builder {
kind: dest.endsWith('.node') ? 'node' : 'exe',
path: dest,
})
return dest
} catch (e) {
throw new Error('Failed to copy artifact', {
cause: e,
@ -656,7 +657,7 @@ class Builder {
) {
if (distFileName && wasiRegisterFunctions.length) {
const { name, dir } = parse(distFileName)
const newPath = join(dir, `${name}.wasi.mjs`)
const newPath = join(dir, `${this.config.binaryName}.wasi.mjs`)
const workerPath = join(dir, 'wasi-worker.mjs')
const declareCodes = `const { ${idents.join(', ')} } = binding\n`
const exportsCode = `export {\n${idents
@ -664,7 +665,7 @@ class Builder {
.join(',\n')}\n}`
await writeFileAsync(
newPath,
createWasiBinding(this.config.binaryName, wasiRegisterFunctions) +
createWasiBinding(name, wasiRegisterFunctions) +
declareCodes +
exportsCode +
'\n',

View file

@ -1,5 +1,5 @@
export const createWasiBinding = (
localName: string,
wasmFileName: string,
wasiRegisterFunctions: string[],
) => `/* eslint-disable */
/* prettier-ignore */
@ -32,7 +32,7 @@ const __sharedMemory = new WebAssembly.Memory({
shared: true,
})
const { instance: __napiInstance, module: __wasiModule, napiModule: __napiModule } = await __emnapiInstantiateNapiModule(__nodeFsPromises.readFile(__nodePath.join(__dirname, '${localName}.wasi-wasm32.wasm')), {
const { instance: __napiInstance, module: __wasiModule, napiModule: __napiModule } = await __emnapiInstantiateNapiModule(__nodeFsPromises.readFile(__nodePath.join(__dirname, '${wasmFileName}.wasm')), {
context: __emnapiContext,
asyncWorkPoolSize: 4,
wasi: __wasi,