Skip to content

feat(cli/watch): reload on .env changes with --env-file #29555

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

edilson258
Copy link
Contributor

Closes #29483

This PR enables Deno to watch the env files when using --watch with --env-file flags. Now, changes to environment variables in the .env (or in any other file provided as env file) will trigger a reload, ensuring scripts always use the latest values without needing a manual restart.

@bartlomieju
Copy link
Member

Thanks for the PR @edilson258, any chance you could a test to that exercises this change?

@edilson258
Copy link
Contributor Author

edilson258 commented Jun 2, 2025

Thanks for the PR @edilson258, any chance you could a test to that exercises this change?

Where exactly i should put such test? and Is there any other similar test that i can use as base?

@bartlomieju
Copy link
Member

@edilson258 ooops, I forgot to mention to add it to tests/integration/watcher_tests.rs

@edilson258
Copy link
Contributor Author

There is a problem with this patch, now we recognize changes in env files and reload when they happen but the env values does not get updated.

Does anyone knows how to solve this?

CC: @bartlomieju, @littledivy

@bartlomieju
Copy link
Member

@edilson258 you need to call load_env_variables_from_env_file after the watcher restarts because of change in the env file

@bartlomieju bartlomieju closed this Jun 9, 2025
@bartlomieju bartlomieju reopened this Jun 9, 2025
@edilson258
Copy link
Contributor Author

@edilson258 you need to call load_env_variables_from_env_file after the watcher restarts because of change in the env file

does not work

@edilson258
Copy link
Contributor Author

@edilson258 you need to call load_env_variables_from_env_file after the watcher restarts because of change in the env file

Maybe when using load_env_variables_from_env_file the env values are updated in rust land and those updates never reflect in JavaScript side!
That may be the case if the Deno.env makes some sort of caching.

@edilson258 edilson258 force-pushed the feat/watch-env-file branch from a11483c to 2f0974b Compare June 21, 2025 05:42
@edilson258 edilson258 force-pushed the feat/watch-env-file branch from 2f0974b to 69994ed Compare July 10, 2025 15:11
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

Successfully merging this pull request may close these issues.

Reload environment variables with --watch and --env-file
2 participants