ducjs 4.0.2 → 4.0.3

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.
Binary file
Binary file
package/dist/wasi.js CHANGED
@@ -39,32 +39,45 @@ const isSuccessfulWasiExit = (error) => {
39
39
  || (candidate === null || candidate === void 0 ? void 0 : candidate.exitCode) === 0
40
40
  || (candidate === null || candidate === void 0 ? void 0 : candidate.message) === "Exited with status 0";
41
41
  };
42
+ let wasiBinaryReady = null;
42
43
  /**
43
- * Resolve the WASI binary path.
44
- * In development, it's in the ducjs dist directory.
45
- * In production, it should be bundled or downloaded.
44
+ * Load the WASI binary from a local package/path or a remote URL.
46
45
  */
47
- function resolveWasiBinary() {
48
- var _a;
49
- // Check for explicit override
50
- const env = (_a = globalThis.process) === null || _a === void 0 ? void 0 : _a.env;
51
- if (env === null || env === void 0 ? void 0 : env.DUCJS_WASI_PATH) {
52
- return env.DUCJS_WASI_PATH;
53
- }
54
- // Try to find it relative to ducjs package
55
- const candidates = [
56
- // Relative to this file (if in node_modules)
57
- resolve(_dirname, "..", "node_modules", "ducjs", "dist", "ducjs_wasi.wasm"),
58
- // Relative to ducjs dist (if running from source)
59
- resolve(_dirname, "..", "ducjs", "dist", "ducjs_wasi.wasm"),
60
- // Direct path from ducjs package
61
- resolve(_dirname, "ducjs_wasi.wasm"),
62
- ];
63
- for (const candidate of candidates) {
64
- if (existsSync(candidate))
65
- return candidate;
66
- }
67
- throw new Error(`ducjs WASI binary not found. Set DUCJS_WASI_PATH or ensure ducjs/dist/ducjs_wasi.wasm exists. Tried: ${candidates.join(", ")}`);
46
+ function loadWasiBinary() {
47
+ if (wasiBinaryReady)
48
+ return wasiBinaryReady;
49
+ wasiBinaryReady = (() => __awaiter(this, void 0, void 0, function* () {
50
+ var _a;
51
+ const env = (_a = globalThis.process) === null || _a === void 0 ? void 0 : _a.env;
52
+ if (env === null || env === void 0 ? void 0 : env.DUCJS_WASI_PATH) {
53
+ return readFileSync(env.DUCJS_WASI_PATH);
54
+ }
55
+ if (env === null || env === void 0 ? void 0 : env.DUCJS_WASI_URL) {
56
+ const response = yield fetch(env.DUCJS_WASI_URL);
57
+ if (!response.ok) {
58
+ throw new Error(`Failed to download ducjs WASI binary: ${response.status} ${response.statusText}`);
59
+ }
60
+ const binary = new Uint8Array(yield response.arrayBuffer());
61
+ if (binary.byteLength === 0) {
62
+ throw new Error("Downloaded ducjs WASI binary is empty");
63
+ }
64
+ return binary;
65
+ }
66
+ const candidates = [
67
+ resolve(_dirname, "..", "node_modules", "ducjs", "dist", "ducjs_wasi.wasm"),
68
+ resolve(_dirname, "..", "ducjs", "dist", "ducjs_wasi.wasm"),
69
+ resolve(_dirname, "ducjs_wasi.wasm"),
70
+ ];
71
+ for (const candidate of candidates) {
72
+ if (existsSync(candidate))
73
+ return readFileSync(candidate);
74
+ }
75
+ throw new Error(`ducjs WASI binary not found. Set DUCJS_WASI_PATH, set DUCJS_WASI_URL, or ensure ducjs/dist/ducjs_wasi.wasm exists. Tried: ${candidates.join(", ")}`);
76
+ }))().catch((error) => {
77
+ wasiBinaryReady = null;
78
+ throw error;
79
+ });
80
+ return wasiBinaryReady;
68
81
  }
69
82
  /**
70
83
  * Stream multiple files into a single .duc file using the WASI binary.
@@ -182,7 +195,7 @@ const writeExternalFileSidecars = (state, manifestDir) => {
182
195
  return manifestPath;
183
196
  };
184
197
  const runWasi = (args, preopens) => __awaiter(void 0, void 0, void 0, function* () {
185
- const wasmBinary = readFileSync(resolveWasiBinary());
198
+ const wasmBinary = yield loadWasiBinary();
186
199
  const wasi = new WASI({
187
200
  version: "preview1",
188
201
  args,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ducjs",
3
- "version": "4.0.2",
3
+ "version": "4.0.3",
4
4
  "description": "SQLite-backed project-state format for physical-engineering work before execution.",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",