Skip to content

Commit 03bbfce

Browse files
Copilotjava-james
andauthored
chore: addGitHub Copilot instructions (#135)
--------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: java-james <22756998+java-james@users.noreply.github.com>
1 parent e7d1a63 commit 03bbfce

1 file changed

Lines changed: 291 additions & 0 deletions

File tree

.github/copilot-instructions.md

Lines changed: 291 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,291 @@
1+
# flutter_dotenv
2+
3+
flutter_dotenv is a Flutter/Dart package that loads configuration at runtime from a `.env` file which can be used throughout the application. This follows the twelve-factor app methodology for configuration management.
4+
5+
Always reference these instructions first and fallback to search or bash commands only when you encounter unexpected information that does not match the info here.
6+
7+
## Quick Reference
8+
9+
**Essential Commands (run in repository root):**
10+
```bash
11+
flutter pub get # Install dependencies (30-90s, timeout: 120s+)
12+
flutter analyze # Static analysis (10-30s, timeout: 60s+)
13+
flutter test --coverage # Run all tests (30-60s, timeout: 120s+)
14+
dart format lib/ test/ example/lib/ # Format code (5-15s, timeout: 30s+)
15+
```
16+
17+
**Example App Commands (run in example/ directory):**
18+
```bash
19+
cd example/
20+
flutter pub get # Install example deps (30-90s, timeout: 120s+)
21+
flutter run # Launch app (60-180s, timeout: 300s+)
22+
flutter run -d chrome # Launch in web browser
23+
```
24+
25+
**Critical Reminder**: NEVER CANCEL any of these operations. Always set timeouts 2-3x the expected time.
26+
27+
## Working Effectively
28+
29+
### Prerequisites and Environment Setup
30+
- Install Flutter SDK (stable channel recommended):
31+
```bash
32+
# Option 1: Using snap (Linux)
33+
sudo snap install flutter --classic
34+
35+
# Option 2: Manual installation
36+
git clone https://github.com/flutter/flutter.git -b stable
37+
export PATH="$PATH:`pwd`/flutter/bin"
38+
```
39+
- Verify installation: `flutter doctor`
40+
- Ensure Dart SDK is included with Flutter (no separate installation needed)
41+
42+
### Bootstrap, Build, and Test Repository
43+
**CRITICAL TIMING**: All commands below have specific timeout requirements. NEVER CANCEL these operations.
44+
45+
```bash
46+
# Navigate to repository
47+
cd /home/runner/work/flutter_dotenv/flutter_dotenv
48+
49+
# Get dependencies - takes 30-90 seconds. NEVER CANCEL. Set timeout to 120+ seconds.
50+
flutter pub get
51+
52+
# Run static analysis - takes 10-30 seconds. NEVER CANCEL. Set timeout to 60+ seconds.
53+
flutter analyze
54+
55+
# Run tests with coverage - takes 30-60 seconds. NEVER CANCEL. Set timeout to 120+ seconds.
56+
flutter test --coverage
57+
58+
# Format code (if making changes) - takes 5-15 seconds. NEVER CANCEL. Set timeout to 30+ seconds.
59+
dart format lib/ test/ example/lib/
60+
```
61+
62+
### Development Workflow
63+
- **ALWAYS run `flutter pub get` first** after cloning or when dependencies change
64+
- **ALWAYS run `flutter analyze`** before making changes to understand current state
65+
- **ALWAYS run `flutter test`** to verify functionality
66+
- **ALWAYS run `dart format`** before committing (CI will fail otherwise)
67+
68+
### Running the Example Application
69+
- Navigate to example directory: `cd example/`
70+
- Get example dependencies: `flutter pub get` - takes 30-90 seconds. NEVER CANCEL. Set timeout to 120+ seconds.
71+
- Run example app: `flutter run` - takes 60-180 seconds to build and launch. NEVER CANCEL. Set timeout to 300+ seconds.
72+
- For web: `flutter run -d chrome`
73+
- Note: Example demonstrates loading .env files with environment variables
74+
75+
## Validation
76+
77+
### Manual Testing Scenarios
78+
**CRITICAL**: After making ANY changes, ALWAYS run through these validation scenarios:
79+
80+
1. **Basic .env Loading Test**:
81+
```bash
82+
cd example/
83+
flutter run
84+
# Verify the app loads and displays environment variables from assets/.env
85+
# Check that FOO=foo, BAR=bar, and FOOBAR=\$FOOfoobar display correctly
86+
# Verify ESCAPED_DOLLAR_SIGN shows "\$1000" properly
87+
```
88+
89+
2. **Parser Functionality Test**:
90+
```bash
91+
flutter test test/parser_test.dart --verbose
92+
# Verify all parser tests pass:
93+
# - Variable substitution (\$FOO${FOO} patterns)
94+
# - Quote handling (single/double quotes, nested quotes)
95+
# - Comment parsing (# comments are ignored)
96+
# - Equal signs in values (foo=bar=baz handling)
97+
# - Leading export keyword removal
98+
```
99+
100+
3. **DotEnv Integration Test**:
101+
```bash
102+
flutter test test/dotenv_test.dart --verbose
103+
# Verify core functionality:
104+
# - Environment loading with loadFromString()
105+
# - Fallback values work (get() with fallback parameter)
106+
# - Type conversions (getInt, getBool, getDouble)
107+
# - Null safety (maybeGet returns null for missing keys)
108+
```
109+
110+
4. **Empty Environment Test**:
111+
```bash
112+
flutter test test/empty_env_test.dart --verbose
113+
# Verify edge cases when no .env file exists
114+
# Ensures graceful fallback behavior
115+
```
116+
117+
5. **Override and Merging Test**:
118+
```bash
119+
# Check that .env-override functionality works in tests
120+
grep -r "override" test/ example/
121+
# Verify overrideWith and mergeWith parameters work correctly
122+
```
123+
124+
### CI/CD Validation
125+
- **ALWAYS run `flutter analyze`** - CI uses this for static analysis
126+
- **ALWAYS run `flutter test --coverage`** - CI requires test coverage
127+
- **ALWAYS format code with `dart format`** - CI checks formatting
128+
- **Check analysis_options.yaml compliance** - project uses flutter_lints
129+
130+
## Common Tasks
131+
132+
### Repository Structure
133+
```
134+
flutter_dotenv/
135+
├── lib/
136+
│ ├── flutter_dotenv.dart # Main library export
137+
│ └── src/
138+
│ ├── dotenv.dart # Core DotEnv implementation
139+
│ ├── parser.dart # .env file parser
140+
│ └── errors.dart # Error definitions
141+
├── test/
142+
│ ├── dotenv_test.dart # Main functionality tests
143+
│ ├── parser_test.dart # Parser-specific tests
144+
│ ├── empty_env_test.dart # Edge case tests
145+
│ ├── .env # Test environment file
146+
│ └── .env-override # Test override file
147+
├── example/ # Complete Flutter example app
148+
├── tool/ # Development utilities
149+
│ ├── fmt.sh # Code formatting script
150+
│ ├── docs.sh # Documentation generation
151+
│ └── release.sh # Release automation
152+
└── .github/workflows/ # CI/CD automation
153+
└── flutter-tests.yml # Test pipeline
154+
```
155+
156+
### Key Files to Monitor
157+
- **Always check `lib/src/dotenv.dart`** when modifying core functionality
158+
- **Always check `lib/src/parser.dart`** when modifying .env parsing logic
159+
- **Always update tests in `test/`** when adding new features
160+
- **Always check `example/lib/main.dart`** for usage patterns
161+
- **Always check `pubspec.yaml`** when modifying dependencies
162+
163+
### Development Tools
164+
```bash
165+
# Format code (modern command - tool/fmt.sh uses deprecated dartfmt)
166+
dart format lib/ test/ example/lib/
167+
168+
# Generate documentation (modern command - tool/docs.sh uses deprecated dartdoc)
169+
dart doc
170+
# Documentation will be in doc/api/index.html
171+
172+
# Release (tool/release.sh) - requires GH_KEY_ID environment variable
173+
# Only use for official releases
174+
```
175+
176+
### Common Debugging Steps
177+
1. **If `flutter pub get` fails**: Check internet connectivity and pubspec.yaml syntax
178+
2. **If tests fail**: Check test/.env files exist and have correct content
179+
3. **If example app crashes**: Verify assets/.env files are properly declared in example/pubspec.yaml under assets section
180+
4. **If analysis fails**: Check analysis_options.yaml and fix linting errors
181+
5. **If build fails**: Ensure Flutter SDK version matches environment constraints (>=2.12.0-0 <4.0.0)
182+
6. **If .env parsing fails**: Check for proper quotes, escape sequences, and variable substitution syntax
183+
7. **If environment variables are null**: Verify .env file is in assets bundle and loadFromString() or load() was called
184+
8. **If variable substitution doesn't work**: Check test/.env for examples - use \$VAR or \${VAR} syntax
185+
186+
### Performance Expectations
187+
- **Dependency resolution**: 30-90 seconds for `flutter pub get`
188+
- **Static analysis**: 10-30 seconds for `flutter analyze`
189+
- **Test execution**: 30-60 seconds for `flutter test`
190+
- **Example app build**: 60-180 seconds for first `flutter run`
191+
- **Documentation generation**: 30-60 seconds for `dart doc`
192+
193+
**CRITICAL**: NEVER CANCEL these operations. They may appear to hang but are processing. Always set timeouts 2-3x the expected time.
194+
195+
### Critical Warnings and Common Pitfalls
196+
197+
**DO NOT**:
198+
- Cancel `flutter pub get`, `flutter test`, or `flutter run` commands - they take significant time
199+
- Use deprecated `dartfmt` command (use `dart format` instead)
200+
- Use deprecated `dartdoc` command (use `dart doc` instead)
201+
- Forget to declare .env files in pubspec.yaml assets section
202+
- Put .env files in version control if they contain secrets (check .gitignore)
203+
- Skip the `await dotenv.load()` call in main() - variables will be empty
204+
205+
**ALWAYS DO**:
206+
- Set timeouts 2-3x longer than expected completion time
207+
- Run `flutter pub get` after any pubspec.yaml changes
208+
- Check that .env files exist in the correct paths (assets/ for example, test/ for tests)
209+
- Validate .env syntax - no spaces around = signs, proper quotes for special characters
210+
- Test both with and without .env files (use empty_env_test.dart as reference)
211+
212+
### Package Usage Patterns
213+
```dart
214+
// Basic usage pattern
215+
import 'package:flutter_dotenv/flutter_dotenv.dart';
216+
217+
// In main.dart - basic loading
218+
await dotenv.load(fileName: "assets/.env");
219+
220+
// Advanced loading with merging and overrides
221+
await dotenv.load(
222+
fileName: "assets/.env",
223+
mergeWith: {
224+
'TEST_VAR': '5',
225+
'DEFAULT_SETTING': 'value',
226+
},
227+
overrideWithFiles: ["assets/.env.override"],
228+
);
229+
230+
// Access variables
231+
String apiKey = dotenv.env['API_KEY'] ?? 'default_key';
232+
String dbUrl = dotenv.get('DATABASE_URL', fallback: 'localhost');
233+
234+
// Null-safe access
235+
String? optionalValue = dotenv.maybeGet('OPTIONAL_KEY');
236+
String valueWithFallback = dotenv.maybeGet('OPTIONAL_KEY', fallback: 'default') ?? 'fallback';
237+
238+
// Type conversions
239+
int port = dotenv.getInt('PORT', fallback: 8080);
240+
bool debug = dotenv.getBool('DEBUG', fallback: false);
241+
double timeout = dotenv.getDouble('TIMEOUT', fallback: 30.0);
242+
243+
// For testing - load from string
244+
dotenv.loadFromString(envString: File('test/.env').readAsStringSync());
245+
```
246+
247+
### Testing Patterns
248+
- **Always test with and without .env files** (see empty_env_test.dart)
249+
- **Always test variable substitution** (FOO=$BAR patterns)
250+
- **Always test override scenarios** (mergeWith and overrideWith parameters)
251+
- **Always test type conversions** (getInt, getBool, getDouble)
252+
- **Always test fallback values** for missing variables
253+
254+
## Emergency Recovery
255+
256+
**If Flutter/Dart installation is corrupted:**
257+
```bash
258+
# Reinstall Flutter (Linux)
259+
sudo snap install flutter --classic
260+
# OR manual install
261+
git clone https://github.com/flutter/flutter.git -b stable
262+
export PATH="$PATH:/path/to/flutter/bin"
263+
flutter doctor
264+
```
265+
266+
**If dependencies are corrupted:**
267+
```bash
268+
flutter clean
269+
flutter pub get
270+
cd example/ && flutter clean && flutter pub get
271+
```
272+
273+
**If tests are failing unexpectedly:**
274+
```bash
275+
# Check that test files exist
276+
ls -la test/.env test/.env-override
277+
# Verify test file content matches expected format
278+
head test/.env
279+
# Run individual test files
280+
flutter test test/dotenv_test.dart --verbose
281+
```
282+
283+
**If example app won't run:**
284+
```bash
285+
# Check assets are properly declared
286+
grep -A5 "assets:" example/pubspec.yaml
287+
# Verify .env files exist
288+
ls -la example/assets/
289+
# Clean and rebuild
290+
cd example/ && flutter clean && flutter pub get && flutter run
291+
```

0 commit comments

Comments
 (0)