Merge array config options
This commit is contained in:
+19
-1
@@ -27480,7 +27480,7 @@ function readConfig() {
|
|||||||
if (configFile !== undefined) {
|
if (configFile !== undefined) {
|
||||||
const externalConfig = yield readConfigFile(configFile);
|
const externalConfig = yield readConfigFile(configFile);
|
||||||
// TO DO check order of precedence
|
// 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);
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/***/ }),
|
/***/ }),
|
||||||
|
|||||||
+1
-1
File diff suppressed because one or more lines are too long
+24
-4
@@ -49,10 +49,7 @@ export async function readConfig(): Promise<ConfigurationOptions> {
|
|||||||
if (configFile !== undefined) {
|
if (configFile !== undefined) {
|
||||||
const externalConfig = await readConfigFile(configFile)
|
const externalConfig = await readConfigFile(configFile)
|
||||||
// TO DO check order of precedence
|
// TO DO check order of precedence
|
||||||
return ConfigurationOptionsSchema.parse({
|
return mergeConfigs(externalConfig, inlineConfig)
|
||||||
...externalConfig,
|
|
||||||
...inlineConfig
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return ConfigurationOptionsSchema.parse(inlineConfig)
|
return ConfigurationOptionsSchema.parse(inlineConfig)
|
||||||
@@ -167,3 +164,26 @@ async function getRemoteConfig(configOpts: {
|
|||||||
throw new Error('Error fetching remote config file')
|
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