7609c37d5f
新增 miniprogram/shell 承接微信 Page 生命周期与 wx 容器调用 收窄微信页面入口为 shell 页面工厂装配 更新三端 host-bridge/shell 目录门禁与认证 smoke 补充微信 shell 测试与 CommonJS 测试加载工具 同步宿主壳架构文档和项目共享记忆 补齐 api-server 外部生成测试 fixture 更新时间字段
32 lines
760 B
JavaScript
32 lines
760 B
JavaScript
import { readFileSync } from 'node:fs';
|
|
import vm from 'node:vm';
|
|
|
|
export function loadCommonJsModule(filePath, requireMap = {}) {
|
|
const module = { exports: {} };
|
|
const sandbox = {
|
|
clearTimeout,
|
|
console,
|
|
getCurrentPages(...args) {
|
|
return globalThis.getCurrentPages(...args);
|
|
},
|
|
module,
|
|
exports: module.exports,
|
|
require(requestPath) {
|
|
if (Object.prototype.hasOwnProperty.call(requireMap, requestPath)) {
|
|
return requireMap[requestPath];
|
|
}
|
|
throw new Error(`Unexpected require: ${requestPath}`);
|
|
},
|
|
setTimeout,
|
|
URL,
|
|
URLSearchParams,
|
|
wx: globalThis.wx,
|
|
};
|
|
|
|
vm.runInNewContext(readFileSync(filePath, 'utf8'), sandbox, {
|
|
filename: filePath,
|
|
});
|
|
|
|
return module.exports;
|
|
}
|