mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-04 20:40:23 +00:00
refactor: share bundled loader Jiti config helpers
This commit is contained in:
@@ -8,7 +8,8 @@ import { resolveBundledPluginPublicSurfacePath } from "./public-surface-runtime.
|
||||
import {
|
||||
buildPluginLoaderAliasMap,
|
||||
buildPluginLoaderJitiOptions,
|
||||
resolvePluginLoaderJitiTryNative,
|
||||
isBundledPluginExtensionPath,
|
||||
resolvePluginLoaderJitiConfig,
|
||||
resolveLoaderPackageRoot,
|
||||
} from "./sdk-alias.js";
|
||||
|
||||
@@ -70,18 +71,16 @@ function resolvePublicSurfaceLocation(params: {
|
||||
}
|
||||
|
||||
function getJiti(modulePath: string) {
|
||||
const tryNative = resolvePluginLoaderJitiTryNative(modulePath, {
|
||||
const { tryNative, aliasMap, cacheKey } = resolvePluginLoaderJitiConfig({
|
||||
modulePath,
|
||||
argv1: process.argv[1],
|
||||
moduleUrl: import.meta.url,
|
||||
preferBuiltDist: true,
|
||||
});
|
||||
const sharedLoader = getSharedBundledPublicSurfaceJiti(modulePath, tryNative);
|
||||
if (sharedLoader) {
|
||||
return sharedLoader;
|
||||
}
|
||||
const aliasMap = buildPluginLoaderAliasMap(modulePath, process.argv[1], import.meta.url);
|
||||
const cacheKey = JSON.stringify({
|
||||
tryNative,
|
||||
aliasMap: Object.entries(aliasMap).toSorted(([left], [right]) => left.localeCompare(right)),
|
||||
});
|
||||
const cached = jitiLoaders.get(cacheKey);
|
||||
if (cached) {
|
||||
return cached;
|
||||
@@ -99,18 +98,13 @@ function getSharedBundledPublicSurfaceJiti(
|
||||
tryNative: boolean,
|
||||
): ReturnType<typeof createJiti> | null {
|
||||
const bundledPluginsDir = resolveBundledPluginsDir();
|
||||
const normalizedModulePath = path.resolve(modulePath);
|
||||
const sharedRoots = [
|
||||
bundledPluginsDir ? path.resolve(bundledPluginsDir) : null,
|
||||
path.join(OPENCLAW_PACKAGE_ROOT, "extensions"),
|
||||
path.join(OPENCLAW_PACKAGE_ROOT, "dist", "extensions"),
|
||||
path.join(OPENCLAW_PACKAGE_ROOT, "dist-runtime", "extensions"),
|
||||
].filter((root): root is string => typeof root === "string");
|
||||
const isBundledPublicSurface = sharedRoots.some(
|
||||
(root) =>
|
||||
normalizedModulePath === root || normalizedModulePath.startsWith(`${root}${path.sep}`),
|
||||
);
|
||||
if (!isBundledPublicSurface) {
|
||||
if (
|
||||
!isBundledPluginExtensionPath({
|
||||
modulePath,
|
||||
openClawPackageRoot: OPENCLAW_PACKAGE_ROOT,
|
||||
...(bundledPluginsDir ? { bundledPluginsDir } : {}),
|
||||
})
|
||||
) {
|
||||
return null;
|
||||
}
|
||||
const cacheKey = tryNative ? "bundled:native" : "bundled:source";
|
||||
|
||||
Reference in New Issue
Block a user