Skip to content

Commit 7862b3b

Browse files
committed
Fix fs sync method imports in claude.mjs
Import readFileSync and writeFileSync from node:fs separately from promises API to fix TypeError when calling sync methods.
1 parent 1a73ff8 commit 7862b3b

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

scripts/claude.mjs

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,21 @@
66

77
import { spawn } from 'node:child_process'
88
import 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'
1015
import os from 'node:os'
1116
import path from 'node:path'
1217
import { fileURLToPath } from 'node:url'
13-
import { parseArgs } from '@socketsecurity/lib/argv/parse'
18+
1419
import { deleteAsync as del } from 'del'
1520
import colors from 'yoctocolors-cjs'
1621

22+
import { parseArgs } from '@socketsecurity/lib/argv/parse'
23+
1724
const __dirname = path.dirname(fileURLToPath(import.meta.url))
1825
const rootPath = path.join(__dirname, '..')
1926
const 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

Comments
 (0)