strictjs-runtime 1.0.7 → 1.0.8

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