fix: always load .env file alongside the environment specific file (#11188)
This commit is contained in:
5
.changeset/shiny-monkeys-sell.md
Normal file
5
.changeset/shiny-monkeys-sell.md
Normal file
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"@medusajs/utils": patch
|
||||
---
|
||||
|
||||
fix: always load .env file alongside the environment specific file
|
||||
@@ -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 {}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user