// Durable patch for a Windows-only bug in @deno/experimental-route-config@0.0.5 // (pulled in by @deno/svelte-adapter, used only by the `deno desktop` build). // // The bug: parseConfig() resolves a static route's destination to an absolute // Windows path with backslashes (…\_app\immutable\:file*), but parsePattern()'s // regex only recognizes forward-slash `/:param` syntax. So on Windows the // `:file*` catch-all is never parsed as a parameter and every client asset // request tries to open the literal path `…\:file*` → os error 123 → the // desktop app crashes on first paint. Widening the regex to accept `\` fixes it. // // Runs before the desktop compile (chained in deno.json's `desktop` task) so the // patched code is bundled into the binary. Idempotent; re-run after any // `deno install`. Reported upstream. Remove once the package ships a fix. const target = new URL( "../node_modules/.deno/@deno+experimental-route-config@0.0.5/node_modules/@deno/experimental-route-config/dist/pattern.js", import.meta.url, ); const NEEDLE = "/(\\/:"; // the source text: /(\/: const PATCHED = "/([\\\\/]:"; // produces: /([\\/]: let src: string; try { src = Deno.readTextFileSync(target); } catch { console.log( "@deno/experimental-route-config not installed; nothing to patch", ); Deno.exit(0); } if (src.includes(PATCHED)) { console.log("route-config already patched"); Deno.exit(0); } if (!src.includes(NEEDLE)) { console.error( "patch target not found — @deno/experimental-route-config may have changed. " + "Re-verify the desktop static-serving fix before shipping.", ); Deno.exit(1); } Deno.writeTextFileSync(target, src.replace(NEEDLE, PATCHED)); console.log( "patched @deno/experimental-route-config for the Windows static-path bug", );