fix(plugin-sdk): stop library import warmup side effects

This commit is contained in:
Vincent Koc
2026-03-19 15:57:22 -07:00
parent 192151610f
commit 009f494cd9
4 changed files with 77 additions and 22 deletions

View File

@@ -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;
},

View File

@@ -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: {