Skip to content

Commit cb0a58e

Browse files
cteroomote[bot]
andauthored
Support linking to @roo-code/cloud in Roo-Code repo (RooCodeInc#6799)
Co-authored-by: roomote[bot] <219738659+roomote[bot]@users.noreply.github.com>
1 parent 37330b0 commit cb0a58e

File tree

4 files changed

+153
-13
lines changed

4 files changed

+153
-13
lines changed

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@
2323
"changeset:version": "cp CHANGELOG.md src/CHANGELOG.md && changeset version && cp -vf src/CHANGELOG.md .",
2424
"knip": "knip --include files",
2525
"update-contributors": "node scripts/update-contributors.js",
26-
"evals": "dotenvx run -f packages/evals/.env.development packages/evals/.env.local -- docker compose -f packages/evals/docker-compose.yml --profile server --profile runner up --build --scale runner=0"
26+
"evals": "dotenvx run -f packages/evals/.env.development packages/evals/.env.local -- docker compose -f packages/evals/docker-compose.yml --profile server --profile runner up --build --scale runner=0",
27+
"link-workspace-packages": "node scripts/link-packages.js",
28+
"unlink-workspace-packages": "node scripts/link-packages.js --unlink"
2729
},
2830
"devDependencies": {
2931
"@changesets/cli": "^2.27.10",

scripts/link-packages.js

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
#!/usr/bin/env node
2+
3+
const { spawn, execSync } = require("child_process")
4+
const path = require("path")
5+
const fs = require("fs")
6+
7+
// Package configuration - Add new packages here as needed.
8+
const config = {
9+
packages: [
10+
{
11+
name: "@roo-code/cloud",
12+
sourcePath: "../Roo-Code-Cloud/packages/sdk",
13+
targetPath: "src/node_modules/@roo-code/cloud",
14+
npmPath: "npm",
15+
watchCommand: "pnpm build:development:watch",
16+
},
17+
],
18+
}
19+
20+
const args = process.argv.slice(2)
21+
const packageName = args.find((arg) => !arg.startsWith("--"))
22+
const watch = !args.includes("--no-watch")
23+
const unlink = args.includes("--unlink")
24+
25+
const packages = packageName ? config.packages.filter((p) => p.name === packageName) : config.packages
26+
27+
if (!packages.length) {
28+
console.error(`Package '${packageName}' not found`)
29+
process.exit(1)
30+
}
31+
32+
packages.forEach(unlink ? unlinkPackage : linkPackage)
33+
34+
// After unlinking, restore npm packages with a single pnpm install.
35+
if (unlink && packages.length > 0) {
36+
const srcPath = path.resolve(__dirname, "..", "src")
37+
console.log("\nRestoring npm packages...")
38+
39+
try {
40+
execSync("pnpm install", { cwd: srcPath, stdio: "inherit" })
41+
console.log("Successfully restored npm packages")
42+
} catch (error) {
43+
console.error(`Failed to restore packages: ${error.message}`)
44+
console.log("You may need to run 'pnpm install' manually in the src directory")
45+
}
46+
}
47+
48+
if (!unlink && watch) {
49+
const watchers = packages.filter((pkg) => pkg.watchCommand).map(startWatch)
50+
51+
if (watchers.length) {
52+
process.on("SIGINT", () => {
53+
console.log("\nStopping...")
54+
watchers.forEach((w) => w.kill())
55+
process.exit(0)
56+
})
57+
console.log("\nWatching for changes. Press Ctrl+C to stop.\n")
58+
}
59+
}
60+
61+
function linkPackage(pkg) {
62+
const sourcePath = path.resolve(__dirname, "..", pkg.sourcePath)
63+
const targetPath = path.resolve(__dirname, "..", pkg.targetPath)
64+
65+
if (!fs.existsSync(sourcePath)) {
66+
console.error(`Source not found: ${sourcePath}`)
67+
process.exit(1)
68+
}
69+
70+
// Install dependencies if needed.
71+
if (!fs.existsSync(path.join(sourcePath, "node_modules"))) {
72+
console.log(`Installing dependencies for ${pkg.name}...`)
73+
74+
try {
75+
execSync("pnpm install", { cwd: sourcePath, stdio: "inherit" })
76+
} catch (e) {
77+
execSync("pnpm install --no-frozen-lockfile", { cwd: sourcePath, stdio: "inherit" })
78+
}
79+
}
80+
81+
// Create symlink.
82+
fs.rmSync(targetPath, { recursive: true, force: true })
83+
fs.mkdirSync(path.dirname(targetPath), { recursive: true })
84+
const linkSource = pkg.npmPath ? path.join(sourcePath, pkg.npmPath) : sourcePath
85+
fs.symlinkSync(linkSource, targetPath, "dir")
86+
console.log(`Linked ${pkg.name}`)
87+
}
88+
89+
function unlinkPackage(pkg) {
90+
const targetPath = path.resolve(__dirname, "..", pkg.targetPath)
91+
if (fs.existsSync(targetPath)) {
92+
fs.rmSync(targetPath, { recursive: true, force: true })
93+
console.log(`Unlinked ${pkg.name}`)
94+
}
95+
}
96+
97+
function startWatch(pkg) {
98+
console.log(`Watching ${pkg.name}...`)
99+
const [cmd, ...args] = pkg.watchCommand.split(" ")
100+
return spawn(cmd, args, {
101+
cwd: path.resolve(__dirname, "..", pkg.sourcePath),
102+
stdio: "inherit",
103+
shell: true,
104+
})
105+
}

src/extension.ts

Lines changed: 37 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -207,28 +207,54 @@ export async function activate(context: vscode.ExtensionContext) {
207207

208208
// Watch the core files and automatically reload the extension host.
209209
if (process.env.NODE_ENV === "development") {
210-
const pattern = "**/*.ts"
211-
212210
const watchPaths = [
213-
{ path: context.extensionPath, name: "extension" },
214-
{ path: path.join(context.extensionPath, "../packages/types"), name: "types" },
215-
{ path: path.join(context.extensionPath, "../packages/telemetry"), name: "telemetry" },
211+
{ path: context.extensionPath, pattern: "**/*.ts" },
212+
{ path: path.join(context.extensionPath, "../packages/types"), pattern: "**/*.ts" },
213+
{ path: path.join(context.extensionPath, "../packages/telemetry"), pattern: "**/*.ts" },
214+
{ path: path.join(context.extensionPath, "node_modules/@roo-code/cloud"), pattern: "**/*" },
216215
]
217216

218217
console.log(
219-
`♻️♻️♻️ Core auto-reloading is ENABLED. Watching for changes in: ${watchPaths.map(({ name }) => name).join(", ")}`,
218+
`♻️♻️♻️ Core auto-reloading: Watching for changes in ${watchPaths.map(({ path }) => path).join(", ")}`,
220219
)
221220

222-
watchPaths.forEach(({ path: watchPath, name }) => {
223-
const watcher = vscode.workspace.createFileSystemWatcher(new vscode.RelativePattern(watchPath, pattern))
221+
// Create a debounced reload function to prevent excessive reloads
222+
let reloadTimeout: NodeJS.Timeout | undefined
223+
const DEBOUNCE_DELAY = 1_000
224+
225+
const debouncedReload = (uri: vscode.Uri) => {
226+
if (reloadTimeout) {
227+
clearTimeout(reloadTimeout)
228+
}
224229

225-
watcher.onDidChange((uri) => {
226-
console.log(`♻️ ${name} file changed: ${uri.fsPath}. Reloading host…`)
230+
console.log(`♻️ ${uri.fsPath} changed; scheduling reload...`)
231+
232+
reloadTimeout = setTimeout(() => {
233+
console.log(`♻️ Reloading host after debounce delay...`)
227234
vscode.commands.executeCommand("workbench.action.reloadWindow")
228-
})
235+
}, DEBOUNCE_DELAY)
236+
}
237+
238+
watchPaths.forEach(({ path: watchPath, pattern }) => {
239+
const relPattern = new vscode.RelativePattern(vscode.Uri.file(watchPath), pattern)
240+
const watcher = vscode.workspace.createFileSystemWatcher(relPattern, false, false, false)
241+
242+
// Listen to all change types to ensure symlinked file updates trigger reloads.
243+
watcher.onDidChange(debouncedReload)
244+
watcher.onDidCreate(debouncedReload)
245+
watcher.onDidDelete(debouncedReload)
229246

230247
context.subscriptions.push(watcher)
231248
})
249+
250+
// Clean up the timeout on deactivation
251+
context.subscriptions.push({
252+
dispose: () => {
253+
if (reloadTimeout) {
254+
clearTimeout(reloadTimeout)
255+
}
256+
},
257+
})
232258
}
233259

234260
return new API(outputChannel, provider, socketPath, enableLogging)

src/tsconfig.json

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,12 @@
2121
"useUnknownInCatchVariables": false
2222
},
2323
"include": ["."],
24-
"exclude": ["node_modules"]
24+
"exclude": ["node_modules"],
25+
"watchOptions": {
26+
"watchFile": "useFsEvents",
27+
"watchDirectory": "useFsEvents",
28+
"fallbackPolling": "dynamicPriority",
29+
"synchronousWatchDirectory": true,
30+
"excludeDirectories": ["**/node_modules", "**/dist", "**/.turbo"]
31+
}
2532
}

0 commit comments

Comments
 (0)