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'
13- import { parseArgs } from '@socketsecurity/lib/argv/parse'
18+
1419import { deleteAsync as del } from 'del'
1520import colors from 'yoctocolors-cjs'
1621
22+ import { parseArgs } from '@socketsecurity/lib/argv/parse'
23+
1724const __dirname = path . dirname ( fileURLToPath ( import . meta. url ) )
1825const rootPath = path . join ( __dirname , '..' )
1926const parentPath = path . join ( rootPath , '..' )
@@ -186,7 +193,7 @@ class CostTracker {
186193 loadMonthlyStats ( ) {
187194 try {
188195 if ( existsSync ( STORAGE_PATHS . stats ) ) {
189- const data = JSON . parse ( fs . readFileSync ( STORAGE_PATHS . stats , 'utf8' ) )
196+ const data = JSON . parse ( readFileSync ( STORAGE_PATHS . stats , 'utf8' ) )
190197 // YYYY-MM
191198 const currentMonth = new Date ( ) . toISOString ( ) . slice ( 0 , 7 )
192199 if ( data . month === currentMonth ) {
@@ -206,10 +213,7 @@ class CostTracker {
206213
207214 saveMonthlyStats ( ) {
208215 try {
209- fs . writeFileSync (
210- STORAGE_PATHS . stats ,
211- JSON . stringify ( this . monthly , null , 2 ) ,
212- )
216+ writeFileSync ( STORAGE_PATHS . stats , JSON . stringify ( this . monthly , null , 2 ) )
213217 } catch {
214218 // Ignore errors.
215219 }
@@ -294,7 +298,7 @@ class ProgressTracker {
294298 loadHistory ( ) {
295299 try {
296300 if ( existsSync ( STORAGE_PATHS . history ) ) {
297- const data = JSON . parse ( fs . readFileSync ( STORAGE_PATHS . history , 'utf8' ) )
301+ const data = JSON . parse ( readFileSync ( STORAGE_PATHS . history , 'utf8' ) )
298302 // Keep only last 50 sessions.
299303 return data . sessions . slice ( - 50 )
300304 }
@@ -316,7 +320,7 @@ class ProgressTracker {
316320 if ( data . sessions . length > 50 ) {
317321 data . sessions = data . sessions . slice ( - 50 )
318322 }
319- fs . writeFileSync ( STORAGE_PATHS . history , JSON . stringify ( data , null , 2 ) )
323+ writeFileSync ( STORAGE_PATHS . history , JSON . stringify ( data , null , 2 ) )
320324 } catch {
321325 // Ignore errors.
322326 }
0 commit comments