From 3f34a9eb71c5d840b12cc1701e1c4764f2d1df8f Mon Sep 17 00:00:00 2001 From: Zixuan Chen Date: Sat, 16 Nov 2024 20:11:05 +0800 Subject: [PATCH] chore: fix base64 build in cloudflare worker --- crates/loro-wasm/CHANGELOG.md | 6 ++++++ crates/loro-wasm/package.json | 2 +- crates/loro-wasm/scripts/post-rollup.ts | 13 +++++++++---- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/crates/loro-wasm/CHANGELOG.md b/crates/loro-wasm/CHANGELOG.md index 5242a6ee..4b9db5a2 100644 --- a/crates/loro-wasm/CHANGELOG.md +++ b/crates/loro-wasm/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog +## 1.1.3-alpha.0 + +### Patch Changes + +- Chore fix base64 built target in cloudflare worker + ## 1.1.2 ### Patch Changes diff --git a/crates/loro-wasm/package.json b/crates/loro-wasm/package.json index 2af53be3..03d49ac2 100644 --- a/crates/loro-wasm/package.json +++ b/crates/loro-wasm/package.json @@ -1,6 +1,6 @@ { "name": "loro-crdt", - "version": "1.1.2", + "version": "1.1.3-alpha.0", "description": "Loro CRDTs is a high-performance CRDT framework that makes your app state synchronized, collaborative and maintainable effortlessly.", "keywords": [ "crdt", diff --git a/crates/loro-wasm/scripts/post-rollup.ts b/crates/loro-wasm/scripts/post-rollup.ts index 5304a22e..f26b3bc2 100644 --- a/crates/loro-wasm/scripts/post-rollup.ts +++ b/crates/loro-wasm/scripts/post-rollup.ts @@ -75,10 +75,15 @@ async function rollupBase64() { /\{\s*const wkmod = await import\('\.\/loro_wasm_bg-([^']+)\.js'\);\s*const instance = new WebAssembly\.Instance\(wkmod\.default, \{\s*"\.\/loro_wasm_bg\.js": imports,\s*\}\);\s*__wbg_set_wasm\(instance\.exports\);\s*\}/; const toReplaceTarget = ` import loro_wasm_bg_js from './loro_wasm_bg-$1.js'; -const instance = new WebAssembly.Instance(loro_wasm_bg_js(), { - "./loro_wasm_bg.js": imports, -}); -__wbg_set_wasm(instance.exports); +if (wasm.__wbindgen_start) { + imports.__wbg_set_wasm(loro_wasm_bg_js()); + wasm.__wbindgen_start(); +} else { + const instance = new WebAssembly.Instance(loro_wasm_bg_js(), { + "./loro_wasm_bg.js": imports, + }); + __wbg_set_wasm(instance.exports); +} `; const base64IndexPath = "./base64/index.js"; const content = await Deno.readTextFile(base64IndexPath);