strictjs-runtime 1.0.2 → 1.0.3
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 +28 -2
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
import
|
|
1
|
+
import fs from "fs";
|
|
2
|
+
import path from "path";
|
|
3
|
+
import { fileURLToPath } from "url";
|
|
4
|
+
import initWasm, {
|
|
2
5
|
get_memory,
|
|
3
6
|
HeapType,
|
|
4
7
|
StrictArray,
|
|
@@ -7,8 +10,22 @@ import init, {
|
|
|
7
10
|
StrictObject
|
|
8
11
|
} from "./pkg/strictjs_runtime.js";
|
|
9
12
|
|
|
13
|
+
// Handle __dirname for ES modules
|
|
14
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
15
|
+
const __dirname = path.dirname(__filename);
|
|
16
|
+
|
|
10
17
|
export default async function strictInit() {
|
|
11
|
-
|
|
18
|
+
// Check if running in Node.js
|
|
19
|
+
if (typeof window === "undefined" && typeof process !== "undefined") {
|
|
20
|
+
// Node.js environment
|
|
21
|
+
const wasmPath = path.resolve(__dirname, "pkg/strictjs_runtime_bg.wasm");
|
|
22
|
+
const wasmBuffer = fs.readFileSync(wasmPath);
|
|
23
|
+
await initWasm(wasmBuffer);
|
|
24
|
+
} else {
|
|
25
|
+
// Browser environment
|
|
26
|
+
await initWasm();
|
|
27
|
+
}
|
|
28
|
+
|
|
12
29
|
return {
|
|
13
30
|
get_memory,
|
|
14
31
|
HeapType,
|
|
@@ -18,3 +35,12 @@ export default async function strictInit() {
|
|
|
18
35
|
StrictObject
|
|
19
36
|
};
|
|
20
37
|
}
|
|
38
|
+
|
|
39
|
+
export {
|
|
40
|
+
get_memory,
|
|
41
|
+
HeapType,
|
|
42
|
+
StrictArray,
|
|
43
|
+
StrictForLoop,
|
|
44
|
+
StrictFunction,
|
|
45
|
+
StrictObject
|
|
46
|
+
};
|