import fs from 'node:fs'; import path from 'node:path'; import { pathToFileURL } from 'node:url'; import { loadWechatMpConfig } from './wechat-mp-config.mjs'; export { loadWechatMpConfig }; let cachedModule = null; let cachedTarget = ''; let cachedMtime = 0; function resolveWechatMpEntry(root = process.cwd()) { const bundlePath = path.join(root, 'wechat-mp.bundle.mjs'); if (fs.existsSync(bundlePath)) return bundlePath; return path.join(root, 'wechat-mp.mjs'); } export async function loadWechatMpModule(root = process.cwd()) { const target = resolveWechatMpEntry(root); const mtime = fs.statSync(target).mtimeMs; if (cachedModule && cachedTarget === target && cachedMtime === mtime) { return cachedModule; } cachedModule = await import(`${pathToFileURL(target).href}?v=${mtime}`); cachedTarget = target; cachedMtime = mtime; return cachedModule; }