From 9045a7c644d9a60c4265373bad3d29eabb33ec1a Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Fri, 1 May 2026 21:49:13 +0100 Subject: [PATCH] refactor: remove bundled public surface runtime shim --- src/channels/plugins/bundled.ts | 3 -- .../doctor-contract-api.fast-path.test.ts | 5 --- src/channels/plugins/doctor-contract-api.ts | 1 - src/plugin-sdk/facade-loader.ts | 8 +--- .../bundled-public-surface-runtime-root.ts | 40 ------------------- src/plugins/provider-public-artifacts.test.ts | 2 - src/plugins/provider-public-artifacts.ts | 1 - src/plugins/public-surface-loader.ts | 8 +--- .../channel-contract-api.fast-path.test.ts | 2 - src/secrets/channel-contract-api.ts | 1 - src/secrets/target-registry.fast-path.test.ts | 1 - 11 files changed, 2 insertions(+), 70 deletions(-) delete mode 100644 src/plugins/bundled-public-surface-runtime-root.ts diff --git a/src/channels/plugins/bundled.ts b/src/channels/plugins/bundled.ts index 1ab2efa60de..4a20c18ce92 100644 --- a/src/channels/plugins/bundled.ts +++ b/src/channels/plugins/bundled.ts @@ -192,7 +192,6 @@ function loadGeneratedBundledChannelModule(params: { rootScope: BundledChannelRootScope; metadata: BundledChannelPluginMetadata; entry: BundledChannelPluginMetadata["source"] | BundledChannelPluginMetadata["setupSource"]; - installRuntimeDeps?: boolean; }): unknown { let modulePath = resolveGeneratedBundledChannelModulePath(params); if (!modulePath) { @@ -224,7 +223,6 @@ function loadGeneratedBundledChannelEntry(params: { rootScope: params.rootScope, metadata: params.metadata, entry: params.metadata.source, - installRuntimeDeps: false, }), ); if (!entry) { @@ -257,7 +255,6 @@ function loadGeneratedBundledChannelSetupEntry(params: { rootScope: params.rootScope, metadata: params.metadata, entry: params.metadata.setupSource, - installRuntimeDeps: false, }), ); if (!setupEntry) { diff --git a/src/channels/plugins/doctor-contract-api.fast-path.test.ts b/src/channels/plugins/doctor-contract-api.fast-path.test.ts index af047ff0d80..bded36ee150 100644 --- a/src/channels/plugins/doctor-contract-api.fast-path.test.ts +++ b/src/channels/plugins/doctor-contract-api.fast-path.test.ts @@ -54,7 +54,6 @@ describe("channel doctor contract api fast path", () => { expect(loadBundledPluginPublicArtifactModuleSyncMock).toHaveBeenCalledWith({ dirName: "discord", artifactBasename: "doctor-contract-api.js", - installRuntimeDeps: false, }); }); @@ -65,12 +64,10 @@ describe("channel doctor contract api fast path", () => { expect(loadBundledPluginPublicArtifactModuleSyncMock).toHaveBeenCalledWith({ dirName: "whatsapp", artifactBasename: "doctor-contract-api.js", - installRuntimeDeps: false, }); expect(loadBundledPluginPublicArtifactModuleSyncMock).not.toHaveBeenCalledWith({ dirName: "whatsapp", artifactBasename: "contract-api.js", - installRuntimeDeps: false, }); }); @@ -86,12 +83,10 @@ describe("channel doctor contract api fast path", () => { expect(loadBundledPluginPublicArtifactModuleSyncMock).toHaveBeenCalledWith({ dirName: "telegram", artifactBasename: "doctor-contract-api.js", - installRuntimeDeps: false, }); expect(loadBundledPluginPublicArtifactModuleSyncMock).not.toHaveBeenCalledWith({ dirName: "telegram", artifactBasename: "contract-api.js", - installRuntimeDeps: false, }); }); }); diff --git a/src/channels/plugins/doctor-contract-api.ts b/src/channels/plugins/doctor-contract-api.ts index 05879b37064..69657674b94 100644 --- a/src/channels/plugins/doctor-contract-api.ts +++ b/src/channels/plugins/doctor-contract-api.ts @@ -23,7 +23,6 @@ function loadBundledChannelPublicArtifact( return loadBundledPluginPublicArtifactModuleSync({ dirName: channelId, artifactBasename, - installRuntimeDeps: false, }); } catch (error) { if ( diff --git a/src/plugin-sdk/facade-loader.ts b/src/plugin-sdk/facade-loader.ts index 79439f393d6..571d4ba3a92 100644 --- a/src/plugin-sdk/facade-loader.ts +++ b/src/plugin-sdk/facade-loader.ts @@ -4,7 +4,6 @@ import path from "node:path"; import { fileURLToPath, pathToFileURL } from "node:url"; import { openBoundaryFileSync } from "../infra/boundary-file-read.js"; import { resolveBundledPluginsDir } from "../plugins/bundled-dir.js"; -import { prepareBuiltBundledPluginPublicSurfaceLocation } from "../plugins/bundled-public-surface-runtime-root.js"; import { getCachedPluginJitiLoader, type PluginJitiLoaderCache, @@ -212,7 +211,6 @@ export async function loadBundledPluginPublicSurfaceModule(par dirName: string; artifactBasename: string; trackedPluginId?: string | (() => string); - env?: NodeJS.ProcessEnv; }): Promise { const location = resolveFacadeModuleLocation(params); if (!location) { @@ -220,11 +218,7 @@ export async function loadBundledPluginPublicSurfaceModule(par `Unable to resolve bundled plugin public surface ${params.dirName}/${params.artifactBasename}`, ); } - const preparedLocation = prepareBuiltBundledPluginPublicSurfaceLocation({ - location, - pluginId: params.dirName, - ...(params.env ? { env: params.env } : {}), - }); + const preparedLocation = location; const cached = loadedFacadeModules.get(preparedLocation.modulePath); if (cached) { return cached as T; diff --git a/src/plugins/bundled-public-surface-runtime-root.ts b/src/plugins/bundled-public-surface-runtime-root.ts deleted file mode 100644 index 4b10ea0f936..00000000000 --- a/src/plugins/bundled-public-surface-runtime-root.ts +++ /dev/null @@ -1,40 +0,0 @@ -import path from "node:path"; - -export type BundledPublicSurfaceLocation = { - modulePath: string; - boundaryRoot: string; -}; - -function isBuiltBundledPluginRoot(rootDir: string): boolean { - return rootDir.replace(/\\/g, "/").includes("/dist/extensions/"); -} - -export function resolveBuiltBundledPluginRootFromModulePath(params: { - modulePath: string; - pluginId: string; -}): string | null { - const resolvedModulePath = path.resolve(params.modulePath); - let currentDir = path.dirname(resolvedModulePath); - while (true) { - if (path.basename(currentDir) === params.pluginId && isBuiltBundledPluginRoot(currentDir)) { - const relativePath = path.relative(currentDir, resolvedModulePath); - if (!relativePath.startsWith("..") && !path.isAbsolute(relativePath)) { - return currentDir; - } - } - const parentDir = path.dirname(currentDir); - if (parentDir === currentDir) { - return null; - } - currentDir = parentDir; - } -} - -export function prepareBuiltBundledPluginPublicSurfaceLocation(params: { - location: BundledPublicSurfaceLocation; - pluginId: string; - env?: NodeJS.ProcessEnv; - installRuntimeDeps?: boolean; -}): BundledPublicSurfaceLocation { - return params.location; -} diff --git a/src/plugins/provider-public-artifacts.test.ts b/src/plugins/provider-public-artifacts.test.ts index fff9e0bc8b1..0ffb3d7085a 100644 --- a/src/plugins/provider-public-artifacts.test.ts +++ b/src/plugins/provider-public-artifacts.test.ts @@ -68,7 +68,6 @@ describe("provider public artifacts", () => { expect(loadBundledPluginPublicArtifactModuleSync).toHaveBeenCalledWith({ dirName: "openai", artifactBasename: "provider-policy-api.js", - installRuntimeDeps: false, }); expect( surface @@ -109,7 +108,6 @@ describe("provider public artifacts", () => { expect(loadBundledPluginPublicArtifactModuleSync).toHaveBeenCalledWith({ dirName: "openai", artifactBasename: "provider-policy-api.js", - installRuntimeDeps: false, }); }); }); diff --git a/src/plugins/provider-public-artifacts.ts b/src/plugins/provider-public-artifacts.ts index 8a8a92a9613..41d5f73f322 100644 --- a/src/plugins/provider-public-artifacts.ts +++ b/src/plugins/provider-public-artifacts.ts @@ -48,7 +48,6 @@ function tryLoadBundledProviderPolicySurface( const mod = loadBundledPluginPublicArtifactModuleSync>({ dirName: pluginId, artifactBasename, - installRuntimeDeps: false, }); if (hasProviderPolicyHook(mod)) { return mod; diff --git a/src/plugins/public-surface-loader.ts b/src/plugins/public-surface-loader.ts index ff59502804c..96e2b838367 100644 --- a/src/plugins/public-surface-loader.ts +++ b/src/plugins/public-surface-loader.ts @@ -5,7 +5,6 @@ import { fileURLToPath } from "node:url"; import { openBoundaryFileSync } from "../infra/boundary-file-read.js"; import { sameFileIdentity } from "../infra/file-identity.js"; import { resolveBundledPluginsDir } from "./bundled-dir.js"; -import { prepareBuiltBundledPluginPublicSurfaceLocation } from "./bundled-public-surface-runtime-root.js"; import { getCachedPluginJitiLoader, type PluginJitiLoaderCache } from "./jiti-loader-cache.js"; import { tryNativeRequireJavaScriptModule } from "./native-module-require.js"; import { resolveBundledPluginPublicSurfacePath } from "./public-surface-runtime.js"; @@ -151,7 +150,6 @@ function getSharedBundledPublicSurfaceJiti(modulePath: string, tryNative: boolea export function loadBundledPluginPublicArtifactModuleSync(params: { dirName: string; artifactBasename: string; - installRuntimeDeps?: boolean; }): T { const location = resolvePublicSurfaceLocation(params); if (!location) { @@ -159,11 +157,7 @@ export function loadBundledPluginPublicArtifactModuleSync(para `Unable to resolve bundled plugin public surface ${params.dirName}/${params.artifactBasename}`, ); } - const preparedLocation = prepareBuiltBundledPluginPublicSurfaceLocation({ - location, - pluginId: params.dirName, - installRuntimeDeps: params.installRuntimeDeps, - }); + const preparedLocation = location; const cached = loadedPublicSurfaceModules.get(location.modulePath) ?? loadedPublicSurfaceModules.get(preparedLocation.modulePath); diff --git a/src/secrets/channel-contract-api.fast-path.test.ts b/src/secrets/channel-contract-api.fast-path.test.ts index a250e9bed69..398a00bff64 100644 --- a/src/secrets/channel-contract-api.fast-path.test.ts +++ b/src/secrets/channel-contract-api.fast-path.test.ts @@ -58,7 +58,6 @@ describe("channel contract api explicit fast path", () => { expect(loadBundledPluginPublicArtifactModuleSyncMock).toHaveBeenCalledWith({ dirName: "bluebubbles", artifactBasename: "secret-contract-api.js", - installRuntimeDeps: false, }); expect(api?.secretTargetRegistryEntries).toEqual( expect.arrayContaining([ @@ -80,7 +79,6 @@ describe("channel contract api explicit fast path", () => { expect(loadBundledPluginPublicArtifactModuleSyncMock).toHaveBeenCalledWith({ dirName: "whatsapp", artifactBasename: "security-contract-api.js", - installRuntimeDeps: false, }); expect(loadPluginManifestRegistryMock).not.toHaveBeenCalled(); }); diff --git a/src/secrets/channel-contract-api.ts b/src/secrets/channel-contract-api.ts index 74fe3a897b6..4401f131fc1 100644 --- a/src/secrets/channel-contract-api.ts +++ b/src/secrets/channel-contract-api.ts @@ -30,7 +30,6 @@ function loadBundledChannelPublicArtifact( return loadBundledPluginPublicArtifactModuleSync({ dirName: channelId, artifactBasename, - installRuntimeDeps: false, }); } catch (error) { if ( diff --git a/src/secrets/target-registry.fast-path.test.ts b/src/secrets/target-registry.fast-path.test.ts index e172efbbee1..98f1567087c 100644 --- a/src/secrets/target-registry.fast-path.test.ts +++ b/src/secrets/target-registry.fast-path.test.ts @@ -59,7 +59,6 @@ describe("secret target registry fast path", () => { expect(loadBundledPluginPublicArtifactModuleSyncMock).toHaveBeenCalledWith({ dirName: "googlechat", artifactBasename: "secret-contract-api.js", - installRuntimeDeps: false, }); expect(loadPluginManifestRegistryMock).not.toHaveBeenCalled(); });