1+ import { parseJSON , stringifyJSON } from "confbox" ;
12import { read , update , write } from "./fs" ;
23
34// biome-ignore lint: lint/suspicious/noConfusingVoidType
@@ -10,7 +11,7 @@ type JSON = any;
1011 */
1112export async function readJSON ( path : string ) : Promise < JSON | undefined > {
1213 const contents = await read ( path ) ;
13- return contents ? JSON . parse ( contents ) : undefined ;
14+ return contents ? parseJSON ( contents ) : undefined ;
1415}
1516
1617/**
@@ -23,7 +24,7 @@ export async function writeJSON(
2324 json : Record < string , unknown > ,
2425 opts ?: Parameters < typeof write > [ 2 ] ,
2526) : Promise < void > {
26- await write ( path , JSON . stringify ( json , undefined , 2 ) , opts ) ;
27+ await write ( path , stringifyJSON ( json ) , opts ) ;
2728}
2829
2930/**
@@ -38,9 +39,9 @@ export async function updateJSON<T extends JSON>(
3839) : Promise < T | undefined > {
3940 let updated : T | undefined ;
4041 await update ( path , async ( existing ) => {
41- const json = JSON . parse ( existing || "{}" ) ;
42+ const json = parseJSON < T > ( existing || `{\n \n}\n` ) ;
4243 updated = ( await updater ( json ) ) || json ;
43- return JSON . stringify ( updated , undefined , 2 ) ;
44+ return stringifyJSON ( updated ) ;
4445 } ) ;
4546 return updated ;
4647}
0 commit comments