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

fix(core): expand env variables on load and unload #22585

Closed
wants to merge 1 commit into from

Conversation

matheo
Copy link
Contributor

@matheo matheo commented Mar 29, 2024

Env variables using other variables were not unloaded from the environment and further customizations were impossible in more specific env files.

Current Behavior

The unloading and re-loading of env variables in task-runner/task-env is faulty because composed variables are not unloaded because they are not expanded, just parsed and checked to be equal to the process.env value.

I'm using the @nx-tools/nx-container plugin to build Docker images and I'm passing some input parameters via env var like:

INPUT_BUILD_ARGS="API_HOST=${API_HOST}\nAPI_PORT=${API_PORT}"

Nx loads .env, .local.env and .env.local by default and I have the localhost configuration in one of them.

But when I want to build for production I want to get the values of .env.production and debugging the issue deeply I found that my var was not unloaded because it was comparing the evaluated value in process.env (INPUT_BUILD_ARGS="API_HOST=localhost\nAPI_PORT=3000") with the non-expanded value (INPUT_BUILD_ARGS="API_HOST=${API_HOST}\nAPI_PORT=${API_PORT}") so it was not unloaded.

After this adjustment and the upgrade of dotenv-expand to not affect process.env it works successfully :)

Expected Behavior

To have my composed variables expanded so they are correctly unloaded and overridden by a specific .env* file.

Env variables using other variables were not unloaded from the environment
and further customizations were impossible in more specific env files.
@matheo matheo requested a review from a team as a code owner March 29, 2024 18:49
@matheo matheo requested a review from FrozenPandaz March 29, 2024 18:49
Copy link

vercel bot commented Mar 29, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
nx-dev ✅ Ready (Inspect) Visit Preview Mar 29, 2024 6:55pm

@matheo
Copy link
Contributor Author

matheo commented Apr 6, 2024

@AgentEnder @Coly010 your feedback here will be appreciated 🙏

FrozenPandaz pushed a commit that referenced this pull request Jun 26, 2024
This pr is meant to replace #22585 and
#20524

Env variables using other variables were not unloaded from the
environment and further customizations were impossible in more specific
env files.

<!-- Please make sure you have read the submission guidelines before
posting an PR -->
<!--
https://github.com/nrwl/nx/blob/master/CONTRIBUTING.md#-submitting-a-pr
-->

<!-- Please make sure that your commit message follows our format -->
<!-- Example: `fix(nx): must begin with lowercase` -->

## Current Behavior
<!-- This is the behavior we have today -->

## Expected Behavior
<!-- This is the behavior we should expect with the changes in this PR
-->

## Related Issue(s)
<!-- Please link the issue being fixed so it gets closed when this is
merged. -->

Fixes #23581

Co-authored-by: Mateo Tibaquira <[email protected]>
FrozenPandaz pushed a commit that referenced this pull request Jun 26, 2024
This pr is meant to replace #22585 and
#20524

Env variables using other variables were not unloaded from the
environment and further customizations were impossible in more specific
env files.

<!-- Please make sure you have read the submission guidelines before
posting an PR -->
<!--
https://github.com/nrwl/nx/blob/master/CONTRIBUTING.md#-submitting-a-pr
-->

<!-- Please make sure that your commit message follows our format -->
<!-- Example: `fix(nx): must begin with lowercase` -->

## Current Behavior
<!-- This is the behavior we have today -->

## Expected Behavior
<!-- This is the behavior we should expect with the changes in this PR
-->

## Related Issue(s)
<!-- Please link the issue being fixed so it gets closed when this is
merged. -->

Fixes #23581

Co-authored-by: Mateo Tibaquira <[email protected]>
(cherry picked from commit 88fd03b)
@xiongemi
Copy link
Collaborator

create a pr #26459 to replace this.

@xiongemi xiongemi closed this Jun 27, 2024
@matheo matheo deleted the fix/nx-task-env branch June 28, 2024 01:49
@matheo
Copy link
Contributor Author

matheo commented Jun 28, 2024

Thank you @xiongemi!

Copy link

github-actions bot commented Jul 6, 2024

This pull request has already been merged/closed. If you experience issues related to these changes, please open a new issue referencing this pull request.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 6, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants