SethTrowbridge/eno#2 add @eno/app mapping #4

Merged
SethTrowbridge merged 1 commits from issue/entry into master 2023-04-01 15:39:05 -04:00
3 changed files with 20 additions and 8 deletions

View File

@ -3,7 +3,9 @@
"deno.window", "DOM"
]},
"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":
{

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";
type ImportMap = {imports?:Record<string, string>, importMap?:string};
let ImportString = ``;
let ImportObject:ImportMap = {};
try
{
@ -75,7 +74,6 @@ try
try
{
ImportObject = JSON.parse(confImports);
ImportString = confImports;
}
catch(e)
{
@ -90,22 +88,31 @@ try
else if(confDenoParsed.imports)
{
ImportObject = {imports:confDenoParsed.imports};
ImportString = JSON.stringify(ImportObject);
}
if(ImportObject.imports)
{
const importReact = ImportObject.imports?.["react"];
const importReact = ImportObject.imports["react"];
if(importReact)
{
ImportObject.imports["react-original"] = importReact;
ImportObject.imports["react"] = `./${LibPath}/react.tsx`;
ImportString = JSON.stringify(ImportObject);
}
else
{
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
{
@ -122,7 +129,7 @@ const Index = `
<html>
<head>
<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>
</head>
<body>
@ -141,7 +148,7 @@ const Index = `
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";
render(H(()=>H(App)), ShadowDiv);