strictjs-runtime 2.0.1 → 2.0.2

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 +46 -40
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -1,53 +1,59 @@
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;
1
+ // index.js
2
+ import initWASM, {
3
+ StrictNumber,
4
+ StrictString,
5
+ get_memory,
6
+ HeapType,
7
+ StrictArray,
8
+ StrictForLoop,
9
+ StrictFunction,
10
+ StrictObject,
11
+ Schema
12
+ } from "./pkg/strictjs_runtime.js";
8
13
 
9
14
  let wasmInitialized = false;
10
15
 
11
- // Dynamic import to handle different environments
12
- if (isNode) {
16
+ /**
17
+ * Initialize StrictJS Runtime.
18
+ * Works in both Node.js and Browser.
19
+ */
20
+ export async function initStrict() {
21
+ if (wasmInitialized) return { StrictNumber, StrictString, get_memory, HeapType, StrictArray, StrictForLoop, StrictFunction, StrictObject, Schema };
22
+
13
23
  // 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
- }
24
+ if (typeof window === "undefined") {
25
+ const fs = await import("fs");
26
+ const path = await import("path");
27
+ const url = await import("url");
28
+
29
+ const __filename = url.fileURLToPath(import.meta.url);
30
+ const __dirname = path.dirname(__filename);
31
+ const wasmPath = path.resolve(__dirname, "pkg/strictjs_runtime_bg.wasm");
32
+ const wasmBuffer = fs.readFileSync(wasmPath);
26
33
 
27
- export default async function strictInit() {
28
- if (!wasmInitialized && !isNode) {
29
- // Initialize WASM for browser
30
- await wasmModule.default();
31
- wasmInitialized = true;
34
+ await initWASM(wasmBuffer);
35
+ } else {
36
+ // Browser environment: fetch automatically
37
+ await initWASM();
32
38
  }
33
39
 
40
+ wasmInitialized = true;
41
+
34
42
  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
43
+ StrictNumber,
44
+ StrictString,
45
+ get_memory,
46
+ HeapType,
47
+ StrictArray,
48
+ StrictForLoop,
49
+ StrictFunction,
50
+ StrictObject,
51
+ Schema
44
52
  };
45
53
  }
46
54
 
47
- // Export all the named exports directly
48
- export const {
49
- StrictNumber,
50
- StrictString,
55
+ // Re-export types for convenience
56
+ export {
51
57
  get_memory,
52
58
  HeapType,
53
59
  StrictArray,
@@ -55,4 +61,4 @@ export const {
55
61
  StrictFunction,
56
62
  StrictObject,
57
63
  Schema
58
- } = wasmModule;
64
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "strictjs-runtime",
3
- "version": "2.0.1",
3
+ "version": "2.0.2",
4
4
  "description": "A lightweight low-level runtime for StrictJS with WebAssembly support.",
5
5
  "main": "index.js",
6
6
  "module": "index.js",