|
1 | 1 | import { spawn, type ChildProcess } from "node:child_process"; |
2 | 2 | import { execSync } from "node:child_process"; |
3 | | -import { rmSync, existsSync, mkdirSync } from "node:fs"; |
| 3 | +import { rmSync, existsSync, mkdirSync, symlinkSync } from "node:fs"; |
4 | 4 | import path from "node:path"; |
5 | 5 | import type { AgentConfig, RunningAgent } from "./types.js"; |
6 | 6 | import { getTerminal, buildShellCommand, type TerminalInfo } from "./terminal.js"; |
@@ -56,6 +56,22 @@ export function createWorktree( |
56 | 56 | return repoDir; |
57 | 57 | } |
58 | 58 |
|
| 59 | + // Symlink node_modules from main repo so tests and builds work in worktree |
| 60 | + try { |
| 61 | + const mainNodeModules = path.join(repoDir, "node_modules"); |
| 62 | + const wtNodeModules = path.join(worktreeDir, "node_modules"); |
| 63 | + if (existsSync(mainNodeModules) && !existsSync(wtNodeModules)) { |
| 64 | + symlinkSync(mainNodeModules, wtNodeModules, "dir"); |
| 65 | + } |
| 66 | + // Also symlink api/node_modules if it exists (monorepo) |
| 67 | + const apiMainNm = path.join(repoDir, "api", "node_modules"); |
| 68 | + const apiWtDir = path.join(worktreeDir, "api"); |
| 69 | + const apiWtNm = path.join(apiWtDir, "node_modules"); |
| 70 | + if (existsSync(apiMainNm) && existsSync(apiWtDir) && !existsSync(apiWtNm)) { |
| 71 | + symlinkSync(apiMainNm, apiWtNm, "dir"); |
| 72 | + } |
| 73 | + } catch { /* non-fatal — tests may fail but agent can still work */ } |
| 74 | + |
59 | 75 | return worktreeDir; |
60 | 76 | } |
61 | 77 |
|
|
0 commit comments