mirror of
https://github.com/aljazceru/opencode.git
synced 2025-12-21 09:44:21 +01:00
fix: {file:...} references weren't being parsed correctly in some cases (#1499)
This commit is contained in:
@@ -373,14 +373,21 @@ export namespace Config {
|
|||||||
return process.env[varName] || ""
|
return process.env[varName] || ""
|
||||||
})
|
})
|
||||||
|
|
||||||
const fileMatches = text.match(/"?\{file:([^}]+)\}"?/g)
|
const fileMatches = text.match(/\{file:[^}]+\}/g)
|
||||||
if (fileMatches) {
|
if (fileMatches) {
|
||||||
const configDir = path.dirname(configPath)
|
const configDir = path.dirname(configPath)
|
||||||
|
const lines = text.split("\n")
|
||||||
|
|
||||||
for (const match of fileMatches) {
|
for (const match of fileMatches) {
|
||||||
const filePath = match.replace(/^"?\{file:/, "").replace(/\}"?$/, "")
|
const lineIndex = lines.findIndex((line) => line.includes(match))
|
||||||
|
if (lineIndex !== -1 && lines[lineIndex].trim().startsWith("//")) {
|
||||||
|
continue // Skip if line is commented
|
||||||
|
}
|
||||||
|
const filePath = match.replace(/^\{file:/, "").replace(/\}$/, "")
|
||||||
const resolvedPath = path.isAbsolute(filePath) ? filePath : path.resolve(configDir, filePath)
|
const resolvedPath = path.isAbsolute(filePath) ? filePath : path.resolve(configDir, filePath)
|
||||||
const fileContent = await Bun.file(resolvedPath).text()
|
const fileContent = (await Bun.file(resolvedPath).text()).trim()
|
||||||
text = text.replace(match, JSON.stringify(fileContent))
|
// escape newlines/quotes, strip outer quotes
|
||||||
|
text = text.replace(match, JSON.stringify(fileContent).slice(1, -1))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user