fix: always load .env file alongside the environment specific file (#11188)
This commit is contained in:
@@ -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.production" when "environment=production".
|
||||||
* - Loads ".env.test" when "environment=test".
|
* - 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"
|
* This method does not return any value and updates the "process.env"
|
||||||
* object instead.
|
* object instead.
|
||||||
*/
|
*/
|
||||||
export function loadEnv(environment: string, envDir: string) {
|
export function loadEnv(environment: string, envDir: string) {
|
||||||
const fileToLoad = KNOWN_ENVIRONMENTS.includes(environment)
|
const filesToLoad = KNOWN_ENVIRONMENTS.includes(environment)
|
||||||
? `.env.${environment}`
|
? [`.env.${environment}`, ".env"].map((file) => join(envDir, file))
|
||||||
: ".env"
|
: [join(envDir, ".env")]
|
||||||
try {
|
try {
|
||||||
expand(dotenv.config({ path: join(envDir, fileToLoad) }))
|
expand(dotenv.config({ path: filesToLoad }))
|
||||||
} catch {}
|
} catch {}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user