mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-09 07:10:42 +00:00
refactor: simplify plugin module loading
This commit is contained in:
@@ -1,23 +1,23 @@
|
||||
import type { PluginJitiLoaderCache } from "./jiti-loader-cache.js";
|
||||
import { getCachedPluginJitiLoader } from "./jiti-loader-cache.js";
|
||||
import { withProfile } from "./plugin-load-profile.js";
|
||||
import type { PluginModuleLoaderCache } from "./plugin-module-loader-cache.js";
|
||||
import { getCachedPluginSourceModuleLoader } from "./plugin-module-loader-cache.js";
|
||||
|
||||
export type PluginSourceLoader = (modulePath: string) => unknown;
|
||||
|
||||
export function createPluginSourceLoader(): PluginSourceLoader {
|
||||
const loaders: PluginJitiLoaderCache = new Map();
|
||||
const loaders: PluginModuleLoaderCache = new Map();
|
||||
return (modulePath) => {
|
||||
const jiti = getCachedPluginJitiLoader({
|
||||
const sourceLoader = getCachedPluginSourceModuleLoader({
|
||||
cache: loaders,
|
||||
modulePath,
|
||||
importerUrl: import.meta.url,
|
||||
jitiFilename: import.meta.url,
|
||||
loaderFilename: import.meta.url,
|
||||
});
|
||||
// Direct source loads are not associated with a specific plugin id —
|
||||
// preserve the existing `plugin=(direct)` field used by tooling that
|
||||
// scrapes [plugin-load-profile] lines.
|
||||
return withProfile({ pluginId: "(direct)", source: modulePath }, "source-loader", () =>
|
||||
jiti(modulePath),
|
||||
sourceLoader(modulePath),
|
||||
);
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user