-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Expand file tree
/
Copy pathlocalEnvVars.ts
More file actions
25 lines (21 loc) · 663 Bytes
/
localEnvVars.ts
File metadata and controls
25 lines (21 loc) · 663 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import { resolveDotEnvVars } from "./dotEnv.js";
import { sanitizeEnvVars } from "./sanitizeEnvVars.js";
export function resolveLocalEnvVars(
envFile?: string,
additionalVariables?: Record<string, string>
) {
const processEnv = gatherProcessEnv();
const dotEnvVars = resolveDotEnvVars(undefined, envFile);
return {
...sanitizeEnvVars(processEnv),
...sanitizeEnvVars(additionalVariables ?? {}),
...sanitizeEnvVars(dotEnvVars),
};
}
function gatherProcessEnv() {
const $env = {
...process.env,
};
// Filter out undefined values
return Object.fromEntries(Object.entries($env).filter(([key, value]) => value !== undefined));
}