diff --git a/app.tsx b/app.tsx index 121e4dd..6389860 100644 --- a/app.tsx +++ b/app.tsx @@ -6,7 +6,7 @@ function App(){ const [countGet, countSet] = React.useState(2); return <> -

test paragraph

+

test paragraph

} diff --git a/hmr/hmr-listen.tsx b/hmr/hmr-listen.tsx index 2495595..6a9e5a9 100644 --- a/hmr/hmr-listen.tsx +++ b/hmr/hmr-listen.tsx @@ -22,7 +22,8 @@ function connect() { }); socket.addEventListener("message", async (ev) => { try { - const reloadPath = location.origin + ev.data + "?reload=" + Math.random(); + const filePath = ev.data.startsWith(".") ? ev.data.slice(1) : ev.data; + const reloadPath = location.origin + filePath + "?reload=" + Math.random(); console.log("realod called", ev.data, reloadPath); const reImport = await import(reloadPath); FileListeners.get(ev.data)?.forEach(h => h(reImport)); diff --git a/hmr/hmr-static.tsx b/hmr/hmr-static.tsx index e08ecfa..001f23e 100644 --- a/hmr/hmr-static.tsx +++ b/hmr/hmr-static.tsx @@ -114,12 +114,12 @@ export const ModuleShape =(inText:string)=> return[local, foreign] as [local:string[], foreign:string[]]; }; -export const ModuleProxy =(inText:string, inPath:string, reactProxy:string)=> +export const ModuleProxy =(inText:string, inPath:string, reactProxy:string, reloadKey:string)=> { const [local, foreign] = ModuleShape(inText); return ` import {FileListen} from "${reactProxy}"; -import * as Import from "${inPath}?reload=${new Date().getTime()}"; +import * as Import from "${inPath}?${reloadKey}=${new Date().getTime()}"; ${ local.map(m=>`let proxy_${m} = Import.${m}; export { proxy_${m} as ${m} };`).join("\n") } FileListen("${inPath}", (updatedModule)=> { diff --git a/server.ts b/server.ts index 58fbd00..f148a9f 100644 --- a/server.ts +++ b/server.ts @@ -3,7 +3,7 @@ import { ModuleProxy } from "./hmr/hmr-static.tsx"; const keyBundle = "=>"; const keyTranspile = "->"; -const keyReload = "reload"; +const keyReload = "hmr:id"; const keysExtension = ["ts", "tsx"]; const extractExtension =(path:string)=> { @@ -59,7 +59,7 @@ async function BakeForce(options:FullBakeConfig) { const body = result.outputFiles.map(file=>file.text()).join("\n"); const listenerImport = `/${keyTranspile}/${import.meta.resolve("./hmr/hmr-listen.tsx")}`; - const save:CachedTranspile = [body, type ? "" : ModuleProxy(body, path, listenerImport)]; + const save:CachedTranspile = [body, type ? "" : ModuleProxy(body, path, listenerImport, keyReload)]; BakeCache[key] = save; // replace promise with resolved value return save; } @@ -183,13 +183,16 @@ Deno.serve(async(req:Request)=> if(parts[0] == keyTranspile) { console.log("TRANSPILE", parts); - const transpiled = await BakeCheck({path:parts.slice(1).join("/"), bundle:false}); + const transpiled = await BakeCheck({ + path:parts.slice(1).join("/"), + bundle:false + }); return JSResponse(transpiled[0]); } if(keysExtension.includes(extension)) { console.log("REGULAR", parts); - const transpiled = await BakeCheck({path:"."+url.pathname, bundle:false}); + const transpiled = await BakeCheck({path:"./"+parts.join("/"), bundle:false}); //return JSResponse(transpiled[0]); return JSResponse(transpiled[url.searchParams.has(keyReload) ? 0 : 1]); }