remap imports

This commit is contained in:
Seth Trowbridge 2023-06-20 22:56:20 -04:00
parent 47ef75c55b
commit 0e5caeada7
5 changed files with 29 additions and 26 deletions

View File

@ -7,7 +7,7 @@
{ {
"react":"https://esm.sh/preact@10.15.1/compat", "react":"https://esm.sh/preact@10.15.1/compat",
"react-original":"https://esm.sh/preact@10.15.1/compat", "react-original":"https://esm.sh/preact@10.15.1/compat",
"@app": "./app.tsx" "@able/": "./_lib_/"
}, },
"tasks": "tasks":
{ {

View File

@ -1,4 +1,4 @@
import "../_lib_/boot.tsx"; import "@able/boot.tsx";
import React from "react"; import React from "react";
const CTXString = React.createContext("lol"); const CTXString = React.createContext("lol");
@ -37,7 +37,7 @@ export default ()=>
const [Store, Dispatch] = React.useReducer(reducer, {name:"seth", age:24} as Store, builder) const [Store, Dispatch] = React.useReducer(reducer, {name:"seth", age:24} as Store, builder)
return <CTXString.Provider value="intradestink"> return <CTXString.Provider value="intradestink">
<div class="my-4 font-sans"> <div class="my-4 font-sans">
<h1 class="font-black text-xl text-red-500">Title?</h1> <h1 class="font-black text-xl text-red-500">Title????</h1>
<h2>subtitle!</h2> <h2>subtitle!</h2>
<p> <p>
<button onClick={e=>Dispatch(1)}>{Store.name}|{Store.age}?</button> <button onClick={e=>Dispatch(1)}>{Store.name}|{Store.age}?</button>

View File

@ -2,11 +2,12 @@
"compilerOptions": { "lib": ["deno.window", "dom"] }, "compilerOptions": { "lib": ["deno.window", "dom"] },
"imports": "imports":
{ {
"react":"https://esm.sh/preact@10.15.1/compat" "react":"https://esm.sh/preact@10.15.1/compat",
"@able/":"http://localhost:4507/_lib_/"
}, },
"tasks": "tasks":
{ {
"local": "deno run -A --no-lock app.tsx --dev", "local": "deno run -A --no-lock --reload=http://localhost:4507 app.tsx --dev",
"serve": "deno run -A --no-lock app.tsx" "serve": "deno run -A --no-lock --reload=http://localhost:4507 app.tsx"
} }
} }

View File

@ -20,18 +20,8 @@ Configure({
}, },
Remap: (inImports)=> Remap: (inImports)=>
{ {
console.log("running remapper");
Object.entries(inImports).forEach(([key, value])=>
{
if(value.startsWith("./"))
{
inImports[key] = value.substring(1);
}
});
inImports["react-original"] = inImports["react"]; inImports["react-original"] = inImports["react"];
inImports["react"] = "/_lib_/react.tsx"; inImports["react"] = "/_lib_/react.tsx";
console.log(inImports);
return inImports; return inImports;
}, },
async Serve(inReq, inURL, inExt, inMap, inProxy) async Serve(inReq, inURL, inExt, inMap, inProxy)

View File

@ -20,7 +20,27 @@ const ImportMapReload =async()=>
console.log(`error reading deno config "${path}" message:"${e}"`); console.log(`error reading deno config "${path}" message:"${e}"`);
return; return;
} }
Object.entries(json.imports).forEach(([key, value])=>
{
if(value.startsWith("./"))
{
json.imports[key] = value.substring(1);
}
});
if(!json.imports["@able/"])
{
console.log(`"@able/" specifier not defined in import map`);
}
json.imports["@able/"] = "/_lib_/";
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);
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 CustomHTTPHandler = (inReq:Request, inURL:URL, inExt:string|false, inMap:{imports:Record<string, string>}, inProxy:string)=>void|false|Response|Promise<Response|void|false>;
@ -35,20 +55,12 @@ let Configuration:Configuration =
Serve(inReq, inURL, inExt, inMap, inProxy){}, Serve(inReq, inURL, inExt, inMap, inProxy){},
Remap: (inImports)=> Remap: (inImports)=>
{ {
Object.entries(inImports).forEach(([key, value])=> const reactURL = inImports["react"];
{
if(value.startsWith("./"))
{
inImports[key] = value.substring(1);
}
});
const reactURL = inImports["react"] ?? console.log("React is not defined in imports");
const setting = Configuration.SWCOp?.jsc?.transform?.react; const setting = Configuration.SWCOp?.jsc?.transform?.react;
if(setting) if(setting && reactURL)
{ {
setting.importSource = reactURL; setting.importSource = reactURL;
} }
console.log(inImports);
return inImports; return inImports;
}, },
Shell(inReq, inURL, inExt, inMap, inProxy) Shell(inReq, inURL, inExt, inMap, inProxy)