UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

42 lines (41 loc) 2.02 kB
import { a as getPluginCache } from "./plugin-cache-DGWspMEc.js"; import { c as resolveUserPath } from "./home-dir-BPhrG-aM.js"; import "./utils-P__uGsPB.js"; import { a as pluginCacheRealpathSync, r as pluginCacheExistsSync } from "./plugin-cache-files-DLPF_Tw2.js"; import { r as isPluginInPackageBundledRoots } from "./bundled-dir-BEfbEeCF.js"; import fs from "node:fs"; import path from "node:path"; //#region src/plugins/dev-source-root.ts /** Env var that points bundled-plugin lookup at an OpenClaw source checkout. */ const OPENCLAW_DEV_SOURCE_ROOT_ENV = "OPENCLAW_DEV_SOURCE_ROOT"; function readPackageName(packageJsonPath) { try { const parsed = JSON.parse(fs.readFileSync(packageJsonPath, "utf-8")); return typeof parsed.name === "string" ? parsed.name : null; } catch { return null; } } /** Resolves and validates the configured OpenClaw development source root. */ function resolveOpenClawDevSourceRoot(env = process.env) { const rawRoot = env[OPENCLAW_DEV_SOURCE_ROOT_ENV]?.trim(); if (!rawRoot) return null; const resolvedRoot = resolveUserPath(rawRoot, env); const roots = getPluginCache().sdk.devSourceRoots; if (roots.has(resolvedRoot)) return roots.get(resolvedRoot) ?? null; const realRoot = pluginCacheRealpathSync(resolvedRoot); const result = realRoot && readPackageName(path.join(realRoot, "package.json")) === "openclaw" && pluginCacheExistsSync(path.join(realRoot, "src")) && pluginCacheExistsSync(path.join(realRoot, "extensions")) ? realRoot : null; roots.set(resolvedRoot, result); return result; } /** Prioritizes already-bundled candidates; the selector itself never grants provenance. */ function isBundledPluginInsideDevSourceRoot(params) { const devSourceRoot = resolveOpenClawDevSourceRoot(params.env); if (!devSourceRoot) return false; return isPluginInPackageBundledRoots({ packageRoot: devSourceRoot, rootDir: resolveUserPath(params.rootDir, params.env) }); } //#endregion export { resolveOpenClawDevSourceRoot as n, isBundledPluginInsideDevSourceRoot as t };