MCPcopy Create free account
hub / github.com/agent-tower/core / fixSpawnHelperPermissions

Function fixSpawnHelperPermissions

packages/server/scripts/postinstall.js:85–121  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

83 // 1. 优先查找包自身的 node_modules(npm 全局安装场景)
84 const localNodeModules = join(packageRoot, 'node_modules');
85
86 // 2. 尝试查找 monorepo 根目录(pnpm monorepo 场景)
87 const monorepoRoot = findMonorepoRoot(__dirname);
88 const monorepoNodeModules = monorepoRoot ? join(monorepoRoot, 'node_modules') : null;
89
90 // 收集所有需要搜索的 node_modules 目录(去重)
91 const searchDirs = [];
92 if (existsSync(localNodeModules)) {
93 searchDirs.push(localNodeModules);
94 }
95 if (monorepoNodeModules && monorepoNodeModules !== localNodeModules && existsSync(monorepoNodeModules)) {
96 searchDirs.push(monorepoNodeModules);
97 }
98
99 return {
100 packageRoot,
101 monorepoRoot,
102 searchDirs,
103 };
104}
105
106function fixSpawnHelperPermissions() {
107 const { searchDirs } = collectSearchDirs();
108
109 if (searchDirs.length === 0) {
110 console.log('[postinstall] 未找到 node_modules 目录,跳过 spawn-helper 权限修复');
111 return;
112 }
113
114 let fixed = 0;
115 for (const nodeModulesDir of searchDirs) {
116 console.log(`[postinstall] 在 ${nodeModulesDir} 中查找 spawn-helper...`);
117 const spawnHelpers = findFiles(nodeModulesDir, /^spawn-helper$/);
118
119 for (const file of spawnHelpers) {
120 if (!NODE_PTY_PATH_RE.test(file)) continue;
121
122 try {
123 const stats = statSync(file);
124 const isExecutable = (stats.mode & 0o111) !== 0;

Callers 1

postinstall.jsFile · 0.85

Calls 2

collectSearchDirsFunction · 0.85
findFilesFunction · 0.85

Tested by

no test coverage detected