strictjs-runtime 2.0.5 → 2.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +21 -12
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
import fs from "fs";
|
|
2
|
-
import path from "path";
|
|
3
|
-
import { fileURLToPath } from "url";
|
|
4
1
|
import initWASM, {
|
|
5
2
|
StrictNumber,
|
|
6
3
|
StrictString,
|
|
@@ -13,21 +10,33 @@ import initWASM, {
|
|
|
13
10
|
Schema
|
|
14
11
|
} from "./pkg/strictjs_runtime.js";
|
|
15
12
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
13
|
+
let nodeInitWASM = null;
|
|
14
|
+
|
|
15
|
+
// Only import `fs` and `path` in Node environment
|
|
16
|
+
if (typeof window === "undefined") {
|
|
17
|
+
const fs = await import("fs");
|
|
18
|
+
const path = await import("path");
|
|
19
|
+
const { fileURLToPath } = await import("url");
|
|
20
|
+
|
|
21
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
22
|
+
const __dirname = path.dirname(__filename);
|
|
23
|
+
|
|
24
|
+
nodeInitWASM = async () => {
|
|
25
|
+
const wasmPath = path.resolve(__dirname, "pkg/strictjs_runtime_bg.wasm");
|
|
26
|
+
const wasmBuffer = fs.readFileSync(wasmPath);
|
|
27
|
+
await initWASM(wasmBuffer);
|
|
28
|
+
};
|
|
29
|
+
}
|
|
19
30
|
|
|
20
31
|
/**
|
|
21
32
|
* Initializes StrictJS Runtime
|
|
22
|
-
* -
|
|
23
|
-
* -
|
|
33
|
+
* - Node: Loads WASM from filesystem
|
|
34
|
+
* - Browser: WASM auto-fetch
|
|
24
35
|
*/
|
|
25
36
|
export default async function strictInit() {
|
|
26
37
|
if (typeof window === "undefined") {
|
|
27
38
|
// Node.js environment
|
|
28
|
-
|
|
29
|
-
const wasmBuffer = fs.readFileSync(wasmPath);
|
|
30
|
-
await initWASM(wasmBuffer);
|
|
39
|
+
await nodeInitWASM();
|
|
31
40
|
} else {
|
|
32
41
|
// Browser environment
|
|
33
42
|
await initWASM();
|
|
@@ -46,7 +55,7 @@ export default async function strictInit() {
|
|
|
46
55
|
};
|
|
47
56
|
}
|
|
48
57
|
|
|
49
|
-
// Named exports
|
|
58
|
+
// Named exports
|
|
50
59
|
export {
|
|
51
60
|
get_memory,
|
|
52
61
|
HeapType,
|