| 85 | process.exit(1); |
| 86 | |
| 87 | function loadOptionalEnvFile(filePath) { |
| 88 | if (!filePath) { |
| 89 | return; |
| 90 | } |
| 91 | const resolvedPath = path.resolve(String(filePath)); |
| 92 | if (!fs.existsSync(resolvedPath)) { |
| 93 | throw new Error(`CODEXBRIDGE_TEST_ENV_FILE does not exist: ${resolvedPath}`); |
| 94 | } |
| 95 | const content = fs.readFileSync(resolvedPath, 'utf8'); |
| 96 | for (const rawLine of content.split(/\r?\n/u)) { |
| 97 | const line = rawLine.trim(); |
| 98 | if (!line || line.startsWith('#')) { |
| 99 | continue; |
| 100 | } |
| 101 | const index = line.indexOf('='); |
| 102 | if (index <= 0) { |
| 103 | continue; |
| 104 | } |
| 105 | const key = line.slice(0, index).trim(); |
| 106 | if (!/^[A-Za-z_][A-Za-z0-9_]*$/u.test(key)) { |
| 107 | continue; |
| 108 | } |
| 109 | let value = line.slice(index + 1).trim(); |
| 110 | if ( |
| 111 | (value.startsWith('"') && value.endsWith('"')) |
| 112 | || (value.startsWith("'") && value.endsWith("'")) |
| 113 | ) { |
| 114 | value = value.slice(1, -1); |
| 115 | } |
| 116 | process.env[key] = value; |
| 117 | } |
| 118 | } |