mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 06:40:44 +00:00
fix(plugins): share runtime boundary jiti cache helper
This commit is contained in:
@@ -3,6 +3,7 @@ import path from "node:path";
|
||||
import { afterEach, describe, expect, it } from "vitest";
|
||||
import { stageBundledPluginRuntime } from "../../scripts/stage-bundled-plugin-runtime.mjs";
|
||||
import { bundledDistPluginFile } from "../../test/helpers/bundled-plugin-paths.js";
|
||||
import type { PluginJitiLoaderCache } from "./jiti-loader-cache.js";
|
||||
import { loadPluginBoundaryModuleWithJiti } from "./runtime/runtime-plugin-boundary.js";
|
||||
import { cleanupTrackedTempDirs, makeTrackedTempDir } from "./test-helpers/fs-fixtures.js";
|
||||
|
||||
@@ -89,7 +90,7 @@ function createBundledWhatsAppRuntimeFixture() {
|
||||
}
|
||||
|
||||
function loadWhatsAppBoundaryModules(runtimePluginDir: string) {
|
||||
const loaders = new Map<boolean, ReturnType<typeof import("jiti").createJiti>>();
|
||||
const loaders: PluginJitiLoaderCache = new Map();
|
||||
return {
|
||||
light: loadPluginBoundaryModuleWithJiti<LightModule>(
|
||||
path.join(runtimePluginDir, "light-runtime-api.js"),
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
import fs from "node:fs";
|
||||
import path from "node:path";
|
||||
import { createJiti } from "jiti";
|
||||
import { loadConfig } from "../../config/config.js";
|
||||
import { getCachedPluginJitiLoader, type PluginJitiLoaderCache } from "../jiti-loader-cache.js";
|
||||
import { loadPluginManifestRegistry } from "../manifest-registry.js";
|
||||
import {
|
||||
buildPluginLoaderJitiOptions,
|
||||
resolvePluginSdkAliasFile,
|
||||
resolvePluginSdkScopedAliasMap,
|
||||
shouldPreferNativeJiti,
|
||||
@@ -119,15 +118,8 @@ export function resolvePluginRuntimeModulePath(
|
||||
return null;
|
||||
}
|
||||
|
||||
export function getPluginBoundaryJiti(
|
||||
modulePath: string,
|
||||
loaders: Map<boolean, ReturnType<typeof createJiti>>,
|
||||
) {
|
||||
export function getPluginBoundaryJiti(modulePath: string, loaders: PluginJitiLoaderCache) {
|
||||
const tryNative = shouldPreferNativeJiti(modulePath);
|
||||
const cached = loaders.get(tryNative);
|
||||
if (cached) {
|
||||
return cached;
|
||||
}
|
||||
const pluginSdkAlias = resolvePluginSdkAliasFile({
|
||||
srcFile: "root-alias.cjs",
|
||||
distFile: "root-alias.cjs",
|
||||
@@ -142,17 +134,19 @@ export function getPluginBoundaryJiti(
|
||||
: {}),
|
||||
...resolvePluginSdkScopedAliasMap({ modulePath }),
|
||||
};
|
||||
const loader = createJiti(import.meta.url, {
|
||||
...buildPluginLoaderJitiOptions(aliasMap),
|
||||
return getCachedPluginJitiLoader({
|
||||
cache: loaders,
|
||||
modulePath,
|
||||
importerUrl: import.meta.url,
|
||||
jitiFilename: import.meta.url,
|
||||
aliasMap,
|
||||
tryNative,
|
||||
});
|
||||
loaders.set(tryNative, loader);
|
||||
return loader;
|
||||
}
|
||||
|
||||
export function loadPluginBoundaryModuleWithJiti<TModule>(
|
||||
modulePath: string,
|
||||
loaders: Map<boolean, ReturnType<typeof createJiti>>,
|
||||
loaders: PluginJitiLoaderCache,
|
||||
): TModule {
|
||||
return getPluginBoundaryJiti(modulePath, loaders)(modulePath) as TModule;
|
||||
}
|
||||
@@ -162,7 +156,7 @@ export function createCachedPluginBoundaryModuleLoader<TModule>(
|
||||
): () => TModule | null {
|
||||
let cachedModulePath: string | null = null;
|
||||
let cachedModule: TModule | null = null;
|
||||
const loaders = new Map<boolean, ReturnType<typeof createJiti>>();
|
||||
const loaders: PluginJitiLoaderCache = new Map();
|
||||
|
||||
return () => {
|
||||
const missingLabel = params.missingLabel ?? `${params.pluginId} plugin runtime`;
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import type { AgentToolResult } from "@mariozechner/pi-agent-core";
|
||||
import { createJiti } from "jiti";
|
||||
import type { ChannelAgentTool } from "../../channels/plugins/types.core.js";
|
||||
import type { OpenClawConfig } from "../../config/types.openclaw.js";
|
||||
import {
|
||||
@@ -9,6 +8,7 @@ import {
|
||||
optimizeImageToJpeg as optimizeImageToJpegImpl,
|
||||
} from "../../media/web-media.js";
|
||||
import type { PollInput } from "../../polls.js";
|
||||
import type { PluginJitiLoaderCache } from "../jiti-loader-cache.js";
|
||||
import {
|
||||
loadPluginBoundaryModuleWithJiti,
|
||||
resolvePluginRuntimeRecordByEntryBaseNames,
|
||||
@@ -108,7 +108,7 @@ let cachedHeavyModule: WebChannelHeavyRuntimeModule | null = null;
|
||||
let cachedLightModulePath: string | null = null;
|
||||
let cachedLightModule: WebChannelLightRuntimeModule | null = null;
|
||||
|
||||
const jitiLoaders = new Map<boolean, ReturnType<typeof createJiti>>();
|
||||
const jitiLoaders: PluginJitiLoaderCache = new Map();
|
||||
|
||||
function resolveWebChannelPluginRecord(): WebChannelPluginRecord {
|
||||
return resolvePluginRuntimeRecordByEntryBaseNames(["light-runtime-api", "runtime-api"], () => {
|
||||
|
||||
Reference in New Issue
Block a user