import esbuild from 'esbuild' import path from 'node:path' import { fileURLToPath } from 'node:url' const __dirname = path.dirname(fileURLToPath(import.meta.url)) const repoRoot = path.resolve(__dirname, '../..') export async function loadModule(relPathFromRepoRoot) { const entryPoint = path.join(repoRoot, relPathFromRepoRoot) const result = await esbuild.build({ entryPoints: [entryPoint], bundle: true, format: 'esm', write: false, platform: 'neutral', }) const code = result.outputFiles[0].text const dataUrl = `data:text/javascript;base64,${Buffer.from(code).toString('base64')}` return import(dataUrl) }