strictjs-runtime 2.0.6 → 2.0.7

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 +11 -6
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -12,8 +12,10 @@ import initWASM, {
12
12
 
13
13
  let nodeInitWASM = null;
14
14
 
15
- // Only import `fs` and `path` in Node environment
16
- if (typeof window === "undefined") {
15
+ /**
16
+ * This function dynamically loads WASM in Node.js
17
+ */
18
+ async function setupNodeLoader() {
17
19
  const fs = await import("fs");
18
20
  const path = await import("path");
19
21
  const { fileURLToPath } = await import("url");
@@ -21,13 +23,18 @@ if (typeof window === "undefined") {
21
23
  const __filename = fileURLToPath(import.meta.url);
22
24
  const __dirname = path.dirname(__filename);
23
25
 
24
- nodeInitWASM = async () => {
26
+ return async () => {
25
27
  const wasmPath = path.resolve(__dirname, "pkg/strictjs_runtime_bg.wasm");
26
28
  const wasmBuffer = fs.readFileSync(wasmPath);
27
29
  await initWASM(wasmBuffer);
28
30
  };
29
31
  }
30
32
 
33
+ // Lazy initialize Node loader if in Node.js environment
34
+ if (typeof window === "undefined") {
35
+ nodeInitWASM = await setupNodeLoader();
36
+ }
37
+
31
38
  /**
32
39
  * Initializes StrictJS Runtime
33
40
  * - Node: Loads WASM from filesystem
@@ -35,11 +42,9 @@ if (typeof window === "undefined") {
35
42
  */
36
43
  export default async function strictInit() {
37
44
  if (typeof window === "undefined") {
38
- // Node.js environment
39
45
  await nodeInitWASM();
40
46
  } else {
41
- // Browser environment
42
- await initWASM();
47
+ await initWASM(); // Browser automatically fetches the `.wasm` file
43
48
  }
44
49
 
45
50
  return {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "strictjs-runtime",
3
- "version": "2.0.6",
3
+ "version": "2.0.7",
4
4
  "description": "A lightweight low-level runtime for StrictJS with WebAssembly support.",
5
5
  "main": "index.js",
6
6
  "module": "index.js",