From d7a5350256d7cfea52c883ced0bb371930cba1f7 Mon Sep 17 00:00:00 2001 From: Seth Trowbridge Date: Wed, 21 Jun 2023 22:35:59 -0400 Subject: [PATCH] configurable lib folder --- run-local.tsx | 6 +++--- run-serve.tsx | 17 ++++++++++------- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/run-local.tsx b/run-local.tsx index abc92b8..665788b 100644 --- a/run-local.tsx +++ b/run-local.tsx @@ -21,19 +21,19 @@ Configure({ Remap: (inImports, inConfig)=> { inImports["react-original"] = inImports["react"]; - inImports["react"] = "/_lib_/hmr-react.tsx"; + inImports["react"] = `${inConfig.Spoof}/hmr-react.tsx`; return inImports; }, async Serve(inReq, inURL, inExt, inMap, inConfig) { - if(Transpile.Check(inExt) && !inURL.searchParams.get("reload") && !inURL.pathname.startsWith("/_lib_/")) + if(Transpile.Check(inExt) && !inURL.searchParams.get("reload") && !inURL.pathname.startsWith(inConfig.Spoof+"/")) { const imp = await import(inConfig.Proxy+inURL.pathname); const members = []; for( const key in imp ) { members.push(key); } const code =` -import {FileListen} from "/_lib_/hmr-listen.tsx"; +import {FileListen} from "${inConfig.Spoof}/hmr-listen.tsx"; import * as Import from "${inURL.pathname}?reload=0"; ${ members.map(m=>`let proxy_${m} = Import.${m}; export { proxy_${m} as ${m} };`).join("\n") } FileListen("${inURL.pathname}", (updatedModule)=> diff --git a/run-serve.tsx b/run-serve.tsx index ef71716..f67320a 100644 --- a/run-serve.tsx +++ b/run-serve.tsx @@ -28,11 +28,13 @@ const ImportMapReload =async()=> json.imports[key] = value.substring(1); } }); - if(!json.imports["@able/"]) + + const mapKey = (Configuration.Spoof.startsWith("/") ? Configuration.Spoof.substring(1) : Configuration.Spoof)+"/"; + if(!json.imports[mapKey]) { - console.log(`"@able/" specifier not defined in import map`); + console.log(`"${mapKey}" specifier not defined in import map`); } - json.imports["@able/"] = "/_lib_/"; + json.imports[mapKey] = Configuration.Spoof+"/"; if(!json.imports["react"]) { @@ -45,13 +47,14 @@ const ImportMapReload =async()=> type CustomHTTPHandler = (inReq:Request, inURL:URL, inExt:string|false, inMap:{imports:Record}, inConfig:Configuration)=>void|false|Response|Promise; type CustomRemapper = (inImports:Record, inConfig:Configuration)=>Record; -type Configuration = {Proxy:string, Allow:string, Reset:string, SWCOp:SWCW.Options, Serve:CustomHTTPHandler, Shell:CustomHTTPHandler, Remap:CustomRemapper}; -type ConfigurationArgs = {Proxy?:string, Allow?:string, Reset?:string, SWCOp?:SWCW.Options, Serve?:CustomHTTPHandler, Shell?:CustomHTTPHandler, Remap?:CustomRemapper}; +type Configuration = {Proxy:string, Spoof:string, Allow:string, Reset:string, SWCOp:SWCW.Options, Serve:CustomHTTPHandler, Shell:CustomHTTPHandler, Remap:CustomRemapper}; +type ConfigurationArgs = {Proxy?:string, Spoof?:string, Allow?:string, Reset?:string, SWCOp?:SWCW.Options, Serve?:CustomHTTPHandler, Shell?:CustomHTTPHandler, Remap?:CustomRemapper}; let Configuration:Configuration = { Proxy: new URL(`file://${Deno.cwd().replaceAll("\\", "/")}`).toString(), Allow: "*", Reset: "/clear-cache", + Spoof: "/@able", Serve(inReq, inURL, inExt, inMap, inConfig){}, Remap: (inImports, inConfig)=> { @@ -78,7 +81,7 @@ let Configuration:Configuration =
@@ -189,7 +192,7 @@ HTTP.serve(async(req: Request)=> { let code; let path; - if(url.pathname.startsWith("/_lib_/")) + if(url.pathname.startsWith(Configuration.Spoof+"/")) { const clipRoot = import.meta.url.substring(0, import.meta.url.lastIndexOf("/")); const clipPath = url.pathname.substring(url.pathname.indexOf("/", 1));