import * as fs from 'fs' ; export function readFileIfExists ( filename ) { try { return fs . readFileSync ( filename , { encoding : 'utf8' } ) ?? null ; } catch ( err ) { if ( err . code === 'ENOENT' ) { return null ; } else { throw err ; } } } export function atomicWriteFileSync ( filename , filebody ) { const tempFilename = `${ filename }.${ Date . now ( ) }` ; fs . writeFileSync ( tempFilename , filebody , { encoding : 'utf8' } ) ; fs . renameSync ( tempFilename , filename ) ; }