( file: string, config: A, defaultConfig: A, )
| 1188 | } |
| 1189 | |
| 1190 | function saveConfig<A extends object>( |
| 1191 | file: string, |
| 1192 | config: A, |
| 1193 | defaultConfig: A, |
| 1194 | ): void { |
| 1195 | // Ensure the directory exists before writing the config file |
| 1196 | const dir = dirname(file) |
| 1197 | const fs = getFsImplementation() |
| 1198 | // mkdirSync is already recursive in FsOperations implementation |
| 1199 | fs.mkdirSync(dir) |
| 1200 | |
| 1201 | // Filter out any values that match the defaults |
| 1202 | const filteredConfig = pickBy( |
| 1203 | config, |
| 1204 | (value, key) => |
| 1205 | jsonStringify(value) !== jsonStringify(defaultConfig[key as keyof A]), |
| 1206 | ) |
| 1207 | // Write config file with secure permissions - mode only applies to new files |
| 1208 | writeFileSyncAndFlush_DEPRECATED( |
| 1209 | file, |
| 1210 | jsonStringify(filteredConfig, null, 2), |
| 1211 | { |
| 1212 | encoding: 'utf-8', |
| 1213 | mode: 0o600, |
| 1214 | }, |
| 1215 | ) |
| 1216 | if (file === getGlobalNcodeFile()) { |
| 1217 | globalConfigWriteCount++ |
| 1218 | } |
| 1219 | } |
| 1220 | |
| 1221 | /** |
| 1222 | * Returns true if a write was performed; false if the write was skipped |
no test coverage detected