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