Skip to content

Commit

Permalink
fix: always load .env file alongside the environment specific file (m…
Browse files Browse the repository at this point in the history
  • Loading branch information
thetutlage authored Jan 29, 2025
1 parent 716de2c commit c982117
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/shiny-monkeys-sell.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@medusajs/utils": patch
---

fix: always load .env file alongside the environment specific file
11 changes: 7 additions & 4 deletions packages/core/utils/src/common/load-env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,17 @@ const KNOWN_ENVIRONMENTS = ["staging", "production", "test"]
* - Loads ".env.production" when "environment=production".
* - Loads ".env.test" when "environment=test".
*
* The ".env" file is always loaded alongside the environment
* specific .env file.
*
* This method does not return any value and updates the "process.env"
* object instead.
*/
export function loadEnv(environment: string, envDir: string) {
const fileToLoad = KNOWN_ENVIRONMENTS.includes(environment)
? `.env.${environment}`
: ".env"
const filesToLoad = KNOWN_ENVIRONMENTS.includes(environment)
? [`.env.${environment}`, ".env"].map((file) => join(envDir, file))
: [join(envDir, ".env")]
try {
expand(dotenv.config({ path: join(envDir, fileToLoad) }))
expand(dotenv.config({ path: filesToLoad }))
} catch {}
}

0 comments on commit c982117

Please sign in to comment.