dotenv merges in inverse order?
Hi, when specifying two dotenv files that contain common keys, it seems that priority is given to the first file instead of the last file. This seems counter-intuitive to me and is the opposite of what was found in https://discord.com/channels/974121106208354339/1064231491883782215/1064231491883782215.
first.env:
second.env:
Taskfile.yml:
Running "task test" gives as output
while I would expect
Is it a bug or a feature?
Solution:Jump to solution
IIRC there was some discussion at the time on the priority order. We made a deliberate decision to implement this way.
The idea is to follow the behavior of how
.env
files usually work. They do not override values that are already set on the ENV. In the same way, we loop over the list of .env
files and only set the ENVs that were not previously set....3 Replies
I agree that this seem counterintuitive. The docs don't mention precedence, so I'm not sure if this was intended or not. The introduction of
dotenv
predates my time as a maintainer. Maybe @andreynering knows.
The problem with changing this now is that it would probably break many people's Taskfiles. It's something that we could potentially look into changing for a future major version though if it is decided that this is incorrectSolution
IIRC there was some discussion at the time on the priority order. We made a deliberate decision to implement this way.
The idea is to follow the behavior of how
.env
files usually work. They do not override values that are already set on the ENV. In the same way, we loop over the list of .env
files and only set the ENVs that were not previously set.Ok, thanks for the clarification!