(path: string)
| 199 | } |
| 200 | |
| 201 | function readJsonObject(path: string): JsonObject { |
| 202 | if (!existsSync(path)) { |
| 203 | return {}; |
| 204 | } |
| 205 | |
| 206 | const raw = readFileSync(path, "utf-8").trim(); |
| 207 | if (raw === "") { |
| 208 | return {}; |
| 209 | } |
| 210 | |
| 211 | try { |
| 212 | const parsed = JSON.parse(raw) as unknown; |
| 213 | if (!isJsonObject(parsed)) { |
| 214 | throw new Error("root value is not a JSON object"); |
| 215 | } |
| 216 | return parsed; |
| 217 | } catch (err) { |
| 218 | throw new Error(`Invalid JSON in ${path}: ${toErrorMessage(err)}`); |
| 219 | } |
| 220 | } |
| 221 | |
| 222 | function isJsonObject(value: unknown): value is JsonObject { |
| 223 | return typeof value === "object" && value !== null && !Array.isArray(value); |
no test coverage detected