Merge lists in configs instead of overwritting them
This commit is contained in:
+21
-4
@@ -53,11 +53,9 @@ export async function readConfig(): Promise<ConfigurationOptions> {
|
|||||||
const configFile = getOptionalInput('config-file')
|
const configFile = getOptionalInput('config-file')
|
||||||
if (configFile !== undefined) {
|
if (configFile !== undefined) {
|
||||||
const externalConfig = await readConfigFile(configFile)
|
const externalConfig = await readConfigFile(configFile)
|
||||||
// the reasoning behind reading the inline config when an external
|
console.log('externalConfig====', externalConfig)
|
||||||
// config file is provided is that we still want to allow users to
|
|
||||||
// pass inline options in the presence of an external config file.
|
|
||||||
// TO DO check order of precedence
|
// TO DO check order of precedence
|
||||||
return {...inlineConfig, ...externalConfig}
|
return mergeConfigs(inlineConfig, externalConfig)
|
||||||
}
|
}
|
||||||
return inlineConfig
|
return inlineConfig
|
||||||
}
|
}
|
||||||
@@ -182,3 +180,22 @@ async function getRemoteConfig(configOpts: {
|
|||||||
throw new Error('Error fetching remote config file')
|
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
|
||||||
|
},
|
||||||
|
{}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user