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>
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
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;
|
||||
}
|
||||
Reference in New Issue
Block a user