From 19a5fb834f3b4b74643540d1b71e40a6e6fd8a05 Mon Sep 17 00:00:00 2001 From: Sainan <63328889+Sainan@users.noreply.github.com> Date: Fri, 4 Apr 2025 17:53:12 +0200 Subject: [PATCH] move object clearing logic to loadConfig function --- src/services/configService.ts | 6 ++++++ src/services/configWatcherService.ts | 7 ------- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/services/configService.ts b/src/services/configService.ts index 22142528..c01fee7e 100644 --- a/src/services/configService.ts +++ b/src/services/configService.ts @@ -64,5 +64,11 @@ export const config: IConfig = { }; export const loadConfig = (): void => { + // Set all values to undefined now so if the new config.json omits some fields that were previously present, it's correct in-memory. + for (const key of Object.keys(config)) { + // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-member-access + (config as any)[key] = undefined; + } + Object.assign(config, JSON.parse(fs.readFileSync(configPath, "utf-8"))); }; diff --git a/src/services/configWatcherService.ts b/src/services/configWatcherService.ts index f32bddf2..e8584785 100644 --- a/src/services/configWatcherService.ts +++ b/src/services/configWatcherService.ts @@ -9,13 +9,6 @@ fs.watchFile(configPath, () => { amnesia = false; } else { logger.info("Detected a change to config.json, reloading its contents."); - - // Set all values to undefined now so if the new config.json omits some fields that were previously present, it's correct in-memory. - for (const key of Object.keys(config)) { - // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-member-access - (config as any)[key] = undefined; - } - try { loadConfig(); } catch (e) {