Merge array config options
This commit is contained in:
20
dist/index.js
generated
vendored
20
dist/index.js
generated
vendored
@@ -27480,7 +27480,7 @@ function readConfig() {
|
||||
if (configFile !== undefined) {
|
||||
const externalConfig = yield readConfigFile(configFile);
|
||||
// TO DO check order of precedence
|
||||
return schemas_1.ConfigurationOptionsSchema.parse(Object.assign(Object.assign({}, externalConfig), inlineConfig));
|
||||
return mergeConfigs(externalConfig, inlineConfig);
|
||||
}
|
||||
return schemas_1.ConfigurationOptionsSchema.parse(inlineConfig);
|
||||
});
|
||||
@@ -27580,6 +27580,24 @@ function getRemoteConfig(configOpts) {
|
||||
}
|
||||
});
|
||||
}
|
||||
function mergeConfigs(baseConfig, prioConfig) {
|
||||
const mergedConfig = Object.assign({}, baseConfig);
|
||||
for (const key of Object.keys(prioConfig)) {
|
||||
// based on the assumption that ConfigurationOptions values are either arrays or primitive types
|
||||
// former are merged, latter are overwritten
|
||||
if (key in mergedConfig && Array.isArray(mergedConfig[key])) {
|
||||
// casting to unknown[] needed. TS unable to auto infer
|
||||
mergedConfig[key] = [
|
||||
...mergedConfig[key],
|
||||
...prioConfig[key]
|
||||
];
|
||||
}
|
||||
else {
|
||||
mergedConfig[key] = prioConfig[key];
|
||||
}
|
||||
}
|
||||
return schemas_1.ConfigurationOptionsSchema.parse(mergedConfig);
|
||||
}
|
||||
|
||||
|
||||
/***/ }),
|
||||
|
||||
2
dist/index.js.map
generated
vendored
2
dist/index.js.map
generated
vendored
File diff suppressed because one or more lines are too long
@@ -49,10 +49,7 @@ export async function readConfig(): Promise<ConfigurationOptions> {
|
||||
if (configFile !== undefined) {
|
||||
const externalConfig = await readConfigFile(configFile)
|
||||
// TO DO check order of precedence
|
||||
return ConfigurationOptionsSchema.parse({
|
||||
...externalConfig,
|
||||
...inlineConfig
|
||||
})
|
||||
return mergeConfigs(externalConfig, inlineConfig)
|
||||
}
|
||||
|
||||
return ConfigurationOptionsSchema.parse(inlineConfig)
|
||||
@@ -167,3 +164,26 @@ async function getRemoteConfig(configOpts: {
|
||||
throw new Error('Error fetching remote config file')
|
||||
}
|
||||
}
|
||||
|
||||
function mergeConfigs(
|
||||
baseConfig: ConfigurationOptionsPartial,
|
||||
prioConfig: ConfigurationOptionsPartial
|
||||
): ConfigurationOptions {
|
||||
const mergedConfig: {[key: string]: unknown} = {...baseConfig}
|
||||
|
||||
for (const key of Object.keys(prioConfig) as (keyof typeof prioConfig)[]) {
|
||||
// based on the assumption that ConfigurationOptions values are either arrays or primitive types
|
||||
// former are merged, latter are overwritten
|
||||
if (key in mergedConfig && Array.isArray(mergedConfig[key])) {
|
||||
// casting to unknown[] needed. TS unable to auto infer
|
||||
mergedConfig[key] = [
|
||||
...(mergedConfig[key] as unknown[]),
|
||||
...(prioConfig[key] as unknown[])
|
||||
]
|
||||
} else {
|
||||
mergedConfig[key] = prioConfig[key]
|
||||
}
|
||||
}
|
||||
|
||||
return ConfigurationOptionsSchema.parse(mergedConfig)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user