(file: string, alsoEdit: Edit = noEdit)
| 116 | * written through it (#2721). |
| 117 | */ |
| 118 | export function removeCodegraphServer(file: string, alsoEdit: Edit = noEdit): FileResult { |
| 119 | if (!fs.existsSync(file)) return { path: file, action: 'not-found' }; |
| 120 | const before = fs.readFileSync(file, 'utf-8'); |
| 121 | const { config, valid } = parseConfig(before); |
| 122 | if (!valid) return { path: file, action: 'not-found' }; |
| 123 | |
| 124 | let text = before; |
| 125 | const servers: unknown = config.mcpServers; |
| 126 | if (isObject(servers) && 'codegraph' in servers) { |
| 127 | text = editJson(text, SERVER_PATH, undefined); |
| 128 | if (Object.keys(servers).length === 1) text = editJson(text, ['mcpServers'], undefined); |
| 129 | } |
| 130 | text = alsoEdit(text); |
| 131 | |
| 132 | if (text === before) return { path: file, action: 'not-found' }; |
| 133 | if (/^\s*\{\s*\}\s*$/.test(text)) removeFileUnlessLinked(file, '{}\n'); |
| 134 | else atomicWriteFileSync(file, text); |
| 135 | return { path: file, action: 'removed' }; |
| 136 | } |
no test coverage detected