





























@@ -1,13 +1,19 @@
11import fs from "node:fs";
22import path from "node:path";
3-import { pathToFileURL } from "node:url";
43import { getToolPluginMetadata, type ToolPluginMetadata } from "../plugin-sdk/tool-plugin.js";
54import {
65loadPluginManifest,
76PLUGIN_MANIFEST_FILENAME,
87resolvePackageExtensionEntries,
98} from "../plugins/manifest.js";
9+import { unwrapDefaultModuleExport } from "../plugins/module-export.js";
10+import {
11+createPluginModuleLoaderCache,
12+getCachedPluginModuleLoader,
13+} from "../plugins/plugin-module-loader-cache.js";
14+import { buildPluginLoaderAliasMap } from "../plugins/sdk-alias.js";
1015import { defaultRuntime } from "../runtime.js";
16+import { toSafeImportPath } from "../shared/import-specifier.js";
1117import { isRecord } from "../utils.js";
12181319type JsonObject = Record<string, unknown>;
@@ -34,6 +40,8 @@ type LoadedToolPlugin = {
3440metadata: ToolPluginMetadata;
3541};
364243+const toolPluginEntryModuleLoaders = createPluginModuleLoaderCache();
44+3745function readJsonFile(filePath: string): JsonObject {
3846return JSON.parse(fs.readFileSync(filePath, "utf8")) as JsonObject;
3947}
@@ -83,12 +91,21 @@ function readPackageManifest(rootDir: string): JsonObject {
8391}
84928593async function importToolPluginEntry(entryPath: string): Promise<unknown> {
86-const mod = (await import(pathToFileURL(entryPath).href)) as {
87-default?: unknown;
88-createEntry?: unknown;
89-entry?: unknown;
90-};
91-const candidate = mod.default ?? mod.createEntry ?? mod.entry;
94+const loader = getCachedPluginModuleLoader({
95+cache: toolPluginEntryModuleLoaders,
96+modulePath: entryPath,
97+importerUrl: import.meta.url,
98+loaderFilename: entryPath,
99+aliasMap: buildPluginLoaderAliasMap(entryPath, process.argv[1], import.meta.url),
100+});
101+const loaded = loader(toSafeImportPath(entryPath));
102+const mod =
103+loaded && typeof loaded === "object"
104+ ? (loaded as { default?: unknown; createEntry?: unknown; entry?: unknown })
105+ : undefined;
106+const candidate = unwrapDefaultModuleExport(
107+mod?.default ?? mod?.createEntry ?? mod?.entry ?? loaded,
108+);
92109return typeof candidate === "function" ? (candidate as () => unknown)() : candidate;
93110}
94111此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。