From 85bfaf5386e77068ffe1da834506fcb2fa467c55 Mon Sep 17 00:00:00 2001 From: Seth Trowbridge Date: Sat, 1 Apr 2023 08:44:39 -0400 Subject: [PATCH] variablaize lib path --- server.tsx | 29 ++++++++++------------------- 1 file changed, 10 insertions(+), 19 deletions(-) diff --git a/server.tsx b/server.tsx index 8bac226..b9fa4c0 100644 --- a/server.tsx +++ b/server.tsx @@ -3,10 +3,7 @@ import * as MIME from "https://deno.land/std@0.180.0/media_types/mod.ts"; import { debounce } from "https://deno.land/std@0.151.0/async/debounce.ts"; const Transpiled = new Map(); -/** - * checks for (.tsx | .jsx | .ts | .js) extensions - */ -export const Transpileable =(inFilePath:string):boolean=> +const Transpileable =(inFilePath:string):boolean=> { let dotIndex = inFilePath.length-4; if(inFilePath[dotIndex] !== ".") @@ -25,14 +22,14 @@ export const Transpileable =(inFilePath:string):boolean=> return false; }; -export const Transpile =async(inCode:string, inKey:string):Promise=> +const Transpile =async(inCode:string, inKey:string):Promise=> { const transpile = await ESBuild.transform(inCode, { loader: "tsx", sourcemap: "inline", minify:true }); Transpiled.set(inKey, transpile.code); return transpile.code; }; type Transpiler = (inPath:string, inKey:string, inCheck?:boolean)=>Promise; -export const TranspileFS:Transpiler =async(inPath, inKey, inCheck)=> +const TranspileFS:Transpiler =async(inPath, inKey, inCheck)=> { if(inCheck) { @@ -45,7 +42,7 @@ export const TranspileFS:Transpiler =async(inPath, inKey, inCheck)=> const body = await Deno.readTextFile(inPath); return Transpile(body, inKey); }; -export const TranspileURL:Transpiler =async(inPath, inKey, inCheck)=> +const TranspileURL:Transpiler =async(inPath, inKey, inCheck)=> { if(inCheck) { @@ -62,7 +59,7 @@ export const TranspileURL:Transpiler =async(inPath, inKey, inCheck)=> }; - +const LibPath = "lib"; type ImportMap = {imports?:Record, importMap?:string}; let ImportString = ``; let ImportObject:ImportMap = {}; @@ -102,8 +99,7 @@ try if(importReact) { ImportObject.imports["react-original"] = importReact; - ImportObject.imports["react"] = "/lib/react.tsx"; - ImportObject.imports["hmr"] = "/lib/hmr.tsx"; + ImportObject.imports["react"] = `./${LibPath}/react.tsx`; ImportString = JSON.stringify(ImportObject); } else @@ -121,21 +117,16 @@ catch(e) { console.log(`deno.json not found`); } - - const Index = ` - + +
Loading
- -