-
-
Notifications
You must be signed in to change notification settings - Fork 53
add loading from base env file #121
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
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR implements support for loading variables from a base environment file in addition to the main environment file. This allows sharing common variables across different environments and provides a fallback mechanism where the main environment file can override values from the base file.
- Adds
baseEnvFileNameparameter to theload()method for specifying an optional base environment file - Refactors file loading logic into a reusable
_loadLinesFromFile()helper method - Implements variable precedence where base environment variables are loaded first, then overridden by main environment file variables
Reviewed Changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| lib/src/dotenv.dart | Core implementation of base environment file loading with proper precedence handling |
| example/pubspec.yaml | Adds the new base environment file asset to the example app |
| example/lib/main.dart | Updates example to demonstrate base environment file usage |
| example/assets/.env | Adds override example for base environment variable |
| example/assets/.base.env | Creates sample base environment file with shared variables |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| final linesFromMergeWith = mergeWith.entries | ||
| .map((entry) => "${entry.key}=${entry.value}") | ||
| .toList(); | ||
| final allLines = linesFromMergeWith..addAll(linesFromFile); |
Copilot
AI
Aug 20, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The precedence order is incorrect. Base environment variables should be added first, but linesFromMergeWith and linesFromFile are combined before base environment variables are processed. This means mergeWith and main file variables won't properly override base environment variables.
| final allLines = linesFromMergeWith..addAll(linesFromFile); | |
| final allLines = linesFromFile..addAll(linesFromMergeWith); |
| final allLines = linesFromMergeWith..addAll(linesFromFile); | ||
| final envEntries = parser.parse(allLines); | ||
|
|
||
| _envMap.addAll(baseEnvEntries); |
Copilot
AI
Aug 20, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The order of adding entries to _envMap is incorrect according to the documented priority. Base environment variables are added after main environment variables, but they should be added first so that main environment variables can override them.
#120
This will serve some purposes:
Priority will be as follows: