

























@@ -2,33 +2,12 @@
22// while packaged dist builds resolve a distinct runtime entry that cannot loop
33// back into this wrapper through the stable root runtime alias.
44import fs from "node:fs";
5-import { createRequire } from "node:module";
65import path from "node:path";
76import { fileURLToPath, pathToFileURL } from "node:url";
879-const require = createRequire(import.meta.url);
10-118const PLUGIN_ID = "matrix";
12-const OPENCLAW_PLUGIN_SDK_PACKAGE_NAMES = [
13-["openclaw", "plugin-sdk"].join("/"),
14-["@openclaw", "plugin-sdk"].join("/"),
15-];
16-const PLUGIN_SDK_EXPORT_PREFIX = "./plugin-sdk/";
17-const PLUGIN_SDK_SOURCE_EXTENSIONS = [".ts", ".mts", ".js", ".mjs", ".cts", ".cjs"];
189const PLUGIN_ENTRY_RUNTIME_BASENAME = "plugin-entry.handlers.runtime";
1910const NATIVE_RUNTIME_EXTENSIONS = [".js", ".mjs", ".cjs"];
20-const JITI_EXTENSIONS = [
21-".ts",
22-".tsx",
23-".mts",
24-".cts",
25-".mtsx",
26-".ctsx",
27-".js",
28-".mjs",
29-".cjs",
30-".json",
31-];
32113312function readPackageJson(packageRoot) {
3413try {
@@ -84,55 +63,6 @@ function resolveExistingFile(basePath, extensions) {
8463return null;
8564}
866587-function buildPluginSdkAliasMap(moduleUrl) {
88-const location = findOpenClawPackageRoot(path.dirname(fileURLToPath(moduleUrl)));
89-if (!location) {
90-return {};
91-}
92-93-const { packageRoot, packageJson } = location;
94-const sourcePluginSdkDir = path.join(packageRoot, "src", "plugin-sdk");
95-const distPluginSdkDir = path.join(packageRoot, "dist", "plugin-sdk");
96-const aliasMap = {};
97-const rootAlias =
98-resolveExistingFile(path.join(sourcePluginSdkDir, "root-alias"), [".cjs"]) ??
99-resolveExistingFile(path.join(distPluginSdkDir, "root-alias"), [".cjs"]);
100-if (rootAlias) {
101-for (const packageName of OPENCLAW_PLUGIN_SDK_PACKAGE_NAMES) {
102-aliasMap[packageName] = rootAlias;
103-}
104-}
105-106-for (const exportKey of Object.keys(packageJson.exports ?? {}).toSorted()) {
107-if (!exportKey.startsWith(PLUGIN_SDK_EXPORT_PREFIX)) {
108-continue;
109-}
110-const subpath = exportKey.slice(PLUGIN_SDK_EXPORT_PREFIX.length);
111-if (!/^[A-Za-z0-9][A-Za-z0-9_-]*$/.test(subpath)) {
112-continue;
113-}
114-const resolvedPath =
115-resolveExistingFile(path.join(sourcePluginSdkDir, subpath), PLUGIN_SDK_SOURCE_EXTENSIONS) ??
116-resolveExistingFile(path.join(distPluginSdkDir, subpath), [".js"]);
117-if (resolvedPath) {
118-for (const packageName of OPENCLAW_PLUGIN_SDK_PACKAGE_NAMES) {
119-aliasMap[`${packageName}/${subpath}`] = resolvedPath;
120-}
121-}
122-}
123-124-const extensionApi =
125-resolveExistingFile(
126-path.join(packageRoot, "src", "extensionAPI"),
127-PLUGIN_SDK_SOURCE_EXTENSIONS,
128-) ?? resolveExistingFile(path.join(packageRoot, "dist", "extensionAPI"), [".js"]);
129-if (extensionApi) {
130-aliasMap["openclaw/extension-api"] = extensionApi;
131-}
132-133-return aliasMap;
134-}
135-13666function resolveBundledPluginRuntimeModulePath(moduleUrl, params) {
13767const modulePath = fileURLToPath(moduleUrl);
13868const moduleDir = path.dirname(modulePath);
@@ -142,7 +72,7 @@ function resolveBundledPluginRuntimeModulePath(moduleUrl, params) {
14272];
1437314474for (const candidate of localCandidates) {
145-const resolved = resolveExistingFile(candidate, PLUGIN_SDK_SOURCE_EXTENSIONS);
75+const resolved = resolveExistingFile(candidate, NATIVE_RUNTIME_EXTENSIONS);
14676if (resolved) {
14777return resolved;
14878}
@@ -157,7 +87,7 @@ function resolveBundledPluginRuntimeModulePath(moduleUrl, params) {
15787];
1588815989for (const candidate of packageCandidates) {
160-const resolved = resolveExistingFile(candidate, PLUGIN_SDK_SOURCE_EXTENSIONS);
90+const resolved = resolveExistingFile(candidate, NATIVE_RUNTIME_EXTENSIONS);
16191if (resolved) {
16292return resolved;
16393}
@@ -170,17 +100,7 @@ function resolveBundledPluginRuntimeModulePath(moduleUrl, params) {
170100}
171101172102async function loadRuntimeModule(modulePath) {
173-if (NATIVE_RUNTIME_EXTENSIONS.includes(path.extname(modulePath))) {
174-return import(pathToFileURL(modulePath).href);
175-}
176-const { createJiti } = require("jiti");
177-const jiti = createJiti(import.meta.url, {
178-alias: buildPluginSdkAliasMap(import.meta.url),
179-interopDefault: true,
180-tryNative: false,
181-extensions: JITI_EXTENSIONS,
182-});
183-return jiti(modulePath);
103+return import(pathToFileURL(modulePath).href);
184104}
185105186106const mod = await loadRuntimeModule(
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。