@nodora/js 0.0.1 → 0.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.
package/lib/index.js CHANGED
@@ -1,23 +1,9 @@
1
- import "./wasm_exec";
1
+ import "./wasm_exec.js";
2
+ import { loadWasmBinary } from "#wasm-loader";
2
3
 
3
4
  let wasmInstance = null;
4
5
  let initPromise = null;
5
6
 
6
- async function loadWasmBinary() {
7
- if (typeof window !== "undefined") {
8
- const wasmUrl = new URL("./nodora.wasm", import.meta.url);
9
- const response = await fetch(wasmUrl.href);
10
- if (!response.ok) {
11
- throw new Error(`HTTP ${response.status}: ${response.statusText}`);
12
- }
13
- return response.arrayBuffer();
14
- }
15
-
16
- const { readFile } = await import("fs/promises");
17
- const { fileURLToPath } = await import("url");
18
- return readFile(fileURLToPath(new URL("./nodora.wasm", import.meta.url)));
19
- }
20
-
21
7
  async function init() {
22
8
  if (initPromise) return initPromise;
23
9
  initPromise = (async () => {
@@ -0,0 +1,8 @@
1
+ export async function loadWasmBinary() {
2
+ const wasmUrl = new URL("./nodora.wasm", import.meta.url);
3
+ const response = await fetch(wasmUrl.href);
4
+ if (!response.ok) {
5
+ throw new Error(`HTTP ${response.status}: ${response.statusText}`);
6
+ }
7
+ return response.arrayBuffer();
8
+ }
@@ -0,0 +1,6 @@
1
+ import { readFile } from "fs/promises";
2
+ import { fileURLToPath } from "url";
3
+
4
+ export async function loadWasmBinary() {
5
+ return readFile(fileURLToPath(new URL("./nodora.wasm", import.meta.url)));
6
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nodora/js",
3
- "version": "0.0.1",
3
+ "version": "0.0.2",
4
4
  "description": "JS bindings for Nodora rule engine",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
@@ -31,9 +31,15 @@
31
31
  },
32
32
  "exports": {
33
33
  ".": {
34
+ "types": "./lib/index.d.ts",
34
35
  "import": "./lib/index.js",
35
- "require": "./lib/index.js",
36
- "types": "./lib/index.d.ts"
36
+ "require": "./lib/index.js"
37
+ }
38
+ },
39
+ "imports": {
40
+ "#wasm-loader": {
41
+ "browser": "./lib/wasm.browser.js",
42
+ "default": "./lib/wasm.node.js"
37
43
  }
38
44
  }
39
45
  }