MCPcopy Index your code
hub / github.com/colbymchenry/codegraph / readJsonFile

Function readJsonFile

src/installer/targets/shared.ts:58–73  ·  view source on GitHub ↗
(filePath: string)

Source from the content-addressed store, hash-verified

56 * existing config that happened to break JSON parse temporarily.
57 */
58export function readJsonFile(filePath: string): Record<string, any> {
59 if (!fs.existsSync(filePath)) {
60 return {};
61 }
62 try {
63 return JSON.parse(fs.readFileSync(filePath, 'utf-8'));
64 } catch (err) {
65 const msg = err instanceof Error ? err.message : String(err);
66 console.warn(` Warning: Could not parse ${path.basename(filePath)}: ${msg}`);
67 console.warn(` A backup will be created before overwriting.`);
68 try {
69 fs.copyFileSync(filePath, filePath + '.backup');
70 } catch { /* ignore backup failure */ }
71 return {};
72 }
73}
74
75/**
76 * Write a file atomically: write to `<path>.tmp.<pid>`, then rename.

Callers 15

hasMcpConfigFunction · 0.90
hasPermissionsFunction · 0.90
detectMethod · 0.90
uninstallMethod · 0.90
writeMcpEntryFunction · 0.90
detectMethod · 0.90
uninstallMethod · 0.90
writeMcpEntryFunction · 0.90
cleanupLegacyLocalMcpFunction · 0.90
writePermissionsEntryFunction · 0.90
writePromptHookEntryFunction · 0.90

Calls 1

warnMethod · 0.80

Tested by

no test coverage detected