wip: warn users of deprecated keys in app configurations

Signed-off-by: Colton Padden <colton.padden@fastmail.com>
This commit is contained in:
Colton Padden
2022-01-02 11:39:33 -05:00
parent 1fa18f2ab6
commit 1136ed83e3
13 changed files with 210 additions and 14 deletions
+19 -1
View File
@@ -83,9 +83,27 @@ export class ConfigReader implements Config {
// Merge together all configs into a single config with recursive fallback
// readers, giving the first config object in the array the lowest priority.
return configs.reduce<ConfigReader>(
(previousReader, { data, context, filteredKeys }) => {
(previousReader, { data, context, filteredKeys, deprecatedKeys }) => {
const reader = new ConfigReader(data, context, previousReader);
reader.filteredKeys = filteredKeys;
// TODO(cmpadden) introduce `deprecatedKeys` and `notifiedDeprecatedKeys` & use logger
if (deprecatedKeys) {
for (const { key, description } of deprecatedKeys) {
if (description) {
// eslint-disable-next-line no-console
console.warn(
`The configuration key '${key}' is deprecated and may be removed soon. (reason: ${description})`,
);
} else {
// eslint-disable-next-line no-console
console.warn(
`The configuration key '${key}' is deprecated and may be removed soon.`,
);
}
}
}
return reader;
},
undefined!,
+6
View File
@@ -36,6 +36,12 @@ export type AppConfig = {
* This can be used to warn the user if they try to read any of these keys.
*/
filteredKeys?: string[];
/**
* A list of deprecated keys that were found in the configuration when it was loaded.
*
* This can be used to warn the user if they are using deprecated properties.
*/
deprecatedKeys?: { key: string; description: string }[];
};
/**