console.log("MARKO"); export interface MarkoCacheEntry { src: string; scannedClientRefs: string[]; } export const markoCache = new Map(); export function loadMarko(module: NodeJS.Module, filepath: string) { let cache = markoCache.get(filepath); console.log({ filepath, has: !!cache }) if (!cache) { let src = fs.readFileSync(filepath, "utf8"); // A non-standard thing here is Clover Sitegen implements // its own client side scripting stuff, so it overrides // bare client import statements to it's own usage. const scannedClientRefs = new Set(); if (src.match(/^\s*client\s+import\s+["']/m)) { src = src.replace( /^\s*client\s+import\s+("[^"]+"|'[^']+')[^\n]+/m, (_, src) => { const ref = JSON.parse(`"${src.slice(1, -1)}"`); const resolved = hot.resolveClientRef(filepath, ref); scannedClientRefs.add(resolved); return ``; }, ) + '\nimport { addScript as CloverScriptInclude } from "#sitegen";\n'; } src = marko.compileSync(src, filepath).code; src = src.replace("marko/debug/html", "#ssr/marko"); cache = { src, scannedClientRefs: Array.from(scannedClientRefs) }; markoCache.set(filepath, cache); } const { src, scannedClientRefs } = cache; return hot.loadEsbuildCode(module, filepath, src, { scannedClientRefs, }); } import * as marko from "@marko/compiler"; import * as hot from "./hot.ts"; import * as fs from "#sitegen/fs";