惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

V
V2EX
J
Java Code Geeks
月光博客
月光博客
博客园_首页
The GitHub Blog
The GitHub Blog
Vercel News
Vercel News
B
Blog RSS Feed
博客园 - 聂微东
宝玉的分享
宝玉的分享
T
Tailwind CSS Blog
Jina AI
Jina AI
S
SegmentFault 最新的问题
B
Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
有赞技术团队
有赞技术团队
Hugging Face - Blog
Hugging Face - Blog
Google DeepMind News
Google DeepMind News
阮一峰的网络日志
阮一峰的网络日志
The Cloudflare Blog
量子位
Martin Fowler
Martin Fowler
博客园 - Franky
大猫的无限游戏
大猫的无限游戏
博客园 - 叶小钗

Recent Commits to openclaw:main

test: merge chat side-result checks · openclaw/openclaw@ddd2c2a test: merge cron history checks · openclaw/openclaw@f7eb746 test: merge responsive navigation shell checks · openclaw/openclaw@c2e4b47 docs(changelog): add codex oauth fixes · openclaw/openclaw@628e6cd test: merge navigation routing cases · openclaw/openclaw@5d8cecb Tests: mock channel registry bundled fallback · openclaw/openclaw@2b08233 Secrets: avoid broad web search discovery for single plugin config · openclaw/openclaw@a464f59 test: merge config view browser checks · openclaw/openclaw@20cf511 fix(status): align oauth health with runtime · openclaw/openclaw@eed7116 feat: add macOS screen snapshots for monitor preview (#67954) thanks … · openclaw/openclaw@f377db1 fix: report shared auth scopes in hello-ok (#67810) thanks @BunsDev · openclaw/openclaw@0b6c39b Auto-reply: avoid eager bundled route fallback · openclaw/openclaw@3ea1bf4 Tests: narrow session binding contract setup · openclaw/openclaw@54e4e16 fix(macOS): enable undo/redo in webchat composer text input (#34962) · openclaw/openclaw@00951dc Tests: speed up channel setup promotion · openclaw/openclaw@82b529a Docs: refresh agent instructions · openclaw/openclaw@5775fe2 fix(auth): serialize OAuth refresh across agents to fix #26322 (#67876) · openclaw/openclaw@8e79080 test: allow ollama public surface boundary test · openclaw/openclaw@7d4f1a6 Docs: add test performance guardrails · openclaw/openclaw@89706d3 Tests: restore context-engine usage proof · openclaw/openclaw@e4c4f95 Tests: slim context engine runtime coverage · openclaw/openclaw@74c198f ci: retry failed custom checkouts · openclaw/openclaw@0ee5baf test: trim duplicate provider auth onboarding cases · openclaw/openclaw@1ffc02e matrix: fix sessions_spawn --thread subagent session spawning (#67643) · openclaw/openclaw@1ce2596 test: reduce auth choice fixture churn · openclaw/openclaw@857b9cd test: mock health status config boundaries · openclaw/openclaw@9d5ab4a test: mock onboard config io boundary · openclaw/openclaw@299694d test: mock legacy state plugin boundaries · openclaw/openclaw@2713089 test: mock channel install boundaries · openclaw/openclaw@b945248 test: mock doctor preview channel boundaries · openclaw/openclaw@b1a3ad4
fix(plugin-sdk): symlink openclaw peerDependencies after ...
anishesg · 2026-04-24 · via Recent Commits to openclaw:main

@@ -8,6 +8,7 @@ import {

88

unscopedPackageName,

99

} from "../infra/install-safe-path.js";

1010

import { type NpmIntegrityDrift, type NpmSpecResolution } from "../infra/install-source-utils.js";

11+

import { resolveOpenClawPackageRootSync } from "../infra/openclaw-root.js";

1112

import { normalizeOptionalString } from "../shared/string-coerce.js";

1213

import { CONFIG_DIR, resolveUserPath } from "../utils.js";

1314

import type { InstallSecurityScanResult } from "./install-security-scan.js";

@@ -31,6 +32,7 @@ type PluginInstallLogger = {

31323233

type PackageManifest = PluginPackageManifest & {

3334

dependencies?: Record<string, string>;

35+

peerDependencies?: Record<string, string>;

3436

};

35373638

const MISSING_EXTENSIONS_ERROR =

@@ -608,6 +610,71 @@ async function detectNativePackageInstallSource(packageDir: string): Promise<boo

608610

}

609611

}

610612613+

/**

614+

* After npm install completes, symlink any peerDependencies that name the host

615+

* openclaw package into the plugin's node_modules/ directory. npm never

616+

* materialises peerDependencies automatically, so plugins that moved openclaw

617+

* from dependencies → peerDependencies would fail at runtime without this.

618+

*/

619+

async function linkOpenClawPeerDependencies(params: {

620+

installedDir: string;

621+

peerDependencies: Record<string, string>;

622+

logger: PluginInstallLogger;

623+

}): Promise<void> {

624+

const OPENCLAW_PEER_NAMES = new Set(["openclaw"]);

625+

const peers = Object.keys(params.peerDependencies).filter((name) =>

626+

OPENCLAW_PEER_NAMES.has(name),

627+

);

628+

if (peers.length === 0) {

629+

return;

630+

}

631+632+

const hostRoot = resolveOpenClawPackageRootSync({

633+

argv1: process.argv[1],

634+

moduleUrl: import.meta.url,

635+

cwd: process.cwd(),

636+

});

637+

if (!hostRoot) {

638+

params.logger.warn?.(

639+

"Could not locate openclaw package root to symlink peerDependencies; plugin may fail to resolve openclaw at runtime.",

640+

);

641+

return;

642+

}

643+644+

const nodeModulesDir = path.join(params.installedDir, "node_modules");

645+

await fs.mkdir(nodeModulesDir, { recursive: true });

646+647+

for (const peerName of peers) {

648+

const linkPath = path.join(nodeModulesDir, peerName);

649+

// Resolve the actual source for scoped packages (e.g. @scope/name).

650+

const linkTarget = path.join(hostRoot, "node_modules", peerName);

651+

// Check whether the package exists at the expected location inside the

652+

// host root's node_modules. If it does not (e.g. openclaw IS the root

653+

// package), fall back to the host root itself.

654+

let resolvedTarget: string;

655+

try {

656+

await fs.access(path.join(linkTarget, "package.json"));

657+

resolvedTarget = linkTarget;

658+

} catch {

659+

resolvedTarget = hostRoot;

660+

}

661+662+

try {

663+

// Remove any existing entry (broken link or stale directory) before

664+

// creating the new symlink so re-installs are idempotent.

665+

await fs.rm(linkPath, { recursive: true, force: true });

666+

await fs.symlink(resolvedTarget, linkPath, "junction");

667+

params.logger.info?.(

668+

`Linked peerDependency "${peerName}" → ${resolvedTarget}`,

669+

);

670+

} catch (err) {

671+

params.logger.warn?.(

672+

`Failed to symlink peerDependency "${peerName}": ${String(err)}`,

673+

);

674+

}

675+

}

676+

}

677+611678

async function installPluginFromPackageDir(

612679

params: {

613680

packageDir: string;

@@ -742,6 +809,7 @@ async function installPluginFromPackageDir(

742809

}

743810744811

const deps = manifest.dependencies ?? {};

812+

const peerDeps = manifest.peerDependencies ?? {};

745813

return await installPluginDirectoryIntoExtensions({

746814

sourceDir: params.packageDir,

747815

pluginId,

@@ -755,7 +823,7 @@ async function installPluginFromPackageDir(

755823

mode: targetResult.target.effectiveMode,

756824

dryRun,

757825

copyErrorPrefix: "failed to copy plugin",

758-

hasDeps: Object.keys(deps).length > 0,

826+

hasDeps: Object.keys(deps).length > 0 || Object.keys(peerDeps).length > 0,

759827

depsLogMessage: "Installing plugin dependencies…",

760828

nameEncoder: encodePluginInstallDirName,

761829

afterCopy: async (installedDir) => {

@@ -770,16 +838,25 @@ async function installPluginFromPackageDir(

770838

}

771839

}

772840

},

773-

afterInstall: async (installedDir) =>

774-

await runInstallSourceScan({

841+

afterInstall: async (installedDir) => {

842+

// Symlink any openclaw peerDependencies into the plugin's node_modules/

843+

// so that plugins declaring openclaw as a peerDependency (rather than a

844+

// regular dependency) can resolve it at runtime.

845+

await linkOpenClawPeerDependencies({

846+

installedDir,

847+

peerDependencies: peerDeps,

848+

logger,

849+

});

850+

return await runInstallSourceScan({

775851

subject: `Plugin "${pluginId}"`,

776852

scan: async () =>

777853

await runtime.scanInstalledPackageDependencyTree({

778854

logger,

779855

packageDir: installedDir,

780856

pluginId,

781857

}),

782-

}),

858+

});

859+

},

783860

});

784861

}

785862