UNPKG

dressed

Version:

A sleek, serverless-ready Discord bot framework.

47 lines 1.83 kB
// MIT License // Copyright (c) 2025 Vercel, Inc. // See the LICENSE file in the project root or https://github.com/vercel/next.js/blob/canary/license.md for full license information. import { readFileSync, statSync } from "node:fs"; import { join } from "node:path"; import { parse } from "dotenv"; const initialEnv = Object.assign({}, process.env); function processEnv(loadedEnvFiles) { if (process.env.__PROCESSED_ENV || loadedEnvFiles.length === 0) { return process.env; } process.env.__PROCESSED_ENV = "true"; const parsed = {}; for (const envFile of loadedEnvFiles) { try { const result = parse(envFile.contents); for (const key of Object.keys(result)) { if (typeof parsed[key] === "undefined" && typeof initialEnv[key] === "undefined") { parsed[key] = result[key]; } } envFile.env = result; } catch (_a) { } } Object.assign(process.env, parsed); } export function loadEnvConfig() { const isTest = process.env.NODE_ENV === "test"; const isDev = process.env.NODE_ENV === "development"; const mode = isTest ? "test" : isDev ? "development" : "production"; const dotenvFiles = [`.env.${mode}.local`, mode !== "test" && `.env.local`, `.env.${mode}`, ".env"].filter(Boolean); const files = []; for (const envFile of dotenvFiles) { const dotEnvPath = join(".", envFile); try { const stats = statSync(dotEnvPath); if (!stats.isFile() && !stats.isFIFO()) continue; const contents = readFileSync(dotEnvPath, "utf8"); files.push({ path: envFile, contents, env: {} }); } catch (_a) { } } processEnv(files); } //# sourceMappingURL=dotenv.js.map