mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-28 01:21:36 +00:00
fix(plugin-sdk): stop library import warmup side effects
This commit is contained in:
@@ -113,6 +113,13 @@ const fastExports = {
|
||||
const target = { ...fastExports };
|
||||
let rootExports = null;
|
||||
|
||||
function shouldResolveMonolithic(prop) {
|
||||
if (typeof prop !== "string") {
|
||||
return false;
|
||||
}
|
||||
return prop !== "then";
|
||||
}
|
||||
|
||||
function getMonolithicSdk() {
|
||||
const loaded = tryLoadMonolithicSdk();
|
||||
if (loaded && typeof loaded === "object") {
|
||||
@@ -125,6 +132,9 @@ function getExportValue(prop) {
|
||||
if (Reflect.has(target, prop)) {
|
||||
return Reflect.get(target, prop);
|
||||
}
|
||||
if (!shouldResolveMonolithic(prop)) {
|
||||
return undefined;
|
||||
}
|
||||
const monolithic = getMonolithicSdk();
|
||||
if (!monolithic) {
|
||||
return undefined;
|
||||
@@ -137,6 +147,9 @@ function getExportDescriptor(prop) {
|
||||
if (ownDescriptor) {
|
||||
return ownDescriptor;
|
||||
}
|
||||
if (!shouldResolveMonolithic(prop)) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
const monolithic = getMonolithicSdk();
|
||||
if (!monolithic) {
|
||||
@@ -166,6 +179,9 @@ rootExports = new Proxy(target, {
|
||||
if (Reflect.has(target, prop)) {
|
||||
return true;
|
||||
}
|
||||
if (!shouldResolveMonolithic(prop)) {
|
||||
return false;
|
||||
}
|
||||
const monolithic = getMonolithicSdk();
|
||||
return monolithic ? Reflect.has(monolithic, prop) : false;
|
||||
},
|
||||
|
||||
@@ -109,6 +109,17 @@ describe("plugin-sdk root alias", () => {
|
||||
expect(lazyModule.jitiLoadCalls).toBe(0);
|
||||
});
|
||||
|
||||
it("does not load the monolithic sdk for promise-like or symbol reflection probes", () => {
|
||||
const lazyModule = loadRootAliasWithStubs();
|
||||
const lazyRootSdk = lazyModule.moduleExports;
|
||||
|
||||
expect("then" in lazyRootSdk).toBe(false);
|
||||
expect(Reflect.get(lazyRootSdk, Symbol.toStringTag)).toBeUndefined();
|
||||
expect(Object.getOwnPropertyDescriptor(lazyRootSdk, Symbol.toStringTag)).toBeUndefined();
|
||||
expect(lazyModule.createJitiCalls).toBe(0);
|
||||
expect(lazyModule.jitiLoadCalls).toBe(0);
|
||||
});
|
||||
|
||||
it("loads legacy root exports on demand and preserves reflection", () => {
|
||||
const lazyModule = loadRootAliasWithStubs({
|
||||
monolithicExports: {
|
||||
|
||||
Reference in New Issue
Block a user