From d1b3ebbb916d32a4af320a101308f400b857984f Mon Sep 17 00:00:00 2001 From: Moises Sacal Date: Fri, 5 Jun 2026 16:18:55 +1000 Subject: [PATCH] fixed merging configurations --- src/configuration.ts | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/configuration.ts b/src/configuration.ts index 40aa5cb..21ee4e9 100644 --- a/src/configuration.ts +++ b/src/configuration.ts @@ -5,21 +5,30 @@ import { log } from './utils.ts'; export { config }; const nodeEnv = process.env.NODE_ENV || 'development'; const configPath = process.env.LDACAPI_CONFIG_PATH || `../${nodeEnv}.config.ts`; -(async function() { +(async () => { try { const actualConfig = await import(configPath); log.info(`Loaded config from ${configPath}`); - merge(config, actualConfig.default); + merge(config as unknown as PlainObject, actualConfig.default as PlainObject); } catch (error) { log.error(error); } })(); -function merge(target: any, source: any) { +type PlainObject = Record; + +function isPlainObject(value: unknown): value is PlainObject { + return typeof value === 'object' && value !== null && Object.is((value as object).constructor, Object); +} + +function merge(target: PlainObject, source: PlainObject) { for (const key in source) { const value = source[key]; - if (typeof value === 'object' && Object.is(value.constructor, Object)) { - merge(target[key], value); + if (isPlainObject(value)) { + if (!isPlainObject(target[key])) { + target[key] = {}; + } + merge(target[key] as PlainObject, value); } else { target[key] = value; }