Skip to content

Consider requiring a statement in justfile to load .env file #469

@casey

Description

@casey

If you're here because of a warning, sorry for the inconvenience!

When just 1.0 is released, it will stop loading .env files by default. Automatically loading .env files seemed like it might lead to unexpected behavior, especially because .env files are often sitting around, and might be present locally but not present in production, or vice-versa.

In order to avoid unexpected breakages, just will issue a warning if a .env file is found, but dotenv-load, the setting that controls .env file loading, is not set. dotenv-load currently defaults to true, but will be changed to default to false.

To silence the warning and continue to load .env files, add the following to your justfile:

set dotenv-load := true

To silence the warning and no longer load .env files, add the following to your justfile:

set dotenv-load := false

You can also suppress the warning by seting the environment variable JUST_SUPPRESS_DOTENV_LOAD_WARNING to 1.

In order to give users plenty of time to update, the change will be made over multiple releases:

  • 2021-03-28 v0.8.7 – Add dotenv-load setting
  • 2021-07-28 v0.x.y – Warn if .env file loaded without dotenv-load being set.
  • 2022-02-01 v1.0.0 – Change dotenv-load default to false.

This is probably a non-issue. But it strikes me that some users might be surprised when just loads their .env file. It might be wise to not load .env files by default, and let users opt-in with a setting, like so:

set load-dotenv := true

Of course, that would be a breaking change, so it's probably not worth it.

Update: I more and more think there's a bit too much magic and potential for unexpected behavior with automatic .env file loading, so I'm more leaning towards doing this.

I'd like to let users control:

  1. Whether or not a dotenv file is loaded at all
  2. The name of the dotenv file
  3. Whether or not to search recursively up to the root for the dotenv file

Eventually, I'd like the default behavior to be to not load a dotenv file, unless the user asks for it with a setting in their justfile, or a command line argument.

In order to avoid disruption, we can have a transitionary period during which Just will emit a warning if it finds a .env file but there was no directive in the Justfile, suggesting that the user add a directive to load the .env file.

I'm eager to hear from people who would be annoyed by this change, i.e who would now have to write a statement to load a .env file.

As for the actual way of controlling these settings, here's an idea. Dotenv loading would be controlled by the following settings, shown with their default settings:

# control whether or not to load a dotenv file at all. defaults to `false`, so no dotenv file is loaded by default
set dotenv-load := false

# controls the file name of the dotenv file. defaults to `.env`
set dotenv-name := ".env"

# controls whether or not to search parent directories recursively, up to the root, defaults to `true`
set dotenv-recursive := true

I'm not sure whether dotenv-recursive should be true or false by default. We should probably do whatever other dotenv implementations do by default.

As an additional convenience, if dotenv-name or dotenv-recursive are set in a justfile, dotenv-load will also be set to to true, if it isn't set explicitly to false.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions