1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | const _ = require("lodash");
|
4 | exports.default = (env, opts = {}) => {
|
5 | const envs = [];
|
6 | return {
|
7 | run() {
|
8 |
|
9 | const normalizedEnv = _.mapValues(env, v => v === null ? undefined : v);
|
10 |
|
11 | envs.push(process.env);
|
12 | if (opts.clear) {
|
13 | process.env = Object.assign({}, normalizedEnv);
|
14 | }
|
15 | else {
|
16 | process.env = Object.assign(Object.assign({}, process.env), normalizedEnv);
|
17 | Object.entries(normalizedEnv)
|
18 | .filter(([, v]) => v === undefined)
|
19 | .forEach(([k]) => {
|
20 | delete process.env[k];
|
21 | });
|
22 | }
|
23 | },
|
24 | finally() {
|
25 | const env = envs.pop();
|
26 | if (env)
|
27 | process.env = env;
|
28 | },
|
29 | };
|
30 | };
|