Skip to content

Commit f05457d

Browse files
committed
feat(marketplace): yaml migrate for modes, + uninstall UX (remove empty)
1 parent faf9857 commit f05457d

File tree

5 files changed

+35
-28
lines changed

5 files changed

+35
-28
lines changed

pnpm-lock.yaml

Lines changed: 15 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@
367367
"cheerio": "^1.0.0",
368368
"chokidar": "^4.0.1",
369369
"clone-deep": "^4.0.1",
370-
"config-rocket": "^0.5.8",
370+
"config-rocket": "^0.6.1",
371371
"default-shell": "^2.2.0",
372372
"delay": "^6.0.0",
373373
"diff": "^5.2.0",
@@ -396,7 +396,7 @@
396396
"puppeteer-chromium-resolver": "^23.0.0",
397397
"puppeteer-core": "^23.4.0",
398398
"reconnecting-eventsource": "^1.6.4",
399-
"roo-rocket": "^0.4.0",
399+
"roo-rocket": "^0.5.0",
400400
"sanitize-filename": "^1.6.3",
401401
"say": "^0.16.0",
402402
"serialize-error": "^11.0.3",

src/services/marketplace/InstalledMetadataManager.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,10 @@ export class InstalledMetadataManager {
161161
// Serialize metadata to YAML
162162
const yamlContent = yaml.stringify(metadata)
163163

164-
// Write to file
165-
await fs.writeFile(filePath, yamlContent, "utf-8")
164+
// Write to file if there are any entries, otherwise remove file
165+
if (Object.keys(metadata).length) await fs.writeFile(filePath, yamlContent, "utf-8")
166+
else await fs.rm(filePath)
167+
166168
console.debug(`InstalledMetadataManager: Metadata saved successfully to ${filePath}`)
167169
} catch (error) {
168170
console.error(`InstalledMetadataManager: Error saving metadata file ${filePath}:`, error)

src/services/marketplace/MarketplaceManager.ts

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import * as vscode from "vscode"
22
import * as path from "path"
33
import * as fs from "fs/promises"
4+
import * as yaml from "yaml"
45
import { GitFetcher } from "./GitFetcher"
56
import {
67
MarketplaceItem,
@@ -684,17 +685,16 @@ export class MarketplaceManager {
684685
mcps: [],
685686
files: [],
686687
}
687-
customHookable.hook("onFileOutput", ({ filePath, data }) => {
688+
customHookable.hook("onFileOutput", ({ filePath, parsedData }) => {
689+
const pD = parsedData as Record<string, any>
688690
if (filePath.endsWith("/.roomodes")) {
689-
const parsedData = JSON.parse(data)
690-
if (parsedData?.customModes?.length) {
691-
parsedData.customModes.forEach((mode: any) => {
691+
if (pD?.customModes?.length) {
692+
pD.customModes.forEach((mode: any) => {
692693
itemInstalledMetadata.modes?.push(mode.slug)
693694
})
694695
}
695696
} else if (filePath.endsWith("/.roo/mcp.json")) {
696-
const parsedData = JSON.parse(data)
697-
const mcpSlugs = Object.keys(parsedData?.mcpServers ?? {})
697+
const mcpSlugs = Object.keys(pD?.mcpServers ?? {})
698698
if (mcpSlugs.length) {
699699
mcpSlugs.forEach((mcpSlug: any) => {
700700
itemInstalledMetadata.mcps?.push(mcpSlug)
@@ -737,11 +737,13 @@ export class MarketplaceManager {
737737
if (await fs.access(modesFilePath).catch(() => true))
738738
vscode.window.showWarningMessage(`"${item.name}": modes file not found`)
739739
else {
740-
const parsedModesFile = JSON.parse(await fs.readFile(modesFilePath, "utf-8"))
740+
const parsedModesFile = yaml.parse(await fs.readFile(modesFilePath, "utf-8"))
741741
parsedModesFile.customModes = parsedModesFile.customModes.filter(
742742
(m: any) => !itemInstalledMetadata.modes!.includes(m.slug),
743743
)
744-
await fs.writeFile(modesFilePath, JSON.stringify(parsedModesFile, null, 2), "utf-8")
744+
if (parsedModesFile.customModes.length)
745+
await fs.writeFile(modesFilePath, yaml.stringify(parsedModesFile, null, 2), "utf-8") // Remove file if no more modes left
746+
else await fs.rm(modesFilePath)
745747
}
746748
}
747749
if (itemInstalledMetadata.mcps) {
@@ -752,7 +754,9 @@ export class MarketplaceManager {
752754
itemInstalledMetadata.mcps.forEach((mcp) => {
753755
delete parsedMcpsFile.mcpServers[mcp]
754756
})
755-
await fs.writeFile(mcpsFilePath, JSON.stringify(parsedMcpsFile, null, 2), "utf-8")
757+
if (Object.keys(parsedMcpsFile.mcpServers).length)
758+
await fs.writeFile(mcpsFilePath, JSON.stringify(parsedMcpsFile, null, 2), "utf-8") // Remove file if no more modes left
759+
else await fs.rm(mcpsFilePath)
756760
}
757761
}
758762
if (itemInstalledMetadata.files) {

webview-ui/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
"class-variance-authority": "^0.7.1",
3939
"clsx": "^2.1.1",
4040
"cmdk": "^1.0.0",
41-
"config-rocket": "^0.5.8",
41+
"config-rocket": "^0.6.1",
4242
"date-fns": "^4.1.0",
4343
"debounce": "^2.1.1",
4444
"fast-deep-equal": "^3.1.3",

0 commit comments

Comments
 (0)