( file: string, config: A, defaultConfig: A, )
| 1134 | } |
| 1135 | |
| 1136 | function saveConfig<A extends object>( |
| 1137 | file: string, |
| 1138 | config: A, |
| 1139 | defaultConfig: A, |
| 1140 | ): void { |
| 1141 | // Ensure the directory exists before writing the config file |
| 1142 | const dir = dirname(file) |
| 1143 | const fs = getFsImplementation() |
| 1144 | // mkdirSync is already recursive in FsOperations implementation |
| 1145 | fs.mkdirSync(dir) |
| 1146 | |
| 1147 | // Filter out any values that match the defaults |
| 1148 | const filteredConfig = pickBy( |
| 1149 | config, |
| 1150 | (value, key) => |
| 1151 | jsonStringify(value) !== jsonStringify(defaultConfig[key as keyof A]), |
| 1152 | ) |
| 1153 | // Write config file with secure permissions - mode only applies to new files |
| 1154 | writeFileSyncAndFlush_DEPRECATED( |
| 1155 | file, |
| 1156 | jsonStringify(filteredConfig, null, 2), |
| 1157 | { |
| 1158 | encoding: 'utf-8', |
| 1159 | mode: 0o600, |
| 1160 | }, |
| 1161 | ) |
| 1162 | if (file === getGlobalClaudeFile()) { |
| 1163 | globalConfigWriteCount++ |
| 1164 | } |
| 1165 | } |
| 1166 | |
| 1167 | /** |
| 1168 | * Returns true if a write was performed; false if the write was skipped |
no test coverage detected