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

推荐订阅源

J
Java Code Geeks
G
Google Developers Blog
Blog — PlanetScale
Blog — PlanetScale
U
Unit 42
A
About on SuperTechFans
Vercel News
Vercel News
B
Blog
Martin Fowler
Martin Fowler
MyScale Blog
MyScale Blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
腾讯CDC
D
Docker
V
Visual Studio Blog
博客园 - 叶小钗
The Cloudflare Blog
Jina AI
Jina AI
B
Blog RSS Feed
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
WordPress大学
WordPress大学
T
Tailwind CSS Blog
MongoDB | Blog
MongoDB | Blog
D
DataBreaches.Net
月光博客
月光博客
大猫的无限游戏
大猫的无限游戏

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
refactor(plugins): split bundled runtime deps staging scr...
steipete · 2026-04-30 · via Recent Commits to openclaw:main

@@ -0,0 +1,209 @@

1+

import fs from "node:fs";

2+

import path from "node:path";

3+

import {

4+

collectInstalledRuntimeDependencyRoots,

5+

dependencyNodeModulesPath,

6+

findContainingRealRoot,

7+

resolveInstalledDirectDependencyNames,

8+

selectRuntimeDependencyRootsToCopy,

9+

} from "./bundled-runtime-deps-package-tree.mjs";

10+

import { pruneStagedRuntimeDependencyCargo } from "./bundled-runtime-deps-prune.mjs";

11+

import {

12+

assertPathIsNotSymlink,

13+

makePluginOwnedTempDir,

14+

removeOwnedTempPathBestEffort,

15+

removePathIfExists,

16+

replaceDirAtomically,

17+

writeJsonAtomically,

18+

} from "./bundled-runtime-deps-stage-state.mjs";

19+20+

function copyMaterializedDependencyTree(params) {

21+

const { activeRoots, allowedRealRoots, sourcePath, targetPath } = params;

22+

const sourceStats = fs.lstatSync(sourcePath);

23+24+

if (sourceStats.isSymbolicLink()) {

25+

let resolvedPath;

26+

try {

27+

resolvedPath = fs.realpathSync(sourcePath);

28+

} catch {

29+

return false;

30+

}

31+

const containingRoot = findContainingRealRoot(resolvedPath, allowedRealRoots);

32+

if (containingRoot === null) {

33+

return false;

34+

}

35+

if (activeRoots.has(containingRoot)) {

36+

return true;

37+

}

38+

const nextActiveRoots = new Set(activeRoots);

39+

nextActiveRoots.add(containingRoot);

40+

return copyMaterializedDependencyTree({

41+

activeRoots: nextActiveRoots,

42+

allowedRealRoots,

43+

sourcePath: resolvedPath,

44+

targetPath,

45+

});

46+

}

47+48+

if (sourceStats.isDirectory()) {

49+

fs.mkdirSync(targetPath, { recursive: true });

50+

for (const entry of fs

51+

.readdirSync(sourcePath, { withFileTypes: true })

52+

.toSorted((left, right) => left.name.localeCompare(right.name))) {

53+

if (

54+

!copyMaterializedDependencyTree({

55+

activeRoots,

56+

allowedRealRoots,

57+

sourcePath: path.join(sourcePath, entry.name),

58+

targetPath: path.join(targetPath, entry.name),

59+

})

60+

) {

61+

return false;

62+

}

63+

}

64+

return true;

65+

}

66+67+

if (sourceStats.isFile()) {

68+

fs.mkdirSync(path.dirname(targetPath), { recursive: true });

69+

fs.copyFileSync(sourcePath, targetPath);

70+

fs.chmodSync(targetPath, sourceStats.mode);

71+

return true;

72+

}

73+74+

return true;

75+

}

76+77+

export function listBundledPluginRuntimeDirs(repoRoot) {

78+

const extensionsRoot = path.join(repoRoot, "dist", "extensions");

79+

if (!fs.existsSync(extensionsRoot)) {

80+

return [];

81+

}

82+83+

return fs

84+

.readdirSync(extensionsRoot, { withFileTypes: true })

85+

.filter((dirent) => dirent.isDirectory())

86+

.map((dirent) => path.join(extensionsRoot, dirent.name))

87+

.filter((pluginDir) => fs.existsSync(path.join(pluginDir, "package.json")));

88+

}

89+90+

export function resolveInstalledWorkspacePluginRoot(repoRoot, pluginId) {

91+

const currentPluginRoot = path.join(repoRoot, "extensions", pluginId);

92+

if (fs.existsSync(path.join(currentPluginRoot, "node_modules"))) {

93+

return currentPluginRoot;

94+

}

95+96+

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

97+

if (!fs.existsSync(nodeModulesDir)) {

98+

return currentPluginRoot;

99+

}

100+101+

let installedWorkspaceRoot;

102+

try {

103+

installedWorkspaceRoot = path.dirname(fs.realpathSync(nodeModulesDir));

104+

} catch {

105+

return currentPluginRoot;

106+

}

107+108+

const installedPluginRoot = path.join(installedWorkspaceRoot, "extensions", pluginId);

109+

if (fs.existsSync(path.join(installedPluginRoot, "package.json"))) {

110+

return installedPluginRoot;

111+

}

112+113+

return currentPluginRoot;

114+

}

115+116+

export function stageInstalledRootRuntimeDeps(params) {

117+

const {

118+

directDependencyPackageRoot = null,

119+

cheapFingerprint,

120+

fingerprint,

121+

packageJson,

122+

pluginDir,

123+

pruneConfig,

124+

repoRoot,

125+

stampPath,

126+

} = params;

127+

const dependencySpecs = {

128+

...packageJson.dependencies,

129+

...packageJson.optionalDependencies,

130+

};

131+

const optionalDependencyNames = new Set(Object.keys(packageJson.optionalDependencies ?? {}));

132+

const rootNodeModulesDir = path.join(repoRoot, "node_modules");

133+

if (Object.keys(dependencySpecs).length === 0 || !fs.existsSync(rootNodeModulesDir)) {

134+

return false;

135+

}

136+137+

const directDependencyNames = resolveInstalledDirectDependencyNames(

138+

rootNodeModulesDir,

139+

dependencySpecs,

140+

directDependencyPackageRoot,

141+

optionalDependencyNames,

142+

);

143+

if (directDependencyNames === null) {

144+

return false;

145+

}

146+

const resolution = collectInstalledRuntimeDependencyRoots(

147+

rootNodeModulesDir,

148+

dependencySpecs,

149+

directDependencyPackageRoot,

150+

optionalDependencyNames,

151+

);

152+

if (resolution === null) {

153+

return false;

154+

}

155+

const rootsToCopy = selectRuntimeDependencyRootsToCopy(resolution);

156+

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

157+

if (rootsToCopy.length === 0) {

158+

assertPathIsNotSymlink(nodeModulesDir, "remove runtime deps");

159+

removePathIfExists(nodeModulesDir);

160+

writeJsonAtomically(stampPath, {

161+

cheapFingerprint,

162+

fingerprint,

163+

generatedAt: new Date().toISOString(),

164+

});

165+

return true;

166+

}

167+

const allowedRealRoots = rootsToCopy.map((record) => record.realRoot);

168+169+

const stagedNodeModulesDir = path.join(

170+

makePluginOwnedTempDir(pluginDir, "stage"),

171+

"node_modules",

172+

);

173+174+

try {

175+

for (const record of rootsToCopy.toSorted((left, right) =>

176+

left.name.localeCompare(right.name),

177+

)) {

178+

const sourcePath = record.realRoot;

179+

const targetPath = dependencyNodeModulesPath(stagedNodeModulesDir, record.name);

180+

if (targetPath === null) {

181+

return false;

182+

}

183+

fs.mkdirSync(path.dirname(targetPath), { recursive: true });

184+

const sourceRootReal = findContainingRealRoot(sourcePath, allowedRealRoots);

185+

if (

186+

sourceRootReal === null ||

187+

!copyMaterializedDependencyTree({

188+

activeRoots: new Set([sourceRootReal]),

189+

allowedRealRoots,

190+

sourcePath,

191+

targetPath,

192+

})

193+

) {

194+

return false;

195+

}

196+

}

197+

pruneStagedRuntimeDependencyCargo(stagedNodeModulesDir, pruneConfig);

198+199+

replaceDirAtomically(nodeModulesDir, stagedNodeModulesDir);

200+

writeJsonAtomically(stampPath, {

201+

cheapFingerprint,

202+

fingerprint,

203+

generatedAt: new Date().toISOString(),

204+

});

205+

return true;

206+

} finally {

207+

removeOwnedTempPathBestEffort(path.dirname(stagedNodeModulesDir));

208+

}

209+

}