Commit 7b24b53
committed
/// issues where the execution context's working directory is not the
/// project root.
static DotEnv _loadEnv() {
final env = DotEnv(includePlatformEnvironment: true);
try {
// Find the project root by looking for pubspec.yaml, then find .env
var dir = Directory.current;
while (true) {
final pubspecFile = File('${dir.path}/pubspec.yaml');
if (pubspecFile.existsSync()) {
// Found project root, now look for .env in this directory
final envFile = File('${dir.path}/.env');
if (envFile.existsSync()) {
_log.info('Found .env file at: ${envFile.path}');
env.load([envFile.path]);
return env;
}
break; // Found pubspec but no .env, break and fall back
}
// Stop if we have reached the root of the filesystem.
if (dir.parent.path == dir.path) {
break;
}
dir = dir.parent;
}
} catch (e) {
_log.warning('Error during robust .env search: $e. Falling back.');
}
// Fallback for when the robust search fails
_log.warning(
'.env file not found by searching for project root. '
'Falling back to default load().',
);
env.load();
return env;
}
/// Retrieves the database connection URI from the environment.1 parent b07d6d2 commit 7b24b53
1 file changed
+30
-22
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
25 | 25 | | |
26 | 26 | | |
27 | 27 | | |
28 | | - | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
29 | 43 | | |
30 | | - | |
31 | | - | |
32 | | - | |
33 | | - | |
34 | | - | |
35 | | - | |
36 | | - | |
37 | | - | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
38 | 49 | | |
39 | | - | |
40 | | - | |
41 | | - | |
42 | | - | |
43 | | - | |
44 | | - | |
45 | | - | |
46 | | - | |
47 | | - | |
48 | | - | |
49 | | - | |
50 | | - | |
51 | | - | |
| 50 | + | |
| 51 | + | |
52 | 52 | | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
53 | 61 | | |
54 | 62 | | |
55 | 63 | | |
| |||
0 commit comments