fix: guard against missing brace in JSONC provider replacement
This commit is contained in:
@@ -55,7 +55,10 @@ export function addProviderConfig(config: InstallConfig): ConfigMergeResult {
|
||||
const providerIdx = content.indexOf('"provider"')
|
||||
if (providerIdx !== -1) {
|
||||
const colonIdx = content.indexOf(":", providerIdx + '"provider"'.length)
|
||||
const braceStart = content.indexOf("{", colonIdx)
|
||||
const braceStart = colonIdx !== -1 ? content.indexOf("{", colonIdx) : -1
|
||||
if (braceStart === -1) {
|
||||
writeFileSync(path, JSON.stringify(newConfig, null, 2) + "\n")
|
||||
} else {
|
||||
let depth = 0
|
||||
let braceEnd = braceStart
|
||||
for (let i = braceStart; i < content.length; i++) {
|
||||
@@ -73,6 +76,7 @@ export function addProviderConfig(config: InstallConfig): ConfigMergeResult {
|
||||
`"provider": ${providerJson}` +
|
||||
content.slice(braceEnd + 1)
|
||||
writeFileSync(path, newContent)
|
||||
}
|
||||
} else {
|
||||
const newContent = content.replace(/(\{)/, `$1\n "provider": ${providerJson},`)
|
||||
writeFileSync(path, newContent)
|
||||
|
||||
Reference in New Issue
Block a user