/** * 极简 .env 加载(不引 dotenv,与根仓库 scripts/verify-live.ts 风格一致)。 * 只解析 KEY=VALUE 行,忽略注释与空行;任何输出都不打印 value。 */ import { readFileSync } from 'node:fs'; export function loadEnvFile(path: URL): void { let raw: string; try { raw = readFileSync(path, 'utf8'); } catch { return; // .env 不存在时静默跳过(允许用真实环境变量注入) } for (const line of raw.split('\n')) { const m = line.match(/^\s*([A-Z0-9_]+)\s*=\s*(.+?)\s*$/); if (m && !m[2].startsWith('#') && process.env[m[1]] === undefined) { process.env[m[1]] = m[2]; } } }