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.
Files changed (2) hide show
  1. package/index.js +36 -41
  2. 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
- let wasmInitialized = false;
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
- // Dynamic import to handle different environments
12
- if (isNode) {
13
- // Node.js environment
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 (!wasmInitialized && !isNode) {
29
- // Initialize WASM for browser
30
- await wasmModule.default();
31
- wasmInitialized = true;
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: wasmModule.StrictNumber,
36
- StrictString: wasmModule.StrictString,
37
- get_memory: wasmModule.get_memory,
38
- HeapType: wasmModule.HeapType,
39
- StrictArray: wasmModule.StrictArray,
40
- StrictForLoop: wasmModule.StrictForLoop,
41
- StrictFunction: wasmModule.StrictFunction,
42
- StrictObject: wasmModule.StrictObject,
43
- Schema: wasmModule.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
- // Export all the named exports directly
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
- } = wasmModule;
53
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "strictjs-runtime",
3
- "version": "2.0.1",
3
+ "version": "2.0.3",
4
4
  "description": "A lightweight low-level runtime for StrictJS with WebAssembly support.",
5
5
  "main": "index.js",
6
6
  "module": "index.js",