Compare commits
3 Commits
a9139c6cd3
...
d7a5350256
Author | SHA1 | Date | |
---|---|---|---|
d7a5350256 | |||
f521ed23eb | |||
cc80a2725d |
@ -68,7 +68,6 @@ const ProxyState =(argNew:StateType)=>
|
||||
// this is a switch/ui change, not a HMR reload change
|
||||
const oldState = MapIndex(HMR.statesOld, HMR.statesNew.size-1);
|
||||
oldState && HMR.statesOld.set(oldState[0], {...oldState[1], state:argNew});
|
||||
console.log("check: ui-invoked")
|
||||
}
|
||||
|
||||
HMR.statesNew.delete(id);
|
||||
@ -112,7 +111,6 @@ const ProxyReducer =(inReducer:(inState:Storelike, inAction:string)=>Storelike,
|
||||
const capture = inReducer(inInterceptState, inInterceptAction);
|
||||
const stateUser = {state:capture, set:()=>{}, reload:HMR.reloads};
|
||||
HMR.statesNew.set(id, stateUser);
|
||||
console.log("interepted reducer", stateUser);
|
||||
return capture;
|
||||
};
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
import {Configure, Transpile, Extension} from "./run-serve.tsx";
|
||||
|
||||
const SocketsLive:Set<WebSocket> = new Set();
|
||||
const SocketsSend =(inData:string)=>{ console.log(inData); for (const socket of SocketsLive){ socket.send(inData); } }
|
||||
const SocketsSend =(inData:string)=>{ for (const socket of SocketsLive){ socket.send(inData); } }
|
||||
|
||||
Configure({
|
||||
SWCOp:
|
||||
@ -18,22 +18,22 @@ Configure({
|
||||
}
|
||||
}
|
||||
},
|
||||
Remap: (inImports)=>
|
||||
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, inProxy)
|
||||
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(inProxy+inURL.pathname);
|
||||
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)=>
|
||||
@ -97,4 +97,4 @@ const Watcher =async()=>
|
||||
}
|
||||
}
|
||||
|
||||
Watcher().then(()=>console.log("done watching"));
|
||||
Watcher();
|
@ -28,32 +28,35 @@ 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"])
|
||||
{
|
||||
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<string, string>}, inProxy:string)=>void|false|Response|Promise<Response|void|false>;
|
||||
type CustomRemapper = (inImports:Record<string, string>)=>Record<string, string>;
|
||||
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 CustomHTTPHandler = (inReq:Request, inURL:URL, inExt:string|false, inMap:{imports:Record<string, string>}, inConfig:Configuration)=>void|false|Response|Promise<Response|void|false>;
|
||||
type CustomRemapper = (inImports:Record<string, string>, inConfig:Configuration)=>Record<string, string>;
|
||||
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",
|
||||
Serve(inReq, inURL, inExt, inMap, inProxy){},
|
||||
Remap: (inImports)=>
|
||||
Spoof: "/@able",
|
||||
Serve(inReq, inURL, inExt, inMap, inConfig){},
|
||||
Remap: (inImports, inConfig)=>
|
||||
{
|
||||
const reactURL = inImports["react"];
|
||||
const setting = Configuration.SWCOp?.jsc?.transform?.react;
|
||||
@ -63,12 +66,9 @@ 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) );
|
||||
|
||||
const parts = Deno.mainModule.split(inProxy);
|
||||
const parts = Deno.mainModule.split(inConfig.Proxy);
|
||||
|
||||
return new Response(
|
||||
`<!doctype html>
|
||||
@ -81,7 +81,7 @@ let Configuration:Configuration =
|
||||
<div id="app"></div>
|
||||
<script type="importmap">${JSON.stringify(inMap)}</script>
|
||||
<script type="module">
|
||||
import Mount from "/_lib_/boot-browser.tsx";
|
||||
import Mount from "${inConfig.Spoof}/boot-browser.tsx";
|
||||
Mount("#app", "${parts[1]??"/app.tsx"}");
|
||||
</script>
|
||||
</body>
|
||||
@ -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;
|
||||
@ -192,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));
|
||||
@ -204,7 +204,6 @@ HTTP.serve(async(req: Request)=>
|
||||
{
|
||||
path = clipRoot + clipPath;
|
||||
}
|
||||
console.log("transpiling", path);
|
||||
code = await Transpile.Fetch(path, url.pathname, true);
|
||||
}
|
||||
else
|
||||
@ -222,7 +221,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;
|
||||
|
Loading…
Reference in New Issue
Block a user