mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 05:50:43 +00:00
refactor: remove bundled public surface runtime shim
This commit is contained in:
@@ -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) {
|
||||
|
||||
@@ -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,
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -23,7 +23,6 @@ function loadBundledChannelPublicArtifact(
|
||||
return loadBundledPluginPublicArtifactModuleSync<BundledChannelDoctorContractApi>({
|
||||
dirName: channelId,
|
||||
artifactBasename,
|
||||
installRuntimeDeps: false,
|
||||
});
|
||||
} catch (error) {
|
||||
if (
|
||||
|
||||
@@ -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<T extends object>(par
|
||||
dirName: string;
|
||||
artifactBasename: string;
|
||||
trackedPluginId?: string | (() => string);
|
||||
env?: NodeJS.ProcessEnv;
|
||||
}): Promise<T> {
|
||||
const location = resolveFacadeModuleLocation(params);
|
||||
if (!location) {
|
||||
@@ -220,11 +218,7 @@ export async function loadBundledPluginPublicSurfaceModule<T extends object>(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;
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
@@ -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,
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -48,7 +48,6 @@ function tryLoadBundledProviderPolicySurface(
|
||||
const mod = loadBundledPluginPublicArtifactModuleSync<Record<string, unknown>>({
|
||||
dirName: pluginId,
|
||||
artifactBasename,
|
||||
installRuntimeDeps: false,
|
||||
});
|
||||
if (hasProviderPolicyHook(mod)) {
|
||||
return mod;
|
||||
|
||||
@@ -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<T extends object>(params: {
|
||||
dirName: string;
|
||||
artifactBasename: string;
|
||||
installRuntimeDeps?: boolean;
|
||||
}): T {
|
||||
const location = resolvePublicSurfaceLocation(params);
|
||||
if (!location) {
|
||||
@@ -159,11 +157,7 @@ export function loadBundledPluginPublicArtifactModuleSync<T extends object>(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);
|
||||
|
||||
@@ -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();
|
||||
});
|
||||
|
||||
@@ -30,7 +30,6 @@ function loadBundledChannelPublicArtifact(
|
||||
return loadBundledPluginPublicArtifactModuleSync<BundledChannelContractApi>({
|
||||
dirName: channelId,
|
||||
artifactBasename,
|
||||
installRuntimeDeps: false,
|
||||
});
|
||||
} catch (error) {
|
||||
if (
|
||||
|
||||
@@ -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();
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user