lit-ssr-utils
Version:
Lit utils to implement SSR to projects that do not use Javascript.
2 lines (1 loc) • 628 B
JavaScript
import A from"fs";import B from"fs/promises";import E from"path";import F from"../crypto/sha1";var D=function(j,k){return j.match(new RegExp(k,"g"))?.length??0},H=function(){let j=import.meta.dir,k=D(j,"src");if(k===0)return console.error("getRoot() failed to find root"),j;while(!0)if(j=E.resolve(j,"../"),k!==D(j,"src"))break;return j},w=new Map,C="./tmp";if(!A.existsSync(C))A.mkdirSync(C,744);var G=H();async function I(j,k="ts"){const q=F(j);if(w.has(q))return w.get(q);const v=E.resolve(import.meta.dir,`${G}/tmp/${q}.${k}`);await B.writeFile(v,j);const z=await import(v);return w.set(q,z),B.rm(v),z}export{I as default};