| 119 | * consistincy. See issue #125 for details. |
| 120 | */ |
| 121 | export function normalizeEnvObject(input: unknown, absolutePath: string): Environment { |
| 122 | if (typeof input !== 'object' || !input) { |
| 123 | throw new Error(`env-cmd cannot load “${absolutePath}” because it does not export an object.`) |
| 124 | } |
| 125 | |
| 126 | const env: Environment = {}; |
| 127 | for (const [key, value] of Object.entries(input)) { |
| 128 | // we're intentionally stringifying the value here, to |
| 129 | // match what `child_process.spawn` does when loading |
| 130 | // env variables. |
| 131 | // eslint-disable-next-line @typescript-eslint/restrict-template-expressions |
| 132 | env[key] = `${value}` |
| 133 | } |
| 134 | return env |
| 135 | } |