From 4149c0c1426b397b0c654e5e605d5f72451082aa Mon Sep 17 00:00:00 2001 From: Hatter Jiang Date: Sat, 14 Feb 2026 20:39:48 +0800 Subject: [PATCH] deno wasm mod --- libraries/deno-wasm-mod.ts | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/libraries/deno-wasm-mod.ts b/libraries/deno-wasm-mod.ts index d1750bf..0e16660 100644 --- a/libraries/deno-wasm-mod.ts +++ b/libraries/deno-wasm-mod.ts @@ -1,9 +1,32 @@ -import {fetchDataWithTimeout} from "https://script.hatter.ink/@49/deno-commons-mod.ts"; +import { + args, + execCommandShell, + exit, + fetchFileWithCache, + log, +} from "https://script.hatter.ink/@50/deno-commons-mod.ts"; // JQ WASM URL: // https://cdn.hatter.ink/doc/8998_BE8D1CBE6106C77968183F226E2129B5/jq.wasm -async function getCachedWasm(wasmUrl: string): Promise { - const wasmResponse = await fetchDataWithTimeout(wasmUrl); - return null; +async function execWasm( + wasmCommand: string, + wasmUrl: string, + wasmArgs?: string[], +): never { + const wasmCacheFileMeta = await fetchFileWithCache(wasmUrl); + const wasmCommandArgs = [wasmCacheFileMeta.cache_full_path, "--"]; + if (wasmArgs) { + wasmCommandArgs.push(...wasmArgs); + } + log.debug(wasmCommandArgs); + exit(await execCommandShell(wasmCommand, wasmCommandArgs)); +} + +if (import.meta.main) { + await execWasm( + "wasmer", + "https://cdn.hatter.ink/doc/8998_BE8D1CBE6106C77968183F226E2129B5/jq.wasm", + args(), + ); }