strictjs-runtime 2.0.2 → 2.0.4
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 +10 -21
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
|
|
2
|
+
import fs from "fs";
|
|
3
|
+
import path from "path";
|
|
4
|
+
import { fileURLToPath } from "url";
|
|
2
5
|
import initWASM, {
|
|
3
6
|
StrictNumber,
|
|
4
7
|
StrictString,
|
|
@@ -11,34 +14,21 @@ import initWASM, {
|
|
|
11
14
|
Schema
|
|
12
15
|
} from "./pkg/strictjs_runtime.js";
|
|
13
16
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
* Initialize StrictJS Runtime.
|
|
18
|
-
* Works in both Node.js and Browser.
|
|
19
|
-
*/
|
|
20
|
-
export async function initStrict() {
|
|
21
|
-
if (wasmInitialized) return { StrictNumber, StrictString, get_memory, HeapType, StrictArray, StrictForLoop, StrictFunction, StrictObject, Schema };
|
|
17
|
+
// Handle __dirname for ES modules
|
|
18
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
19
|
+
const __dirname = path.dirname(__filename);
|
|
22
20
|
|
|
23
|
-
|
|
21
|
+
export default async function strictInit() {
|
|
24
22
|
if (typeof window === "undefined") {
|
|
25
|
-
|
|
26
|
-
const path = await import("path");
|
|
27
|
-
const url = await import("url");
|
|
28
|
-
|
|
29
|
-
const __filename = url.fileURLToPath(import.meta.url);
|
|
30
|
-
const __dirname = path.dirname(__filename);
|
|
23
|
+
// Node.js environment: load WASM manually
|
|
31
24
|
const wasmPath = path.resolve(__dirname, "pkg/strictjs_runtime_bg.wasm");
|
|
32
25
|
const wasmBuffer = fs.readFileSync(wasmPath);
|
|
33
|
-
|
|
34
26
|
await initWASM(wasmBuffer);
|
|
35
27
|
} else {
|
|
36
|
-
// Browser environment: fetch automatically
|
|
28
|
+
// Browser environment: let it fetch automatically
|
|
37
29
|
await initWASM();
|
|
38
30
|
}
|
|
39
31
|
|
|
40
|
-
wasmInitialized = true;
|
|
41
|
-
|
|
42
32
|
return {
|
|
43
33
|
StrictNumber,
|
|
44
34
|
StrictString,
|
|
@@ -52,7 +42,6 @@ export async function initStrict() {
|
|
|
52
42
|
};
|
|
53
43
|
}
|
|
54
44
|
|
|
55
|
-
// Re-export types for convenience
|
|
56
45
|
export {
|
|
57
46
|
get_memory,
|
|
58
47
|
HeapType,
|