Skip to content

Commit 82687d1

Browse files
committed
fix(installation): handle missing config for global install
1 parent 5fdde10 commit 82687d1

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

src/cli/install-globally.ts

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,22 @@ async function setIdeSettings (ideInstance: DetectedIDE, remote?: boolean) {
1313
const configFilePath = resolve(ideInstance.settingsDir, ideInstance.settingsFile)
1414
const settingsPath = getSettingsPath(ideInstance.ide)
1515
const serverConfig = getServerConfig(undefined, remote)
16+
17+
let config = {}
1618
if (existsSync(configFilePath)) {
17-
const fileContent = await readFile(configFilePath, { encoding: 'utf8' })
18-
const existingConfig = parse(fileContent)
19-
deepset(existingConfig, settingsPath, serverConfig)
20-
await writeFile(configFilePath, prettyPrint(existingConfig))
21-
return
22-
} else {
23-
const config = {}
24-
deepset(config, settingsPath, serverConfig)
25-
await writeFile(configFilePath, prettyPrint(config))
19+
try {
20+
const fileContent = await readFile(configFilePath, { encoding: 'utf8' })
21+
const parsed = parse(fileContent)
22+
if (parsed && typeof parsed === 'object') {
23+
config = parsed
24+
}
25+
} catch {
26+
console.error('Failed to parse existing config, creating new one')
27+
}
2628
}
29+
30+
deepset(config, settingsPath, serverConfig)
31+
await writeFile(configFilePath, prettyPrint(config))
2732
}
2833

2934
export async function installGlobally (ides: DetectedIDE[], remote?: boolean) {

0 commit comments

Comments
 (0)