diff --git a/run-local.tsx b/run-local.tsx index 42183d2..43e5c1e 100644 --- a/run-local.tsx +++ b/run-local.tsx @@ -18,17 +18,17 @@ Configure({ } } }, - Remap: (inImports)=> + Remap: (inImports, inConfig)=> { inImports["react-original"] = inImports["react"]; inImports["react"] = "/_lib_/hmr-react.tsx"; return inImports; }, - async Serve(inReq, inURL, inExt, inMap, inProxy) + async Serve(inReq, inURL, inExt, inMap, inConfig) { if(Transpile.Check(inExt) && !inURL.searchParams.get("reload") && !inURL.pathname.startsWith("/_lib_/")) { - const imp = await import(inProxy+inURL.pathname); + const imp = await import(inConfig.Proxy+inURL.pathname); const members = []; for( const key in imp ) { members.push(key); } diff --git a/run-serve.tsx b/run-serve.tsx index b978583..99a456b 100644 --- a/run-serve.tsx +++ b/run-serve.tsx @@ -39,12 +39,12 @@ const ImportMapReload =async()=> console.log(`"react" specifier not defined in import map`); } - ImportMap.imports = Configuration.Remap(json.imports); + ImportMap.imports = Configuration.Remap(json.imports, Configuration); console.log(ImportMap.imports); }; -type CustomHTTPHandler = (inReq:Request, inURL:URL, inExt:string|false, inMap:{imports:Record}, inProxy:string)=>void|false|Response|Promise; -type CustomRemapper = (inImports:Record)=>Record; +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}; let Configuration:Configuration = @@ -53,7 +53,7 @@ let Configuration:Configuration = Allow: "*", Reset: "/clear-cache", Serve(inReq, inURL, inExt, inMap, inProxy){}, - Remap: (inImports)=> + Remap: (inImports, inConfig)=> { const reactURL = inImports["react"]; const setting = Configuration.SWCOp?.jsc?.transform?.react; @@ -63,12 +63,12 @@ let Configuration:Configuration = } return inImports; }, - Shell(inReq, inURL, inExt, inMap, inProxy) + Shell(inReq, inURL, inExt, inMap, inConfig) { - console.log("Start app:", Deno.mainModule, "start dir", inProxy); - console.log("Split:", Deno.mainModule.split(inProxy) ); + console.log("Start app:", Deno.mainModule, "start dir", inConfig.Proxy); + console.log("Split:", Deno.mainModule.split(inConfig.Proxy) ); - const parts = Deno.mainModule.split(inProxy); + const parts = Deno.mainModule.split(inConfig.Proxy); return new Response( ` @@ -181,7 +181,7 @@ HTTP.serve(async(req: Request)=> } // allow for custom handler - const custom = await Configuration.Serve(req, url, ext, ImportMap, Configuration.Proxy); + const custom = await Configuration.Serve(req, url, ext, ImportMap, Configuration); if(custom) { return custom; @@ -222,7 +222,7 @@ HTTP.serve(async(req: Request)=> // custom page html if(!ext) { - const shell = await Configuration.Shell(req, url, ext, ImportMap, Configuration.Proxy); + const shell = await Configuration.Shell(req, url, ext, ImportMap, Configuration); if(shell) { return shell;