Conversation
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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: