UNPKG

poku

Version:

🐷 Poku makes testing easy for Node.js, Bun, Deno, and you at the same time.

30 lines (29 loc) 1.16 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.envFile = void 0; const promises_1 = require("fs/promises"); const node_process_1 = require("process"); const env_js_1 = require("../../services/env.js"); const list_files_js_1 = require("./list-files.js"); const regex = { comment: /^\s*#/, }; /** Reads an environment file and sets the environment variables. */ const envFile = async (filePath = '.env') => { const mapEnv = new Map(); const env = await (0, promises_1.readFile)((0, list_files_js_1.sanitizePath)(filePath), 'utf8'); const lines = env .split('\n') .map((line) => (0, env_js_1.removeComments)(line.trim())) .filter((line) => line.length > 0 && !regex.comment.test(line)); for (const line of lines) { const parsedLine = (0, env_js_1.parseEnvLine)(line); if (parsedLine) { const { arg, value } = parsedLine; mapEnv.set(arg, value ? (0, env_js_1.resolveEnvVariables)(value, node_process_1.env) : value); } } for (const [arg, value] of mapEnv) node_process_1.env[arg] = value; }; exports.envFile = envFile;