You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
/// 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.
0 commit comments