chore(cli): skip Buffer import if fs is enable (#2779)

This commit is contained in:
LongYinan 2025-07-17 14:10:48 +08:00 committed by GitHub
parent 23a3fec5dc
commit c067e0d7bb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 9 additions and 2 deletions

View File

@ -7,7 +7,11 @@ export const createWasiBrowserBinding = (
buffer = false,
) => {
const fsImport = fs ? `import { memfs } from '@napi-rs/wasm-runtime/fs'` : ''
const bufferImport = buffer ? `import { Buffer } from 'buffer'` : ''
const bufferImport = buffer
? fs
? ``
: `import { Buffer } from 'buffer'`
: ''
const wasiCreation = fs
? `
export const { fs: __fs, vol: __volume } = memfs()

View File

@ -6,6 +6,7 @@ import {
} from '@napi-rs/wasm-runtime'
import { memfs } from '@napi-rs/wasm-runtime/fs'
export const { fs: __fs, vol: __volume } = memfs()
const __wasi = new __WASI({
@ -18,6 +19,7 @@ const __wasi = new __WASI({
const __wasmUrl = new URL('./example.wasm32-wasi.wasm', import.meta.url).href
const __emnapiContext = __emnapiGetDefaultContext()
__emnapiContext.feature.Buffer = Buffer
const __sharedMemory = new WebAssembly.Memory({
initial: 16384,

View File

@ -16,7 +16,8 @@
"wasm": {
"initialMemory": 16384,
"browser": {
"fs": true
"fs": true,
"buffer": true
}
},
"dtsHeader": "type MaybePromise<T> = T | Promise<T>",