From 49ed3f2876ef6dd767129292eb3fb132cac7852b Mon Sep 17 00:00:00 2001 From: cnagadya Date: Mon, 7 Nov 2022 12:33:54 +0000 Subject: [PATCH] Merge lists in configs instead of overwritting them --- src/config.ts | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/src/config.ts b/src/config.ts index 2ad037f..01d8a4c 100644 --- a/src/config.ts +++ b/src/config.ts @@ -53,11 +53,9 @@ export async function readConfig(): Promise { const configFile = getOptionalInput('config-file') if (configFile !== undefined) { const externalConfig = await readConfigFile(configFile) - // the reasoning behind reading the inline config when an external - // config file is provided is that we still want to allow users to - // pass inline options in the presence of an external config file. + console.log('externalConfig====', externalConfig) // TO DO check order of precedence - return {...inlineConfig, ...externalConfig} + return mergeConfigs(inlineConfig, externalConfig) } return inlineConfig } @@ -182,3 +180,22 @@ async function getRemoteConfig(configOpts: { throw new Error('Error fetching remote config file') } } + +function mergeConfigs( + ...configs: ConfigurationOptions[] +): ConfigurationOptions { + return configs.reduce( + (mergedConfig: ConfigurationOptions, config: ConfigurationOptions) => { + for (const [key, value] of Object.entries(config)) { + if (Array.isArray(value)) { + const currentValue: string[] = mergedConfig[key] || [] + mergedConfig[key] = [...currentValue, ...value] + } else { + mergedConfig[key] = value + } + } + return mergedConfig + }, + {} + ) +}