Skip to content

Commit a5bece8

Browse files
committed
wip 2
1 parent fbd24ac commit a5bece8

File tree

1 file changed

+35
-25
lines changed

1 file changed

+35
-25
lines changed

src/feature-toggles.js

Lines changed: 35 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ class FeatureToggles {
282282
/**
283283
* Populate this.__config.
284284
*/
285-
_processConfig([configRuntime, configFromFile, configAuto], configFilepath) {
285+
_processConfig({ configRuntime, configFromFilesMap, configAuto } = {}) {
286286
const configRuntimeCount = this._processConfigSource(CONFIG_SOURCE.RUNTIME, configRuntime, configFilepath);
287287
const configFromFileCount = this._processConfigSource(CONFIG_SOURCE.FILE, configFromFile, configFilepath);
288288
const configAutoCount = this._processConfigSource(CONFIG_SOURCE.AUTO, configAuto, configFilepath);
@@ -739,6 +739,20 @@ class FeatureToggles {
739739
);
740740
}
741741

742+
static _consolidatedConfigFilepaths(configFilepath, configFilepaths) {
743+
const result = [];
744+
if (configFilepath) {
745+
result.push(configFilepath);
746+
}
747+
if (configFilepaths) {
748+
result.concat(Object.values(configFilepaths));
749+
}
750+
if (result.length === 0) {
751+
result.push(DEFAULT_CONFIG_FILEPATH);
752+
}
753+
return result;
754+
}
755+
742756
/**
743757
* Implementation for {@link initializeFeatures}.
744758
*
@@ -754,42 +768,38 @@ class FeatureToggles {
754768
return;
755769
}
756770

757-
let configFromFile;
758-
try {
759-
if (configFilepaths && (await tryPathReadable(DEFAULT_CONFIG_FILEPATH))) {
760-
configFilepath = DEFAULT_CONFIG_FILEPATH;
761-
}
762-
if (!configFilepath && (await tryPathReadable(DEFAULT_CONFIG_FILEPATH))) {
763-
configFilepath = DEFAULT_CONFIG_FILEPATH;
764-
}
765-
if (configFilepath) {
766-
configFromFile = await FeatureToggles.readConfigFromFile(configFilepath);
767-
}
768-
} catch (err) {
769-
throw new VError(
770-
{
771-
name: VERROR_CLUSTER_NAME,
772-
cause: err,
773-
info: {
774-
configFilepath,
771+
const consolidatedConfigFilepaths = FeatureToggles._consolidatedConfigFilepaths(configFilepath, configFilepaths);
772+
const configFromFilesMap = {};
773+
for (const configFilepath of consolidatedConfigFilepaths) {
774+
try {
775+
if (await tryPathReadable(configFilepath)) {
776+
configFromFilesMap[configFilepath] = await FeatureToggles.readConfigFromFile(configFilepath);
777+
}
778+
} catch (err) {
779+
throw new VError(
780+
{
781+
name: VERROR_CLUSTER_NAME,
782+
cause: err,
783+
info: {
784+
configFilepath,
785+
},
775786
},
776-
},
777-
"initialization aborted, could not read config file"
778-
);
787+
"initialization aborted, could not read config file"
788+
);
789+
}
779790
}
780791

781792
let toggleCounts;
782793
try {
783-
toggleCounts = this._processConfig([configRuntime, configFromFile, configAuto], configFilepath);
794+
toggleCounts = this._processConfig({ configRuntime, configFromFilesMap, configAuto, configFilepath });
784795
} catch (err) {
785796
throw new VError(
786797
{
787798
name: VERROR_CLUSTER_NAME,
788799
cause: err,
789800
info: {
790-
configFilepath,
791801
...(configRuntime && { configRuntime: JSON.stringify(configRuntime) }),
792-
...(configFromFile && { configFromFile: JSON.stringify(configFromFile) }),
802+
...(configFromFilesMap && { configFromFilesMap: JSON.stringify(configFromFilesMap) }),
793803
...(configAuto && { configAuto: JSON.stringify(configAuto) }),
794804
},
795805
},

0 commit comments

Comments
 (0)