{"version":3,"file":"loadEnvFile.mjs","names":[],"sources":["../../src/loadEnvFile.ts"],"sourcesContent":["import { existsSync } from 'node:fs';\nimport dotenv from 'dotenv';\n\nconst DEFAULT_ENV = process.env.NODE_ENV ?? 'development';\n\nexport type LoadEnvFileOptions = {\n  env?: string;\n  envFile?: string;\n};\n\nexport const getEnvFilePath = (\n  env: string = process.env.NODE_ENV ?? 'development',\n  envFile?: string\n): string | undefined => {\n  const envFiles = envFile\n    ? [envFile]\n    : [`.env.${env}.local`, `.env.${env}`, '.env.local', '.env'];\n\n  return envFiles.find(existsSync); // Returns the first existing env file\n};\n\nexport const loadEnvFile = (options?: Partial<LoadEnvFileOptions>) => {\n  const env = options?.env ?? DEFAULT_ENV;\n\n  const envFiles = getEnvFilePath(env, options?.envFile);\n\n  if (!envFiles) {\n    return {};\n  }\n\n  const result = {};\n\n  dotenv.config({\n    path: envFiles,\n    processEnv: result,\n    quiet: true,\n  });\n\n  return result; // Return the parsed env object\n};\n"],"mappings":";;;;AAGA,MAAM;AAON,MAAa,kBACX,qBACA,YACuB;AAKvB,SAJiB,UACb,CAAC,QAAQ,GACT;EAAC,QAAQ,IAAI;EAAS,QAAQ;EAAO;EAAc;EAAO,EAE9C,KAAK,WAAW;;AAGlC,MAAa,eAAe,YAA0C;CAGpE,MAAM,WAAW,eAFL,SAAS,OAAO,aAES,SAAS,QAAQ;AAEtD,KAAI,CAAC,SACH,QAAO,EAAE;CAGX,MAAM,SAAS,EAAE;AAEjB,QAAO,OAAO;EACZ,MAAM;EACN,YAAY;EACZ,OAAO;EACR,CAAC;AAEF,QAAO"}