mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-25 23:23:32 +00:00
refactor: harden outbound, matrix bootstrap, and plugin entry resolution
This commit is contained in:
@@ -4,7 +4,9 @@ import { openBoundaryFileSync } from "../infra/boundary-file-read.js";
|
||||
import { resolveConfigDir, resolveUserPath } from "../utils.js";
|
||||
import { resolveBundledPluginsDir } from "./bundled-dir.js";
|
||||
import {
|
||||
DEFAULT_PLUGIN_ENTRY_CANDIDATES,
|
||||
getPackageManifestMetadata,
|
||||
resolvePackageExtensionEntries,
|
||||
type OpenClawPackageManifest,
|
||||
type PackageManifest,
|
||||
} from "./manifest.js";
|
||||
@@ -243,14 +245,6 @@ function readPackageManifest(dir: string): PackageManifest | null {
|
||||
}
|
||||
}
|
||||
|
||||
function resolvePackageExtensions(manifest: PackageManifest): string[] {
|
||||
const raw = getPackageManifestMetadata(manifest)?.extensions;
|
||||
if (!Array.isArray(raw)) {
|
||||
return [];
|
||||
}
|
||||
return raw.map((entry) => (typeof entry === "string" ? entry.trim() : "")).filter(Boolean);
|
||||
}
|
||||
|
||||
function deriveIdHint(params: {
|
||||
filePath: string;
|
||||
packageName?: string;
|
||||
@@ -394,7 +388,8 @@ function discoverInDirectory(params: {
|
||||
}
|
||||
|
||||
const manifest = readPackageManifest(fullPath);
|
||||
const extensions = manifest ? resolvePackageExtensions(manifest) : [];
|
||||
const extensionResolution = resolvePackageExtensionEntries(manifest ?? undefined);
|
||||
const extensions = extensionResolution.status === "ok" ? extensionResolution.entries : [];
|
||||
|
||||
if (extensions.length > 0) {
|
||||
for (const extPath of extensions) {
|
||||
@@ -428,8 +423,7 @@ function discoverInDirectory(params: {
|
||||
continue;
|
||||
}
|
||||
|
||||
const indexCandidates = ["index.ts", "index.js", "index.mjs", "index.cjs"];
|
||||
const indexFile = indexCandidates
|
||||
const indexFile = [...DEFAULT_PLUGIN_ENTRY_CANDIDATES]
|
||||
.map((candidate) => path.join(fullPath, candidate))
|
||||
.find((candidate) => fs.existsSync(candidate));
|
||||
if (indexFile && isExtensionFile(indexFile)) {
|
||||
@@ -495,7 +489,8 @@ function discoverFromPath(params: {
|
||||
|
||||
if (stat.isDirectory()) {
|
||||
const manifest = readPackageManifest(resolved);
|
||||
const extensions = manifest ? resolvePackageExtensions(manifest) : [];
|
||||
const extensionResolution = resolvePackageExtensionEntries(manifest ?? undefined);
|
||||
const extensions = extensionResolution.status === "ok" ? extensionResolution.entries : [];
|
||||
|
||||
if (extensions.length > 0) {
|
||||
for (const extPath of extensions) {
|
||||
@@ -529,8 +524,7 @@ function discoverFromPath(params: {
|
||||
return;
|
||||
}
|
||||
|
||||
const indexCandidates = ["index.ts", "index.js", "index.mjs", "index.cjs"];
|
||||
const indexFile = indexCandidates
|
||||
const indexFile = [...DEFAULT_PLUGIN_ENTRY_CANDIDATES]
|
||||
.map((candidate) => path.join(resolved, candidate))
|
||||
.find((candidate) => fs.existsSync(candidate));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user