()
| 111 | } |
| 112 | |
| 113 | function loadCliEnv(): Record<string, string> { |
| 114 | if (cachedEnv) { |
| 115 | return cachedEnv |
| 116 | } |
| 117 | |
| 118 | try { |
| 119 | ensureCliEnvDefaults() |
| 120 | // NOTE: Inline require() is used for lazy loading - the env module depends on |
| 121 | // Infisical secrets which may not be available at module load time in test environments |
| 122 | const { env } = require('../../../packages/internal/src/env') as { |
| 123 | env: Record<string, unknown> |
| 124 | } |
| 125 | |
| 126 | cachedEnv = Object.entries(env).reduce<Record<string, string>>( |
| 127 | (acc, [key, value]) => { |
| 128 | if (value !== undefined && value !== null) { |
| 129 | acc[key] = String(value) |
| 130 | } |
| 131 | return acc |
| 132 | }, |
| 133 | {}, |
| 134 | ) |
| 135 | |
| 136 | return cachedEnv |
| 137 | } catch (error) { |
| 138 | const message = |
| 139 | error instanceof Error |
| 140 | ? error.message |
| 141 | : 'unknown error loading environment' |
| 142 | throw new Error( |
| 143 | `Failed to load CLI environment via packages/internal/src/env: ${message}. ` + |
| 144 | 'Run commands via "infisical run -- bun …" or export the required variables.', |
| 145 | ) |
| 146 | } |
| 147 | } |
| 148 | |
| 149 | export function ensureCliTestEnv(): void { |
| 150 | loadCliEnv() |
no test coverage detected