strictjs-runtime 2.0.4 → 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.
Files changed (2) hide show
  1. package/index.js +25 -11
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -1,7 +1,3 @@
1
-
2
- import fs from "fs";
3
- import path from "path";
4
- import { fileURLToPath } from "url";
5
1
  import initWASM, {
6
2
  StrictNumber,
7
3
  StrictString,
@@ -14,18 +10,35 @@ import initWASM, {
14
10
  Schema
15
11
  } from "./pkg/strictjs_runtime.js";
16
12
 
17
- // Handle __dirname for ES modules
18
- const __filename = fileURLToPath(import.meta.url);
19
- const __dirname = path.dirname(__filename);
13
+ let nodeInitWASM = null;
20
14
 
21
- export default async function strictInit() {
22
- if (typeof window === "undefined") {
23
- // Node.js environment: load WASM manually
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 () => {
24
25
  const wasmPath = path.resolve(__dirname, "pkg/strictjs_runtime_bg.wasm");
25
26
  const wasmBuffer = fs.readFileSync(wasmPath);
26
27
  await initWASM(wasmBuffer);
28
+ };
29
+ }
30
+
31
+ /**
32
+ * Initializes StrictJS Runtime
33
+ * - Node: Loads WASM from filesystem
34
+ * - Browser: WASM auto-fetch
35
+ */
36
+ export default async function strictInit() {
37
+ if (typeof window === "undefined") {
38
+ // Node.js environment
39
+ await nodeInitWASM();
27
40
  } else {
28
- // Browser environment: let it fetch automatically
41
+ // Browser environment
29
42
  await initWASM();
30
43
  }
31
44
 
@@ -42,6 +55,7 @@ export default async function strictInit() {
42
55
  };
43
56
  }
44
57
 
58
+ // Named exports
45
59
  export {
46
60
  get_memory,
47
61
  HeapType,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "strictjs-runtime",
3
- "version": "2.0.4",
3
+ "version": "2.0.6",
4
4
  "description": "A lightweight low-level runtime for StrictJS with WebAssembly support.",
5
5
  "main": "index.js",
6
6
  "module": "index.js",