Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A way to avoid calling a command with read dotenv variables #1203

Open
frederikhors opened this issue May 28, 2022 · 7 comments
Open

A way to avoid calling a command with read dotenv variables #1203

frederikhors opened this issue May 28, 2022 · 7 comments

Comments

@frederikhors
Copy link

frederikhors commented May 28, 2022

I think we need a way to avoid to execute a command with loaded environments variables from dotenv file.

Example: I use set dotenv-load in a justfile which will call later a command like npm run build. I need to have envs read in my justfile but not for that command because some of them are being modified a from justfile before it executes that command.

@casey
Copy link
Owner

casey commented May 28, 2022

Check out #953, which would make variable evaluation lazy, i.e. they would only be evaluated when used. Would that fix the problem?

@frederikhors
Copy link
Author

I think these are two different problems. And both are needed. 😄

@casey
Copy link
Owner

casey commented May 29, 2022

Can you provide an example dotenv file, and example justfile? They should be as simple as possible, just to demonstrate the use-case and issue. I want to make sure I understand the use-case.

@frederikhors
Copy link
Author

Let's say I have a .env file like:

THIS_IS_CHANGED_DURING_BUILD="123"

APP_URL="https://a"

and a justfile like:

set dotenv-load

build:
  curl {{APP_URL}}
  command that changes .env file here
  npm run build

The npm run build command is executed with both initial envs but this is not correct because I need it to be executed with the updated (by justfile command) .env.

@casey
Copy link
Owner

casey commented May 31, 2022

Gotcha. My hunch is that this isn't something that can be supported cleanly at the moment. I think the way to go for this is to implement #945, and then have two different .env files, like .just-env for just and .env for npm.

@frederikhors
Copy link
Author

Oh. I do not like it very much.

I think .env file needs to be just one.

Can you think about this syntax instead?

set dotenv-load
  I_NEED_THIS
  AND_THIS_ONE_ONLY

@dionjwa
Copy link

dionjwa commented Jun 2, 2022

Two alternative approaches:

  • turn that recipe into a bash script, that way you can set or read the env var directly and export it into the script context
  • create another recipe structure:
build:
 curl {{APP_URL}}
 command that changes .env file here
 # This will consume the updated .env
 just _build

_build:
 npm run build

This way it's a bit more explicit that you're re-consuming the changed env vars, otherwise there's some indirection in your commands and env vars.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants