add @eno/app mapping

This commit is contained in:
Seth Trowbridge 2023-04-01 15:34:50 -04:00
parent 5f9f03459c
commit c92407ab47
3 changed files with 20 additions and 8 deletions

View File

@ -3,7 +3,9 @@
"deno.window", "DOM" "deno.window", "DOM"
]}, ]},
"imports": { "imports": {
"react-original": "https://esm.sh/react@18.2.0" "react-original": "https://esm.sh/react@18.2.0",
"react": "https://esm.sh/react@18.2.0",
"@eno/app": "./dummy-app.tsx"
}, },
"tasks": "tasks":
{ {

3
dummy-app.tsx Normal file
View File

@ -0,0 +1,3 @@
import React from "react";
export default ()=> <div>dummy app</div>

View File

@ -61,7 +61,6 @@ const TranspileURL:Transpiler =async(inPath, inKey, inCheck)=>
const LibPath = "lib"; const LibPath = "lib";
type ImportMap = {imports?:Record<string, string>, importMap?:string}; type ImportMap = {imports?:Record<string, string>, importMap?:string};
let ImportString = ``;
let ImportObject:ImportMap = {}; let ImportObject:ImportMap = {};
try try
{ {
@ -75,7 +74,6 @@ try
try try
{ {
ImportObject = JSON.parse(confImports); ImportObject = JSON.parse(confImports);
ImportString = confImports;
} }
catch(e) catch(e)
{ {
@ -90,22 +88,31 @@ try
else if(confDenoParsed.imports) else if(confDenoParsed.imports)
{ {
ImportObject = {imports:confDenoParsed.imports}; ImportObject = {imports:confDenoParsed.imports};
ImportString = JSON.stringify(ImportObject);
} }
if(ImportObject.imports) if(ImportObject.imports)
{ {
const importReact = ImportObject.imports?.["react"]; const importReact = ImportObject.imports["react"];
if(importReact) if(importReact)
{ {
ImportObject.imports["react-original"] = importReact; ImportObject.imports["react-original"] = importReact;
ImportObject.imports["react"] = `./${LibPath}/react.tsx`; ImportObject.imports["react"] = `./${LibPath}/react.tsx`;
ImportString = JSON.stringify(ImportObject);
} }
else else
{ {
console.log(`"imports" configuration does not alias "react"`); console.log(`"imports" configuration does not alias "react"`);
} }
const importApp = ImportObject.imports["@eno/app"];
if(importApp)
{
}
else
{
console.log(`"imports" configuration does not alias an entry-point component with "@eno/app"`);
}
} }
else else
{ {
@ -122,7 +129,7 @@ const Index = `
<html> <html>
<head> <head>
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="viewport" content="width=device-width, initial-scale=1.0">
<script type="importmap">${ImportString}</script> <script type="importmap">${JSON.stringify(ImportObject)}</script>
<script async src="https://ga.jspm.io/npm:es-module-shims@1.5.1/dist/es-module-shims.js" crossorigin="anonymous"></script> <script async src="https://ga.jspm.io/npm:es-module-shims@1.5.1/dist/es-module-shims.js" crossorigin="anonymous"></script>
</head> </head>
<body> <body>
@ -141,7 +148,7 @@ const Index = `
TW.observe(TW.twind(Configure, TW.cssom(ShadowCSS)), ShadowDiv); TW.observe(TW.twind(Configure, TW.cssom(ShadowCSS)), ShadowDiv);
import App from "./app.tsx"; import App from "@eno/app";
import {render, createElement as H} from "react"; import {render, createElement as H} from "react";
render(H(()=>H(App)), ShadowDiv); render(H(()=>H(App)), ShadowDiv);