import { readFileSync } from 'node:fs'; /** Loads KEY=value lines from .env into process.env without overriding existing variables. */ export function loadDotEnv(path = '.env'): void { let text: string; try { text = readFileSync(path, 'utf8'); } catch { return; } for (const line of text.split('\n')) { const m = /^\s*([A-Z_][A-Z0-9_]*)\s*=\s*(.*?)\s*$/.exec(line); if (!m || m[1] in process.env) continue; const raw = m[2]; process.env[m[1]] = /^["']/.test(raw) ? raw.replace(/^["']|["']$/g, '') : raw.split(/\s+#/)[0].trim(); } } export function realBucket(): { token: string; bucket: `buckets/${string}` } | null { loadDotEnv(); const token = process.env.HF_TOKEN; const bucket = process.env.HF_BUCKET; if (!token || !bucket?.startsWith('buckets/')) return null; return { token, bucket: bucket as `buckets/${string}` }; }