diff --git a/public/bundle.js b/public/bundle.js index 28d0c0f..fac0228 100644 --- a/public/bundle.js +++ b/public/bundle.js @@ -1,5 +1,5 @@ //// -// version: c584db7 +// version: df700ff var __defProp = Object.defineProperty; var __export = (target, all) => { @@ -83,9 +83,12 @@ __export(exports_scrollback, { function randomId() { return Math.random().toString(36).slice(7); } -async function importUrl(url) { +async function importUrl(url, cacheTag) { url += url.includes("?") ? "&" : "?"; - url += "t=" + (nodeEnv() === "production" ? gitSHA() : Date.now()); + if (cacheTag) + url += "t=" + cacheTag; + else + url += "t=" + (nodeEnv() === "production" ? gitSHA() : Date.now()); console.log("-> import", url); return import(url); } diff --git a/src/commands.ts b/src/commands.ts index f3892ae..dd5ce13 100644 --- a/src/commands.ts +++ b/src/commands.ts @@ -6,7 +6,7 @@ import { watch, readFileSync } from "fs" import { join, basename } from "path" import { isFile } from "./utils" import { sendAll } from "./websocket" -import { expectDir } from "./utils" +import { expectDir, mtimeEpoch } from "./utils" import { importUrl } from "./shared/utils" import type { Command, Commands } from "./shared/types" import { projectBin, projectName } from "./project" @@ -82,7 +82,11 @@ export async function commandSource(name: string): Promise { export async function loadCommandModule(cmd: string) { const path = commandPath(cmd) if (!path) return - return await importUrl(path) + + if (path.startsWith(NOSE_DIR)) + return await importUrl(path, await mtimeEpoch(path)) + else + return await importUrl(path) } let noseDirWatcher diff --git a/src/shared/utils.ts b/src/shared/utils.ts index 1320ead..10ceaea 100644 --- a/src/shared/utils.ts +++ b/src/shared/utils.ts @@ -40,10 +40,13 @@ export function unique(array: T[]): T[] { return [...new Set(array)] } -// import a typescript module. caches in production, doesn't in dev. -export async function importUrl(url: string) { +// import a typescript module. caches by sha in production, doesn't cache in dev. +export async function importUrl(url: string, cacheTag?: string) { url += url.includes("?") ? "&" : "?" - url += "t=" + (nodeEnv() === "production" ? gitSHA() : Date.now()) + if (cacheTag) + url += "t=" + cacheTag + else + url += "t=" + (nodeEnv() === "production" ? gitSHA() : Date.now()) console.log("-> import", url) return import(url) diff --git a/src/utils.tsx b/src/utils.tsx index 07e432f..22e4ba5 100644 --- a/src/utils.tsx +++ b/src/utils.tsx @@ -63,6 +63,10 @@ export async function mtime(path: string): Promise { return mtime } +export async function mtimeEpoch(path: string): Promise { + return (await mtime(path)).getTime().toString() +} + // is the given file binary? export async function isBinaryFile(path: string): Promise { // Create a stream to read just the beginning diff --git a/src/webapp.ts b/src/webapp.ts index 99edce9..77fba38 100644 --- a/src/webapp.ts +++ b/src/webapp.ts @@ -8,7 +8,7 @@ import { readdirSync, watch } from "fs" import { sendAll } from "./websocket" import { expectDir } from "./utils" import { NOSE_DIR } from "./config" -import { isFile, isDir } from "./utils" +import { isFile, isDir, mtimeEpoch } from "./utils" import { importUrl } from "./shared/utils" export type Handler = (r: Context) => string | Child | Response | Promise @@ -73,7 +73,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) + const mod = await importUrl(path, await mtimeEpoch(path)) if (mod?.default) return mod.default as App }