()
| 101 | |
| 102 | /** Load direnv environment into process.env. Safe to call even if direnv is not installed. */ |
| 103 | export function initializeDirenv(): void { |
| 104 | if (!isDirenvAvailable()) { |
| 105 | return |
| 106 | } |
| 107 | |
| 108 | const envrcDir = findEnvrcDirectory(process.cwd()) |
| 109 | if (!envrcDir) { |
| 110 | return |
| 111 | } |
| 112 | |
| 113 | const envVars = getDirenvExport(envrcDir) |
| 114 | if (!envVars) { |
| 115 | return |
| 116 | } |
| 117 | let appliedCount = 0 |
| 118 | for (const [key, value] of Object.entries(envVars)) { |
| 119 | if (value === null) { |
| 120 | delete process.env[key] |
| 121 | } else { |
| 122 | process.env[key] = value |
| 123 | } |
| 124 | appliedCount++ |
| 125 | } |
| 126 | |
| 127 | if (appliedCount > 0) { |
| 128 | logger.debug( |
| 129 | { envrcDir, variableCount: appliedCount }, |
| 130 | 'Loaded environment variables from direnv', |
| 131 | ) |
| 132 | } |
| 133 | } |
no test coverage detected