( file: string, config: A, defaultConfig: A, )
| 1114 | } |
| 1115 | |
| 1116 | function saveConfig<A extends object>( |
| 1117 | file: string, |
| 1118 | config: A, |
| 1119 | defaultConfig: A, |
| 1120 | ): void { |
| 1121 | // Ensure the directory exists before writing the config file |
| 1122 | const dir = dirname(file) |
| 1123 | const fs = getFsImplementation() |
| 1124 | // mkdirSync is already recursive in FsOperations implementation |
| 1125 | fs.mkdirSync(dir) |
| 1126 | |
| 1127 | // Filter out any values that match the defaults |
| 1128 | const filteredConfig = pickBy( |
| 1129 | config, |
| 1130 | (value, key) => |
| 1131 | jsonStringify(value) !== jsonStringify(defaultConfig[key as keyof A]), |
| 1132 | ) |
| 1133 | // Write config file with secure permissions - mode only applies to new files |
| 1134 | writeFileSyncAndFlush_DEPRECATED( |
| 1135 | file, |
| 1136 | jsonStringify(filteredConfig, null, 2), |
| 1137 | { |
| 1138 | encoding: 'utf-8', |
| 1139 | mode: 0o600, |
| 1140 | }, |
| 1141 | ) |
| 1142 | if (file === getGlobalClaudeFile()) { |
| 1143 | globalConfigWriteCount++ |
| 1144 | } |
| 1145 | } |
| 1146 | |
| 1147 | /** |
| 1148 | * Returns true if a write was performed; false if the write was skipped |
no test coverage detected