@danielsimonjr/mathts-functions 0.11.2 → 0.12.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.
@@ -95,6 +95,24 @@ async function resolvePackagedWasm(metaUrl, wasmFile) {
95
95
  }
96
96
  return null;
97
97
  }
98
+ async function defaultWasmLocation(metaUrl, wasmFile, opts) {
99
+ if (opts?.browser) {
100
+ return new URL(`./wasm/${wasmFile}`, metaUrl).href;
101
+ }
102
+ const { fileURLToPath } = await import("url");
103
+ const { dirname, join } = await import("path");
104
+ const { existsSync } = await import("fs");
105
+ let dir = dirname(fileURLToPath(metaUrl));
106
+ for (let depth = 0; depth < 8; depth++) {
107
+ if (existsSync(join(dir, "package.json"))) {
108
+ return join(dir, "dist", "wasm", wasmFile);
109
+ }
110
+ const parent = dirname(dir);
111
+ if (parent === dir) break;
112
+ dir = parent;
113
+ }
114
+ return join(dirname(fileURLToPath(metaUrl)), "wasm", wasmFile);
115
+ }
98
116
 
99
117
  // src/wasm/WasmLoader.ts
100
118
  var WasmLoader = class _WasmLoader {
@@ -202,10 +220,9 @@ var WasmLoader = class _WasmLoader {
202
220
  if (this.isNode) {
203
221
  const packaged = await resolvePackagedWasm(import.meta.url, wasmFile);
204
222
  if (packaged) return packaged;
205
- const { fileURLToPath } = await import("url");
206
- return fileURLToPath(new URL(`../../../lib/wasm/${wasmFile}`, import.meta.url));
223
+ return defaultWasmLocation(import.meta.url, wasmFile);
207
224
  }
208
- return new URL(`../../../lib/wasm/${wasmFile}`, import.meta.url).href;
225
+ return defaultWasmLocation(import.meta.url, wasmFile, { browser: true });
209
226
  }
210
227
  async loadNodeWasm(path, totalStart) {
211
228
  const fs = await import("fs");