diff --git a/api.tsx b/api.tsx new file mode 100644 index 0000000..2308168 --- /dev/null +++ b/api.tsx @@ -0,0 +1 @@ +export default ()=>{}; \ No newline at end of file diff --git a/app.tsx b/app.tsx new file mode 100644 index 0000000..2308168 --- /dev/null +++ b/app.tsx @@ -0,0 +1 @@ +export default ()=>{}; \ No newline at end of file diff --git a/deno.json b/deno.json index 1de4cfe..0c02170 100644 --- a/deno.json +++ b/deno.json @@ -7,8 +7,6 @@ { "react":"https://esm.sh/preact@10.15.1/compat", "react-original":"https://esm.sh/preact@10.15.1/compat", - "able/": "http://localhost:1234/", - "able:app": "./example/app.tsx", ">able/": "https://gitea.hptrow.me/SethTrowbridge/able-baker/raw/branch/master/" }, "tasks": diff --git a/example/app.tsx b/example/app.tsx index 0f99425..e2f7de8 100644 --- a/example/app.tsx +++ b/example/app.tsx @@ -1,4 +1,4 @@ -import { Router, Switch, Case } from "able/iso-elements.tsx"; +import { Router, Switch, Case } from ">able/iso-elements.tsx"; import React from "react"; @@ -39,7 +39,7 @@ export default ()=> return
-

Title

+

Title?????

subtitle

diff --git a/example/deno.json b/example/deno.json index a352b2f..0b248ee 100644 --- a/example/deno.json +++ b/example/deno.json @@ -3,12 +3,12 @@ "imports": { "react": "https://esm.sh/preact@10.15.1/compat", - "able/": "http://localhost:1234/", - "entry": "./app.tsx" + ">able/app.tsx": "./app.tsx", + ">able/": "http://localhost:4507/" }, "tasks": { - "local": "deno run -A --no-lock --reload=http://localhost:1234 http://localhost:1234/run-local.tsx", - "serve": "deno run -A --no-lock --reload=http://localhost:1234 http://localhost:1234/run-serve.tsx" + "local": "deno run -A --no-lock --reload=http://localhost:4507/ http://localhost:4507/run-local.tsx", + "serve": "deno run -A --no-lock --reload=http://localhost:4507/ http://localhost:4507/run-serve.tsx" } } \ No newline at end of file diff --git a/example/dyn-test.tsx b/example/dyn-test.tsx deleted file mode 100644 index 63ca671..0000000 --- a/example/dyn-test.tsx +++ /dev/null @@ -1,15 +0,0 @@ - -import * as Util from "@able/"; -import * as React from "react"; -import {createElement} from "react/client"; - -import('react').then((module) => { - console.log(module); -}); - - -function unimport(n:number) -{ - return n; -} -unimport(123) \ No newline at end of file diff --git a/run-local.tsx b/run-local.tsx index bae8e0d..e76ed3a 100644 --- a/run-local.tsx +++ b/run-local.tsx @@ -22,44 +22,55 @@ Configure({ Remap: (inImports, inConfig)=> { inImports["react-original"] = inImports["react"]; - inImports["react"] = import.meta.resolve(`./hmr-react.tsx`); + inImports["react"] = `/>able/hmr-react.tsx`; return inImports; }, async Serve(inReq, inURL, inExt, inMap, inConfig) { - if(Transpile.Check(inExt) && !inURL.searchParams.get("reload")) + if(!inURL.pathname.startsWith(encodeURI("/>"))) { - - // we dont need to add ?reload= because this fetch is by way the file system not the hosted url - const [local, foreign] = await Collect.FileExports(Root+inURL.pathname); - const code =` -import {FileListen} from "${import.meta.resolve(`./hmr-listen.tsx`)}"; -import * as Import from "${inURL.pathname}?reload=0"; -${ local.map(m=>`let proxy_${m} = Import.${m}; export { proxy_${m} as ${m} };`).join("\n") } -FileListen("${inURL.pathname}", (updatedModule)=> -{ - ${ local.map(m=>`proxy_${m} = updatedModule.${m};`).join("\n") } -}); -${ foreign.join(";\n") } -` - - return new Response(code, {headers:{"content-type":"application/javascript"}}); - } - - - if(inReq.headers.get("upgrade") == "websocket") - { - try + if(Transpile.Check(inExt) && !inURL.searchParams.get("reload")) { - const { response, socket } = Deno.upgradeWebSocket(inReq); - socket.onopen = () => SocketsLive.add(socket); - socket.onclose = () => SocketsLive.delete(socket); - socket.onmessage = (e) => {}; - socket.onerror = (e) => console.log("Socket errored:", e); - return response; + + // we dont need to add ?reload= because this fetch is by way the file system not the hosted url + + console.log("collecting exports for", Root+inURL.pathname); + + const [local, foreign] = await Collect.FileExports(Root+inURL.pathname); + const code =` + import {FileListen} from ">able/hmr-listen.tsx"; + import * as Import from "${inURL.pathname}?reload=0"; + ${ local.map(m=>`let proxy_${m} = Import.${m}; export { proxy_${m} as ${m} };`).join("\n") } + FileListen("${inURL.pathname}", (updatedModule)=> + { + ${ local.map(m=>`proxy_${m} = updatedModule.${m};`).join("\n") } + }); + ${ foreign.join(";\n") } + ` + + return new Response(code, {headers:{"content-type":"application/javascript"}}); } - catch(e){ /**/ } + + + if(inReq.headers.get("upgrade") == "websocket") + { + try + { + const { response, socket } = Deno.upgradeWebSocket(inReq); + socket.onopen = () => SocketsLive.add(socket); + socket.onclose = () => SocketsLive.delete(socket); + socket.onmessage = (e) => {}; + socket.onerror = (e) => console.log("Socket errored:", e); + return response; + } + catch(e){ /**/ } + } } + else + { + console.log("not collecting", inURL.pathname) + } + } }); @@ -82,7 +93,7 @@ const Watcher =async()=> const key = path.substring(Deno.cwd().length).replaceAll("\\", "/"); if(action != "remove") { - const tsx = await Transpile.Fetch(`file://${Deno.cwd().replaceAll("\\", "/")}`+key, key, true); + const tsx = await Transpile.Fetch(Root+key, key, true); tsx && SocketsSend(key); } else diff --git a/run-serve.tsx b/run-serve.tsx index 21940f5..831a99b 100644 --- a/run-serve.tsx +++ b/run-serve.tsx @@ -56,10 +56,18 @@ const ImportMapReload =async()=> { json.imports[key] = value.substring(1); } - if(key.startsWith(">")||key.startsWith("able/")) + if(key.startsWith(">")) { - ImportMapProxies["/"+encodeURI(key)] = value; - json.imports[key] = "/"+key; + if(value.startsWith("./")) + { + ImportMapProxies[encodeURI(key)] = value.substring(1); + json.imports[key] = value.substring(1); + } + else + { + ImportMapProxies["/"+encodeURI(key)] = value; + json.imports[key] = "/"+key; + } } }); @@ -92,8 +100,8 @@ let Configuration:Configuration =

`, {status:200, headers:{"content-type":"text/html"}}); @@ -296,9 +304,13 @@ const server = Deno.serve({port:parseInt(Deno.env.get("port")||"8000")}, async(r } if(bestMatch.length) { - proxy = ImportMapProxies[bestMatch] + url.pathname.substring(bestMatch.length); - } + const match = ImportMapProxies[bestMatch]; + const path = url.pathname.substring(bestMatch.length); + proxy = path ? match + path : Root + match; + + } } + console.log("proxy will be", proxy); // allow for custom handler const custom = await Configuration.Serve(req, url, ext, ImportMap, Configuration); @@ -310,6 +322,7 @@ const server = Deno.serve({port:parseInt(Deno.env.get("port")||"8000")}, async(r // transpileable files if(Transpile.Check(ext)) { + console.log("transpiling:", proxy); const code = await Transpile.Fetch(proxy, url.pathname); if(code) {