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-original":"https://esm.sh/preact@10.15.1/compat",
"@app": "./app.tsx"
"@able/": "./_lib_/"
},
"tasks":
{

View File

@ -1,4 +1,4 @@
import "../_lib_/boot.tsx";
import "@able/boot.tsx";
import React from "react";
const CTXString = React.createContext("lol");
@ -37,7 +37,7 @@ export default ()=>
const [Store, Dispatch] = React.useReducer(reducer, {name:"seth", age:24} as Store, builder)
return <CTXString.Provider value="intradestink">
<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>
<p>
<button onClick={e=>Dispatch(1)}>{Store.name}|{Store.age}?</button>

View File

@ -2,11 +2,12 @@
"compilerOptions": { "lib": ["deno.window", "dom"] },
"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":
{
"local": "deno run -A --no-lock app.tsx --dev",
"serve": "deno run -A --no-lock app.tsx"
"local": "deno run -A --no-lock --reload=http://localhost:4507 app.tsx --dev",
"serve": "deno run -A --no-lock --reload=http://localhost:4507 app.tsx"
}
}

View File

@ -20,18 +20,8 @@ Configure({
},
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"] = "/_lib_/react.tsx";
console.log(inImports);
return inImports;
},
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}"`);
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);
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>;
@ -35,20 +55,12 @@ let Configuration:Configuration =
Serve(inReq, inURL, inExt, inMap, inProxy){},
Remap: (inImports)=>
{
Object.entries(inImports).forEach(([key, value])=>
{
if(value.startsWith("./"))
{
inImports[key] = value.substring(1);
}
});
const reactURL = inImports["react"] ?? console.log("React is not defined in imports");
const reactURL = inImports["react"];
const setting = Configuration.SWCOp?.jsc?.transform?.react;
if(setting)
if(setting && reactURL)
{
setting.importSource = reactURL;
}
console.log(inImports);
return inImports;
},
Shell(inReq, inURL, inExt, inMap, inProxy)