From 7086e95d15ce9182ba1ca256117e0fd062e5dc52 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 15 Nov 2025 00:33:14 +0000 Subject: [PATCH 1/2] Initial plan From a1b68929adc1ace55561e83b1ee22e73e3f3549c Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 15 Nov 2025 00:47:08 +0000 Subject: [PATCH 2/2] Fix unsafe Deno global access to prevent WASM transformation failures Co-authored-by: kayodebristol <3579196+kayodebristol@users.noreply.github.com> --- cli.ts | 19 +++++++++++++------ runtime.ts | 9 +++++---- src/parser.ts | 7 ++++--- 3 files changed, 22 insertions(+), 13 deletions(-) diff --git a/cli.ts b/cli.ts index 5b9cce6..0160efa 100644 --- a/cli.ts +++ b/cli.ts @@ -15,7 +15,8 @@ const isDeno = typeof globalThis !== "undefined" && "Deno" in globalThis; async function exitWithCode(code: number): Promise { if (isDeno) { - Deno.exit(code); + const DenoNS = (globalThis as any).Deno; + DenoNS.exit(code); } else { const mod = await import("node:process"); mod.default.exit(code); @@ -26,7 +27,10 @@ async function exitWithCode(code: number): Promise { async function readText(p: string): Promise { try { - if (isDeno) return await Deno.readTextFile(p); + if (isDeno) { + const DenoNS = (globalThis as any).Deno; + return await DenoNS.readTextFile(p); + } const fs = await import("node:fs/promises"); return await fs.readFile(p, "utf8"); } catch (_e) { @@ -38,7 +42,8 @@ async function readText(p: string): Promise { async function writeText(p: string, content: string) { if (isDeno) { - await Deno.writeTextFile(p, content); + const DenoNS = (globalThis as any).Deno; + await DenoNS.writeTextFile(p, content); } else { const fs = await import("node:fs/promises"); await fs.writeFile(p, content, "utf8"); @@ -48,7 +53,8 @@ async function writeText(p: string, content: string) { async function fileExists(p: string): Promise { try { if (isDeno) { - await Deno.stat(p); + const DenoNS = (globalThis as any).Deno; + await DenoNS.stat(p); return true; } else { const fs = await import("node:fs/promises"); @@ -90,7 +96,7 @@ async function initConfig(path: string) { // Main function to avoid top-level await which is incompatible with CommonJS async function main() { - const argv = isDeno ? Deno.args : (await import("node:process")).argv.slice(2); + const argv = isDeno ? (globalThis as any).Deno.args : (await import("node:process")).argv.slice(2); const { cmd, configPath } = parseArgs(argv); if (cmd === "init") { @@ -121,7 +127,8 @@ async function main() { main().catch((e) => { console.error("Fatal error:", e); if (isDeno) { - Deno.exit(1); + const DenoNS = (globalThis as any).Deno; + DenoNS.exit(1); } else { import("node:process").then(mod => mod.default.exit(1)); } diff --git a/runtime.ts b/runtime.ts index d12d874..a1ccd39 100644 --- a/runtime.ts +++ b/runtime.ts @@ -46,12 +46,13 @@ export async function loadAdapters(): Promise { const mermaid: MermaidRenderer = { toPng(_mmd) { return Promise.resolve(null); } }; + const DenoNS = (globalThis as any).Deno; const fs: FSLike = { - readFile: p => Deno.readTextFile(p), - writeFile: (p, d) => Deno.writeTextFile(p, d), - writeBinaryFile: (p, d) => Deno.writeFile(p, d), + readFile: p => DenoNS.readTextFile(p), + writeFile: (p, d) => DenoNS.writeTextFile(p, d), + writeBinaryFile: (p, d) => DenoNS.writeFile(p, d), mkdirp: p => ensureDir(p), - exists: p => Deno.stat(p).then(()=>true).catch(()=>false), + exists: p => DenoNS.stat(p).then(()=>true).catch(()=>false), }; return { diff --git a/src/parser.ts b/src/parser.ts index 467df5a..d74cfdd 100644 --- a/src/parser.ts +++ b/src/parser.ts @@ -86,14 +86,15 @@ async function extractMachinesFromFile(filePath: string, _adapters: Adapters): P // Convert to absolute file:// URL let importPath = filePath; if (!importPath.startsWith('file://') && !importPath.startsWith('http://') && !importPath.startsWith('https://')) { - // Check if Deno is available + // Check if Deno is available using safer pattern to avoid WASM transformation issues const isDeno = typeof globalThis !== "undefined" && "Deno" in globalThis; // Make it absolute if it's not already if (!importPath.startsWith('/')) { if (isDeno) { - // Safe to access Deno directly after checking isDeno - importPath = `${Deno.cwd()}/${importPath}`; + // Access Deno dynamically to avoid WASM transformer issues with direct global access + const DenoNS = (globalThis as any).Deno; + importPath = `${DenoNS.cwd()}/${importPath}`; } else { const process = await import("node:process"); importPath = `${process.cwd()}/${importPath}`;