-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: compile wasm package for browser (#302)
- Loading branch information
Showing
5 changed files
with
45 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
module.exports.default = ({ orig, file }) => { | ||
if (!file.includes('dist/browser') || orig !== 'require("@lib")') { | ||
if (!file.includes('dist/browser') || orig !== "from '@lib'") { | ||
return orig; | ||
} | ||
|
||
return 'require("@rrule-rust/lib-wasm32-wasi")'; | ||
return "from '@rrule-rust/lib-wasm32-wasi'"; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
diff --git a/node_modules/@napi-rs/wasm-runtime/dist/runtime.js b/node_modules/@napi-rs/wasm-runtime/dist/runtime.js | ||
index e06c158..a23882c 100644 | ||
--- a/node_modules/@napi-rs/wasm-runtime/dist/runtime.js | ||
+++ b/node_modules/@napi-rs/wasm-runtime/dist/runtime.js | ||
@@ -2532,7 +2532,22 @@ function createNapiModule(options) { | ||
} | ||
return str; | ||
} | ||
- return emnapiString.utf8Decoder.decode(((typeof SharedArrayBuffer === "function" && HEAPU8.buffer instanceof SharedArrayBuffer) || (Object.prototype.toString.call(HEAPU8.buffer.constructor) === "[object SharedArrayBuffer]")) ? HEAPU8.slice(ptr, end) : HEAPU8.subarray(ptr, end)); | ||
+ var decodeFromSharedBuffer = (sharedBuffer) => { | ||
+ const decoder = new TextDecoder() | ||
+ const copyLength = sharedBuffer.byteLength | ||
+ | ||
+ const tempBuffer = new ArrayBuffer(copyLength) | ||
+ const tempView = new Uint8Array(tempBuffer) | ||
+ | ||
+ let sharedView = new Uint8Array(sharedBuffer) | ||
+ if (sharedBuffer.byteLength != copyLength) { | ||
+ sharedView = sharedView.subarray(0, copyLength) | ||
+ } | ||
+ tempView.set(sharedView) | ||
+ | ||
+ return decoder.decode(tempBuffer) | ||
+ } | ||
+ return decodeFromSharedBuffer(((typeof SharedArrayBuffer === "function" && HEAPU8.buffer instanceof SharedArrayBuffer) || (Object.prototype.toString.call(HEAPU8.buffer.constructor) === "[object SharedArrayBuffer]")) ? HEAPU8.slice(ptr, end) : HEAPU8.subarray(ptr, end)); | ||
}, | ||
stringToUTF8: function (str, outPtr, maxBytesToWrite) { | ||
var HEAPU8 = new Uint8Array(wasmMemory.buffer); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"compilerOptions": { | ||
"module": "esnext", | ||
"moduleResolution": "bundler" | ||
}, | ||
"extends": "./tsconfig.build.json", | ||
"exclude": ["./src/lib"] | ||
} |