openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
42 lines (41 loc) • 1.09 kB
JavaScript
//#region src/plugins/module-export.ts
/** Unwraps nested default exports produced by mixed ESM/CJS plugin bundles. */
function unwrapDefaultModuleExport(e) {
let t = e;
const n = /* @__PURE__ */ new Set();
while (t && typeof t === "object" && "default" in t && !n.has(t)) {
n.add(t);
t = t.default;
}
return t;
}
function resolvePluginModuleExport(e) {
const t = /* @__PURE__ */ new Set();
const n = [unwrapDefaultModuleExport(e), e];
for (let e = 0; e < n.length && e < 12; e += 1) {
const r = n[e];
if (t.has(r)) continue;
t.add(r);
if (typeof r === "function") return { register: r };
if (r && typeof r === "object") {
const e = r;
const t = e.register;
if (typeof t === "function") return {
definition: e,
register: t
};
for (const t of ["default", "module"]) if (t in e) n.push(Reflect.get(e, t));
}
}
const r = n[0];
if (r && typeof r === "object") {
const e = r;
return {
definition: e,
register: e.register
};
}
return {};
}
//#endregion
export { unwrapDefaultModuleExport as n, resolvePluginModuleExport as t };