66
77import { spawn } from 'node:child_process'
88import crypto from 'node:crypto'
9- import { existsSync , promises as fs } from 'node:fs'
9+ import {
10+ existsSync ,
11+ readFileSync ,
12+ writeFileSync ,
13+ promises as fs ,
14+ } from 'node:fs'
1015import os from 'node:os'
1116import path from 'node:path'
1217import { fileURLToPath } from 'node:url'
@@ -188,7 +193,7 @@ class CostTracker {
188193 loadMonthlyStats ( ) {
189194 try {
190195 if ( existsSync ( STORAGE_PATHS . stats ) ) {
191- const data = JSON . parse ( fs . readFileSync ( STORAGE_PATHS . stats , 'utf8' ) )
196+ const data = JSON . parse ( readFileSync ( STORAGE_PATHS . stats , 'utf8' ) )
192197 // YYYY-MM
193198 const currentMonth = new Date ( ) . toISOString ( ) . slice ( 0 , 7 )
194199 if ( data . month === currentMonth ) {
@@ -208,10 +213,7 @@ class CostTracker {
208213
209214 saveMonthlyStats ( ) {
210215 try {
211- fs . writeFileSync (
212- STORAGE_PATHS . stats ,
213- JSON . stringify ( this . monthly , null , 2 ) ,
214- )
216+ writeFileSync ( STORAGE_PATHS . stats , JSON . stringify ( this . monthly , null , 2 ) )
215217 } catch {
216218 // Ignore errors.
217219 }
@@ -296,7 +298,7 @@ class ProgressTracker {
296298 loadHistory ( ) {
297299 try {
298300 if ( existsSync ( STORAGE_PATHS . history ) ) {
299- const data = JSON . parse ( fs . readFileSync ( STORAGE_PATHS . history , 'utf8' ) )
301+ const data = JSON . parse ( readFileSync ( STORAGE_PATHS . history , 'utf8' ) )
300302 // Keep only last 50 sessions.
301303 return data . sessions . slice ( - 50 )
302304 }
@@ -318,7 +320,7 @@ class ProgressTracker {
318320 if ( data . sessions . length > 50 ) {
319321 data . sessions = data . sessions . slice ( - 50 )
320322 }
321- fs . writeFileSync ( STORAGE_PATHS . history , JSON . stringify ( data , null , 2 ) )
323+ writeFileSync ( STORAGE_PATHS . history , JSON . stringify ( data , null , 2 ) )
322324 } catch {
323325 // Ignore errors.
324326 }
0 commit comments