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.
- package/dist/ducjs_wasi.wasm +0 -0
- package/dist/ducjs_wasm_bg.wasm +0 -0
- package/dist/wasi.js +38 -25
- package/package.json +1 -1
|
Binary file
|
package/dist/ducjs_wasm_bg.wasm
CHANGED
|
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
|
-
*
|
|
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
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
return
|
|
66
|
-
|
|
67
|
-
|
|
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 =
|
|
198
|
+
const wasmBinary = yield loadWasiBinary();
|
|
186
199
|
const wasi = new WASI({
|
|
187
200
|
version: "preview1",
|
|
188
201
|
args,
|