Skip to content

Commit ab3e740

Browse files
committed
fix: type cli watcher events
1 parent 3d09242 commit ab3e740

1 file changed

Lines changed: 28 additions & 25 deletions

File tree

packages/doom/src/cli/index.ts

Lines changed: 28 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import path from 'node:path'
99

1010
import { logger } from '@rsbuild/core'
1111
import { build, dev, serve } from '@rspress/core'
12-
import { type FSWatcher, watch } from 'chokidar'
12+
import { type FSWatcher, type FSWatcherEventMap, watch } from 'chokidar'
1313
import { type Command, program } from 'commander'
1414
import { green } from 'yoctocolors'
1515

@@ -170,31 +170,34 @@ program
170170

171171
let isRestarting = false
172172

173-
cliWatcher.on('all', async (eventName, filepath) => {
174-
console.log(eventName, filepath)
175-
if (
176-
eventName === 'add' ||
177-
eventName === 'unlink' ||
178-
(eventName === 'change' &&
179-
(CONFIG_FILES.includes(path.basename(filepath)) ||
180-
path.basename(filepath) === META_FILE))
181-
) {
182-
if (isRestarting) {
183-
return
173+
cliWatcher.on(
174+
'all',
175+
async (...[eventName, filepath]: FSWatcherEventMap['all']) => {
176+
console.log(eventName, filepath)
177+
if (
178+
eventName === 'add' ||
179+
eventName === 'unlink' ||
180+
(eventName === 'change' &&
181+
(CONFIG_FILES.includes(path.basename(filepath)) ||
182+
path.basename(filepath) === META_FILE))
183+
) {
184+
if (isRestarting) {
185+
return
186+
}
187+
188+
isRestarting = true
189+
console.log(
190+
`\n✨ ${eventName} ${green(
191+
path.relative(CWD, filepath),
192+
)}, dev server will restart...\n`,
193+
)
194+
await devServer?.close()
195+
await cliWatcher.close()
196+
await startDevServer()
197+
isRestarting = false
184198
}
185-
186-
isRestarting = true
187-
console.log(
188-
`\n✨ ${eventName} ${green(
189-
path.relative(CWD, filepath),
190-
)}, dev server will restart...\n`,
191-
)
192-
await devServer?.close()
193-
await cliWatcher.close()
194-
await startDevServer()
195-
isRestarting = false
196-
}
197-
})
199+
},
200+
)
198201
}
199202

200203
await startDevServer()

0 commit comments

Comments
 (0)