Add getEnv wrapper

This commit is contained in:
rijkvanzanten
2022-11-17 12:20:57 -05:00
parent 1875f1d18d
commit 4ab04f67f3

View File

@@ -291,7 +291,7 @@ const typeMap: Record<string, string> = {
let env: Record<string, any> = {
...defaults,
...process.env,
...getEnv(),
...processConfiguration(),
};
process.env = env;
@@ -300,6 +300,11 @@ env = processValues(env);
export default env;
/**
* Small wrapper function that makes it easier to write unit tests against changing environments
*/
export const getEnv = () => env;
/**
* When changes have been made during runtime, like in the CLI, we can refresh the env object with
* the newly created variables
@@ -308,7 +313,7 @@ export function refreshEnv(): void {
env = {
...defaults,
...process.env,
...getEnv(),
...processConfiguration(),
};
process.env = env;
@@ -316,7 +321,7 @@ export function refreshEnv(): void {
env = processValues(env);
}
function getEnv() {
function processConfiguration() {
const configPath = path.resolve(process.env.CONFIG_PATH || defaults.CONFIG_PATH);
if (fs.existsSync(configPath) === false) return {};