Compare commits
No commits in common. "3a3fdcf5e22b84f1236d1ee71881eb29de0461a0" and "052dd13bb9958b5f96965a20665f1a52e5d9fbfd" have entirely different histories.
3a3fdcf5e2
...
052dd13bb9
@ -1,9 +1,6 @@
|
||||
|
||||
import * as Util from "@able/";
|
||||
import * as React from "react";
|
||||
import {createElement} from "react/client";
|
||||
|
||||
import('react').then((module) => {
|
||||
import('https://esm.sh/react').then((module) => {
|
||||
console.log(module);
|
||||
});
|
||||
|
||||
|
@ -57,11 +57,12 @@ let Configuration:Configuration =
|
||||
Spoof: "/@able",
|
||||
async Serve(inReq, inURL, inExt, inMap, inConfig)
|
||||
{
|
||||
if( inReq.headers.get("user-agent")?.startsWith("Deno") || inURL.searchParams.get("deno") )
|
||||
if(inReq.headers.get("user-agent")?.startsWith("Deno"))
|
||||
{
|
||||
const file = await fetch(inConfig.Proxy + inURL.pathname);
|
||||
const text = await file.text();
|
||||
return new Response(Transpile.Patch(text, "deno-"+inURL.pathname, inMap), {headers:{"content-type":"application/javascript"}} );
|
||||
|
||||
return new Response(Transpile.Patch(text), {headers:{"content-type":"application/javascript"}} );
|
||||
}
|
||||
},
|
||||
Remap: (inImports, inConfig)=>
|
||||
@ -138,76 +139,24 @@ export const Transpile =
|
||||
ImportMapReload();
|
||||
return size;
|
||||
},
|
||||
/**
|
||||
* Converts dynamic module imports in to static, also can resolve paths with an import map
|
||||
*/
|
||||
Patch(inText:string, inKey:string|false = false, inMap?:DenoConfig)
|
||||
Patch(inText)
|
||||
{
|
||||
|
||||
if(inKey)
|
||||
{
|
||||
const check = this.Cache.get(inKey);
|
||||
if(check)
|
||||
{
|
||||
return check;
|
||||
}
|
||||
}
|
||||
|
||||
const remap = inMap ? (inPath:string)=>
|
||||
{
|
||||
const match = inMap.imports[inPath];
|
||||
if(match)
|
||||
{
|
||||
return match;
|
||||
}
|
||||
else if(inPath.includes("/"))
|
||||
{
|
||||
let bestKey = "";
|
||||
let bestLength = 0;
|
||||
Object.keys(inMap.imports).forEach((key, i, arr)=>
|
||||
{
|
||||
if(key.endsWith("/") && inPath.startsWith(key) && key.length > bestLength)
|
||||
{
|
||||
bestKey = key;
|
||||
bestLength = bestLength;
|
||||
}
|
||||
});
|
||||
if(bestKey)
|
||||
{
|
||||
return inMap.imports[bestKey]+inPath.substring(bestKey.length);
|
||||
}
|
||||
}
|
||||
return inPath;
|
||||
}
|
||||
: (inPath:string)=>inPath;
|
||||
let match, regex;
|
||||
let convertedBody = inText;
|
||||
|
||||
// remap static imports
|
||||
regex = /from\s+(['"`])(.*?)\1/g;
|
||||
while ((match = regex.exec(inText)))
|
||||
{
|
||||
const importStatement = match[0];
|
||||
const importPath = match[2];
|
||||
convertedBody = convertedBody.replace(importStatement, `from "${remap(importPath)}"`);
|
||||
}
|
||||
|
||||
// convert dynamic imports into static (to work around deno deploy)
|
||||
const regex = /(?<![\w.])import\(([^)]+)(?!import\b)\)/g;
|
||||
const staticImports = [];
|
||||
regex = /(?<![\w.])import\(([^)]+)(?!import\b)\)/g;
|
||||
|
||||
let match;
|
||||
let convertedBody = inText;
|
||||
while ((match = regex.exec(inText)))
|
||||
{
|
||||
const importStatement = match[0];
|
||||
const importPath = remap(match[1].substring(1, match[1].length-1));
|
||||
const moduleName:string = `_dyn_${staticImports.length}`;
|
||||
const importContent = match[1];
|
||||
const moduleName = `_dyn_${staticImports.length}`;
|
||||
|
||||
staticImports.push(`import ${moduleName} from ${importPath};`);
|
||||
staticImports.push(`import ${moduleName} from ${importContent};`);
|
||||
convertedBody = convertedBody.replace(importStatement, `Promise.resolve(${moduleName})`);
|
||||
}
|
||||
convertedBody = staticImports.join("\n") + convertedBody;
|
||||
|
||||
inKey && this.Cache.set(inKey, convertedBody);
|
||||
return convertedBody;
|
||||
return staticImports.join("\n") + convertedBody;
|
||||
},
|
||||
Fetch: async function(inPath:string, inKey:string, inCheckCache=true)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user