Fix issue where terminal environment variables are not removed when they are commented out or deleted from .env files. #1131
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #936
The problem this PR fixed is when users comment out or remove a variable from their .env file:
The DEBUG variable remained in terminal environments because:
dotenv.parse()ignores commented lines (seems the right behavior per dotenv spec){ API_KEY: 'secret' }envVarsand it never sawDEBUGdelete()call was never reached for removed/commented variablesSolution is to call
clear()before re-injecting variables, which makes the fix stays at the terminal injection layer rather than modifying the parsing layer, avoiding impacting on other consumers.I also noticed some other issues with setting watcher, currently there's no file watcher watching the settings change, so a reload will be required when toggling the setting. We can consider adding a config listener.