Files
memind/wechat-mp-loader.mjs
T
john 6bc5d128d2 fix(wechat): deliver failure notices and hot-swappable wechat-mp bundle
Notify users when HTML publish guards reject stub pages instead of silently
failing, send real page links when non-stub files exist, and split wechat-mp
into wechat-mp.bundle.mjs for fast production updates without full portal rebuilds.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-07-04 12:52:59 +08:00

29 lines
882 B
JavaScript

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;
}