
























@@ -6,13 +6,8 @@ import { openBoundaryFileSync } from "../infra/boundary-file-read.js";
66import { sameFileIdentity } from "../infra/file-identity.js";
77import { resolveBundledPluginsDir } from "./bundled-dir.js";
88import { getCachedPluginJitiLoader, type PluginJitiLoaderCache } from "./jiti-loader-cache.js";
9-import { tryNativeRequireJavaScriptModule } from "./native-module-require.js";
109import { resolveBundledPluginPublicSurfacePath } from "./public-surface-runtime.js";
11-import {
12-isBundledPluginExtensionPath,
13-resolvePluginLoaderJitiTryNative,
14-resolveLoaderPackageRoot,
15-} from "./sdk-alias.js";
10+import { resolvePluginLoaderJitiTryNative, resolveLoaderPackageRoot } from "./sdk-alias.js";
16111712const OPENCLAW_PACKAGE_ROOT =
1813resolveLoaderPackageRoot({
@@ -29,7 +24,6 @@ const publicSurfaceLocations = new Map<
2924} | null
3025>();
3126const jitiLoaders: PluginJitiLoaderCache = new Map();
32-const sharedBundledPublicSurfaceJitiLoaders: PluginJitiLoaderCache = new Map();
33273428function isSourceArtifactPath(modulePath: string): boolean {
3529switch (path.extname(modulePath).toLowerCase()) {
@@ -95,57 +89,23 @@ function resolvePublicSurfaceLocation(params: {
9589}
96909791function getJiti(modulePath: string) {
98-const tryNative = resolvePluginLoaderJitiTryNative(modulePath, { preferBuiltDist: true });
99-const sharedLoader = getSharedBundledPublicSurfaceJiti(modulePath, tryNative);
100-if (sharedLoader) {
101-return sharedLoader;
102-}
103-const loader = getCachedPluginJitiLoader({
92+return getCachedPluginJitiLoader({
10493cache: jitiLoaders,
10594 modulePath,
10695importerUrl: import.meta.url,
10796preferBuiltDist: true,
10897jitiFilename: import.meta.url,
10998});
110-return loader;
11199}
112100113101function loadPublicSurfaceModule(modulePath: string): unknown {
114102const tryNative = resolvePluginLoaderJitiTryNative(modulePath, { preferBuiltDist: true });
115-if (tryNative) {
116-const nativeModule = tryNativeRequireJavaScriptModule(modulePath, { allowWindows: true });
117-if (nativeModule.ok) {
118-return nativeModule.moduleExport;
119-}
120-}
121103if (canUseSourceArtifactRequire({ modulePath, tryNative })) {
122104return sourceArtifactRequire(modulePath);
123105}
124106return getJiti(modulePath)(modulePath);
125107}
126108127-function getSharedBundledPublicSurfaceJiti(modulePath: string, tryNative: boolean) {
128-const bundledPluginsDir = resolveBundledPluginsDir();
129-if (
130-!isBundledPluginExtensionPath({
131- modulePath,
132-openClawPackageRoot: OPENCLAW_PACKAGE_ROOT,
133- ...(bundledPluginsDir ? { bundledPluginsDir } : {}),
134-})
135-) {
136-return null;
137-}
138-const cacheKey = tryNative ? "bundled:native" : "bundled:source";
139-return getCachedPluginJitiLoader({
140-cache: sharedBundledPublicSurfaceJitiLoaders,
141- modulePath,
142-importerUrl: import.meta.url,
143-jitiFilename: import.meta.url,
144-cacheScopeKey: cacheKey,
145- tryNative,
146-});
147-}
148-149109// oxlint-disable-next-line typescript/no-unnecessary-type-parameters -- Dynamic public artifact loaders use caller-supplied module surface types.
150110export function loadBundledPluginPublicArtifactModuleSync<T extends object>(params: {
151111dirName: string;
@@ -157,21 +117,16 @@ export function loadBundledPluginPublicArtifactModuleSync<T extends object>(para
157117`Unable to resolve bundled plugin public surface ${params.dirName}/${params.artifactBasename}`,
158118);
159119}
160-const preparedLocation = location;
161-const cached =
162-loadedPublicSurfaceModules.get(location.modulePath) ??
163-loadedPublicSurfaceModules.get(preparedLocation.modulePath);
120+const cached = loadedPublicSurfaceModules.get(location.modulePath);
164121if (cached) {
165122return cached as T;
166123}
167124168125const opened = openBoundaryFileSync({
169-absolutePath: preparedLocation.modulePath,
170-rootPath: preparedLocation.boundaryRoot,
126+absolutePath: location.modulePath,
127+rootPath: location.boundaryRoot,
171128boundaryLabel:
172-preparedLocation.boundaryRoot === OPENCLAW_PACKAGE_ROOT
173- ? "OpenClaw package root"
174- : "plugin root",
129+location.boundaryRoot === OPENCLAW_PACKAGE_ROOT ? "OpenClaw package root" : "plugin root",
175130rejectHardlinks: true,
176131});
177132if (!opened.ok) {
@@ -193,15 +148,13 @@ export function loadBundledPluginPublicArtifactModuleSync<T extends object>(para
193148194149const sentinel = {} as T;
195150loadedPublicSurfaceModules.set(location.modulePath, sentinel);
196-loadedPublicSurfaceModules.set(preparedLocation.modulePath, sentinel);
197151loadedPublicSurfaceModules.set(validatedPath, sentinel);
198152try {
199153const loaded = loadPublicSurfaceModule(validatedPath) as T;
200154Object.assign(sentinel, loaded);
201155return sentinel;
202156} catch (error) {
203157loadedPublicSurfaceModules.delete(location.modulePath);
204-loadedPublicSurfaceModules.delete(preparedLocation.modulePath);
205158loadedPublicSurfaceModules.delete(validatedPath);
206159throw error;
207160}
@@ -218,5 +171,4 @@ export function resetBundledPluginPublicArtifactLoaderForTest(): void {
218171loadedPublicSurfaceModules.clear();
219172publicSurfaceLocations.clear();
220173jitiLoaders.clear();
221-sharedBundledPublicSurfaceJitiLoaders.clear();
222174}
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。