fix: (regression 3.0.4) it could happen that the config looked empty/reset on start, until restart
Massimo Melina committed
Mar 3, 2026 at 22:51 UTC
35fd431db1858bf04905e5928d6ce4e403adb9f3
1 file changed
+8
-3
src/watchLoad.ts
+8
-3
@@ -15,7 +15,7 @@ interface WatchLoadReturn { unwatch:WatchLoadCanceller, save: WriteFile, emitter
15
export function watchLoad(path:string, parser:(data:any)=>void|Promise<void>, { failedOnFirstAttempt, immediateFirst }:Options={}): WatchLoadReturn {
16
let doing = false
17
let watcher: FSWatcher | undefined
18
- const debounced = debounceAsync(load, { wait: 500, maxWait: 1000 })
18
+ const debounced = debounceAsync(load, { wait: 500, maxWait: 1000, reuseRunning: true })
19
let retry: NodeJS.Timeout
20
let last: string | undefined
21
const emitter = new BetterEventEmitter()
@@ -36,7 +36,7 @@ export function watchLoad(path:string, parser:(data:any)=>void|Promise<void>, {
36
void debounced()
37
})
38
debounced().catch(x=>x)
39
- if (immediateFirst)
39
+ if (immediateFirst && first)
40
void debounced.flush()
41
}
42
catch(e) {
@@ -61,7 +61,9 @@ export function watchLoad(path:string, parser:(data:any)=>void|Promise<void>, {
61
if (e.code === 'EPERM')
62
console.error("missing permissions on file", path) // warn user, who could be clueless about this problem
63
// keep the last good content on transient read failures so we don't apply accidental "empty file" state
64
- return e.code === 'ENOENT' ? '' : last
64
+ if (e.code === 'ENOENT')
65
+ return ''
66
+ throw e
67
})
68
if (text === last)
69
return
@@ -71,6 +73,9 @@ export function watchLoad(path:string, parser:(data:any)=>void|Promise<void>, {
73
unwatch(); install() // reinstall, as the original file could have been renamed. We watch by the name.
74
await parser(text)
75
}
76
+ catch(e) {
77
+ console.error("error loading", path, String(e))
78
+ }
79
finally {
80
doing = false
81
}