Files
qqbot/preload.cjs
rianli f078f0d2f5 fix: preload.cjs 改为同步 require 加载 ESM,修复框架检测不到 register/activate 的问题
- preload.cjs: 移除异步 import() + Proxy 方案,改用 Node 22 原生 CJS require ESM
- package.json: 添加 postbuild 脚本,build 后自动同步产物到 extensions 目录
- upgrade-via-source.sh: 安装后将 extensions 副本替换为 symlink 指向源码目录
2026-03-25 23:41:08 +08:00

34 lines
1.1 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/**
* 插件预加载入口CJS 格式)。
*
* openclaw 框架通过 require() 加载插件,因此需要 .cjs 后缀
* 确保在 "type": "module" 的 package 中也能被正确 require()。
*
* 在 require 真正的插件代码(依赖 openclaw/plugin-sdk之前
* 先同步确保 node_modules/openclaw symlink 存在。
*/
"use strict";
const { ensurePluginSdkSymlink } = require("./scripts/link-sdk-core.cjs");
// 1) 同步创建 symlink
ensurePluginSdkSymlink(__dirname, "[preload]");
// 2) Node 22 原生支持 CJS require() 加载 ESM 模块
// 同步加载插件入口,确保框架同步检查 register/activate 时能找到
const _pluginModule = require("./dist/index.js");
// 3) 展平 default export框架检查 register/activate 在顶级属性
// ESM 的 export default 在 require() 后变成 { default: plugin, ... }
const _default = _pluginModule.default;
const merged = Object.assign({}, _pluginModule);
if (_default && typeof _default === "object") {
for (const key of Object.keys(_default)) {
if (!(key in merged)) {
merged[key] = _default[key];
}
}
}
module.exports = merged;