()
| 72 | const SECRET_KEY_REGEX = /(SECRET|PASSWORD|API_KEY|PRIVATE_KEY)/i |
| 73 | |
| 74 | const parseEnvFile = (): { lines: string[]; parsed: ParsedEnvLine[] } => { |
| 75 | const envPath = getEnvFilePath() |
| 76 | |
| 77 | if (!fs.existsSync(envPath)) { |
| 78 | return { |
| 79 | lines: [], |
| 80 | parsed: [], |
| 81 | } |
| 82 | } |
| 83 | |
| 84 | const lines = fs.readFileSync(envPath, 'utf-8').split(/\r?\n/) |
| 85 | const parsed: ParsedEnvLine[] = [] |
| 86 | |
| 87 | for (let index = 0; index < lines.length; index += 1) { |
| 88 | const line = lines[index] |
| 89 | if (!line || line.trim().startsWith('#')) { |
| 90 | continue |
| 91 | } |
| 92 | |
| 93 | const match = line.match(ENV_LINE_REGEX) |
| 94 | if (!match) { |
| 95 | continue |
| 96 | } |
| 97 | |
| 98 | parsed.push({ |
| 99 | index, |
| 100 | key: match[1], |
| 101 | value: match[2], |
| 102 | }) |
| 103 | } |
| 104 | |
| 105 | return { |
| 106 | lines, |
| 107 | parsed, |
| 108 | } |
| 109 | } |
| 110 | |
| 111 | export const isSupportedEnvKey = (key: string): boolean => { |
| 112 | return SUPPORTED_ENV_KEYS.has(key) || RR_KEY_REGEX.test(key) |
no test coverage detected