From ea5b33c5bdb1bc4e6a1ff448b5af7ec73f4e76af Mon Sep 17 00:00:00 2001 From: Chris Wanstrath Date: Tue, 7 Oct 2025 20:13:52 -0700 Subject: [PATCH] move import cache busted into importUrl --- src/commands.ts | 2 +- src/js/game.ts | 2 +- src/js/shell.ts | 2 +- src/shared/utils.ts | 2 ++ src/webapp.ts | 2 +- 5 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/commands.ts b/src/commands.ts index a4488b7..f3892ae 100644 --- a/src/commands.ts +++ b/src/commands.ts @@ -82,7 +82,7 @@ export async function commandSource(name: string): Promise { export async function loadCommandModule(cmd: string) { const path = commandPath(cmd) if (!path) return - return await importUrl(path + "?t=" + Date.now()) + return await importUrl(path) } let noseDirWatcher diff --git a/src/js/game.ts b/src/js/game.ts index ee43188..efab54f 100644 --- a/src/js/game.ts +++ b/src/js/game.ts @@ -35,7 +35,7 @@ export async function handleGameStart(msg: GameStartMessage) { let game try { - game = await importUrl(`/source/${name}?session=${sessionId}&t=${Date.now()}`) + game = await importUrl(`/source/${name}?session=${sessionId}}`) } catch (err: any) { setStatus(msgId, "error") addOutput(msgId, `Error: ${err.message ? err.message : err}`) diff --git a/src/js/shell.ts b/src/js/shell.ts index 8069888..6c0b489 100644 --- a/src/js/shell.ts +++ b/src/js/shell.ts @@ -25,7 +25,7 @@ export async function runCommand(input: string, showInput = true) { const [cmd = "", ...args] = input.split(" ") if (commands[cmd]?.type === "browser") { - const mod = await importUrl(`/source/${cmd}?t=${Date.now()}`) + const mod = await importUrl(`/source/${cmd}`) if (!mod.default) { addOutput(id, `no default export in ${cmd}`) setStatus(id, "error") diff --git a/src/shared/utils.ts b/src/shared/utils.ts index ee420dd..0721446 100644 --- a/src/shared/utils.ts +++ b/src/shared/utils.ts @@ -41,6 +41,8 @@ export function unique(array: T[]): T[] { } export async function importUrl(url: string) { + url += url.includes("?") ? "&" : "?" + url += "t=" + Date.now() console.log("-> import", url) return import(url) } \ No newline at end of file diff --git a/src/webapp.ts b/src/webapp.ts index bc3ad74..8cc1cf4 100644 --- a/src/webapp.ts +++ b/src/webapp.ts @@ -74,7 +74,7 @@ async function findApp(name: string): Promise { async function loadApp(path: string): Promise { if (!await Bun.file(path).exists()) return - const mod = await importUrl(path + `?t=${Date.now()}`) + const mod = await importUrl(path) if (mod?.default) return mod.default as App }