strictjs-runtime 1.0.7 → 2.0.0

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 +38 -13
  2. package/package.json +6 -4
package/index.js CHANGED
@@ -1,7 +1,7 @@
1
- import fs from "fs";
2
- import path from "path";
1
+
2
+
3
3
  import { fileURLToPath } from "url";
4
- import initWASM, {
4
+ import {
5
5
  StrictNumber,
6
6
  StrictString,
7
7
  get_memory,
@@ -13,19 +13,41 @@ import initWASM, {
13
13
  Schema
14
14
  } from "./pkg/strictjs_runtime.js";
15
15
 
16
- // Handle __dirname for ES modules
17
- const __filename = fileURLToPath(import.meta.url);
18
- const __dirname = path.dirname(__filename);
16
+ // Check if we're in Node.js environment
17
+ const isNode = typeof process !== 'undefined' &&
18
+ process.versions != null &&
19
+ process.versions.node != null;
20
+
21
+ let initWASM;
22
+ let wasmInitialized = false;
23
+
24
+ // Dynamic import to handle different environments
25
+ if (isNode) {
26
+ // Node.js environment
27
+ const fs = await import("fs");
28
+ const path = await import("path");
29
+
30
+ const __filename = fileURLToPath(import.meta.url);
31
+ const __dirname = path.dirname(__filename);
32
+
33
+ initWASM = (await import("./pkg/strictjs_runtime.js")).initWASM;
34
+
35
+ const wasmPath = path.resolve(__dirname, "pkg/strictjs_runtime_bg.wasm");
36
+ const wasmBuffer = fs.readFileSync(wasmPath);
37
+
38
+ await initWASM(wasmBuffer);
39
+ wasmInitialized = true;
40
+
41
+ } else {
42
+ // Browser environment
43
+ initWASM = (await import("./pkg/strictjs_runtime.js")).initWASM;
44
+ }
19
45
 
20
46
  export default async function strictInit() {
21
- if (typeof window === "undefined") {
22
- // Node.js environment: load WASM manually
23
- const wasmPath = path.resolve(__dirname, "pkg/strictjs_runtime_bg.wasm");
24
- const wasmBuffer = fs.readFileSync(wasmPath);
25
- await initWASM(wasmBuffer);
26
- } else {
27
- // Browser environment: let it fetch automatically
47
+ if (!wasmInitialized && !isNode) {
48
+ // Initialize WASM for browser
28
49
  await initWASM();
50
+ wasmInitialized = true;
29
51
  }
30
52
 
31
53
  return {
@@ -42,6 +64,8 @@ export default async function strictInit() {
42
64
  }
43
65
 
44
66
  export {
67
+ StrictNumber,
68
+ StrictString,
45
69
  get_memory,
46
70
  HeapType,
47
71
  StrictArray,
@@ -50,3 +74,4 @@ export {
50
74
  StrictObject,
51
75
  Schema
52
76
  };
77
+
package/package.json CHANGED
@@ -1,8 +1,10 @@
1
1
  {
2
2
  "name": "strictjs-runtime",
3
- "version": "1.0.7",
3
+ "version": "2.0.0",
4
4
  "description": "A lightweight low-level runtime for StrictJS with WebAssembly support.",
5
5
  "main": "index.js",
6
+ "module": "index.js",
7
+ "browser": "index.js",
6
8
  "type": "module",
7
9
  "files": [
8
10
  "pkg",
@@ -21,14 +23,14 @@
21
23
  "javascript",
22
24
  "webassembly"
23
25
  ],
24
- "author": "Kenneth Mburu kennethmburu21@gmail.com",
26
+ "author": "Kenneth Mburu <kennethmburu21@gmail.com>",
25
27
  "repository": {
26
28
  "type": "git",
27
29
  "url": "https://github.com/Kenneth732/strictJS.git"
28
30
  },
29
31
  "bugs": {
30
- "url": "https://github.com/Kenneth732/strictJS.git"
32
+ "url": "https://github.com/Kenneth732/strictJS/issues"
31
33
  },
32
- "homepage": "https://github.com/Kenneth732/strictJS.git",
34
+ "homepage": "https://github.com/Kenneth732/strictJS",
33
35
  "license": "MIT"
34
36
  }