fix(core): use workaround for wasm loading

This commit is contained in:
alina 🌸 2024-03-04 03:58:23 +03:00
parent 14549020aa
commit f274dfe857
Signed by: teidesu
SSH key fingerprint: SHA256:uNeCpw6aTSU4aIObXLvHfLkDa82HWH9EiOj9AXOIRpI
2 changed files with 12 additions and 1 deletions

View file

@ -2,6 +2,15 @@ import { MtcuteWasmModule, SyncInitInput } from './types.js'
export * from './types.js'
export function getWasmUrl(): URL {
// would be nice if we could just use `new URL('@mtcute/wasm/mtcute.wasm', import.meta.url)`
// wherever this is used, but vite does some funky stuff with transitive dependencies
// making it not work. probably related to https://github.com/vitejs/vite/issues/8427,
// but asking the user to deoptimize the entire @mtcute/web is definitely not a good idea
// so we'll just use this hack for now
return new URL('../mtcute.wasm', import.meta.url)
}
let wasm!: MtcuteWasmModule
let compressor!: number
let decompressor!: number

View file

@ -1,8 +1,10 @@
import { getWasmUrl } from '@mtcute/wasm'
export type WasmInitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module
export async function loadWasmBinary(input?: WasmInitInput): Promise<WebAssembly.Instance> {
if (typeof input === 'undefined') {
input = new URL('@mtcute/wasm/mtcute.wasm', import.meta.url)
input = getWasmUrl()
}
if (