@@ -12,28 +12,29 @@ function getEnvVar(key: string): string | undefined {
1212interface GetConfigOptions {
1313 warn ?: boolean ;
1414 nullishString ?: boolean ;
15- failOnNotFound ?: boolean ;
16- failInTestEnv ?: boolean ; // this is only to test getConfig and should never be set to override defaults
15+ throwErrorIfNotFound ?: boolean ;
16+ throwErrorInTestEnv ?: boolean ; // this is only to test getConfig and should never be set to override defaults
1717}
1818
1919export const isTestEnvironment = getEnvVar ( 'NODE_ENV' ) === 'test' ;
2020
2121const defaultGetConfigOptions : GetConfigOptions = {
2222 warn : ! isTestEnvironment ,
2323 nullishString : false ,
24- failOnNotFound : false ,
25- failInTestEnv : false
24+ throwErrorIfNotFound : false ,
25+ throwErrorInTestEnv : false
2626} ;
2727
2828/**
2929 * Returns a string config value from environment variables.
30- * Logs a warning or throws an error if the value is missing, if `warn` and `failOnNotFound ` are true in options
30+ * Logs a warning or throws an error if the value is missing, if `warn` and `throwErrorIfNotFound ` are true in options
3131 *
3232 * @param key - The environment variable key to fetch.
3333 * @param options - Optional settings:
34- * - `failOnNotFound `: whether to throw an error if the value is missing (default to `false`).
34+ * - `throwErrorIfNotFound `: whether to throw an error if the value is missing (default to `false`).
3535 * - `warn`: whether to warn if the value is missing (default `true` unless in test env).
3636 * - `nullishString`: if true, returns `''` instead of `undefined` when missing.
37+ * - `throwErrorInTestEnv`: this is to test getConfig and should not be overridden (default to `false`).
3738 * @returns String value of the env var, or `''` or `undefined` if missing.
3839 */
3940export function getConfig (
@@ -45,7 +46,7 @@ export function getConfig(
4546 }
4647
4748 // override default options with param options
48- const { warn, nullishString, failOnNotFound , failInTestEnv } = {
49+ const { warn, nullishString, throwErrorIfNotFound , throwErrorInTestEnv } = {
4950 ...defaultGetConfigOptions ,
5051 ...options
5152 } ;
@@ -59,8 +60,8 @@ export function getConfig(
5960
6061 // error, warn or continue if no value found:
6162 if (
62- ( failOnNotFound && ! isTestEnvironment ) ||
63- ( failOnNotFound && isTestEnvironment && failInTestEnv ) // this is just to enable us to test getConfig's error throwing
63+ ( throwErrorIfNotFound && ! isTestEnvironment ) ||
64+ ( throwErrorIfNotFound && isTestEnvironment && throwErrorInTestEnv ) // this is just to enable us to test getConfig's error throwing
6465 ) {
6566 throw new Error ( notFoundMessage ) ;
6667 }
0 commit comments