Platform agnostic #19

Merged
teidesu merged 25 commits from platform-agnostic into master 2024-03-07 05:54:20 +03:00
2 changed files with 12 additions and 1 deletions
Showing only changes of commit f274dfe857 - Show all commits

View file

@ -2,6 +2,15 @@ import { MtcuteWasmModule, SyncInitInput } from './types.js'
export * 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 wasm!: MtcuteWasmModule
let compressor!: number let compressor!: number
let decompressor!: 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 type WasmInitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module
export async function loadWasmBinary(input?: WasmInitInput): Promise<WebAssembly.Instance> { export async function loadWasmBinary(input?: WasmInitInput): Promise<WebAssembly.Instance> {
if (typeof input === 'undefined') { if (typeof input === 'undefined') {
input = new URL('@mtcute/wasm/mtcute.wasm', import.meta.url) input = getWasmUrl()
} }
if ( if (