MCPcopy Index your code
hub / github.com/CodebuffAI/codebuff / loadEnvFile

Function loadEnvFile

agents/e2e/base2-free-summary-format.e2e.test.ts:83–108  ·  view source on GitHub ↗
(filePath: string)

Source from the content-addressed store, hash-verified

81}
82
83const loadEnvFile = async (filePath: string) => {
84 try {
85 const content = await fs.promises.readFile(filePath, 'utf-8')
86 for (const rawLine of content.split('\n')) {
87 const line = rawLine.trim()
88 if (!line || line.startsWith('#')) continue
89 const normalized = line.startsWith('export ')
90 ? line.slice('export '.length)
91 : line
92 const equalsIndex = normalized.indexOf('=')
93 if (equalsIndex <= 0) continue
94 const key = normalized.slice(0, equalsIndex).trim()
95 if (!key || process.env[key]) continue
96 let value = normalized.slice(equalsIndex + 1).trim()
97 if (
98 (value.startsWith('"') && value.endsWith('"')) ||
99 (value.startsWith("'") && value.endsWith("'"))
100 ) {
101 value = value.slice(1, -1)
102 }
103 process.env[key] = value
104 }
105 } catch {
106 // ignore missing env files
107 }
108}
109
110/**
111 * Creates a pre-summarized conversation that mimics what the context pruner produces.

Calls 1

readFileMethod · 0.80

Tested by

no test coverage detected