Skip to content

Commit 0bcd594

Browse files
committed
feat(core): add watchers parameter to onWatched hook
1 parent 9d49773 commit 0bcd594

File tree

3 files changed

+5
-4
lines changed

3 files changed

+5
-4
lines changed

docs/.vuepress/config.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,16 +171,16 @@ const config: UserConfig<DefaultThemeOptions> = {
171171

172172
evergreen: process.env.NODE_ENV !== 'production',
173173

174-
onWatched: (_, restart) => {
174+
onWatched: (_, watchers, restart) => {
175175
const watcher = chokidar.watch('configs/**/*.ts', {
176176
cwd: __dirname,
177177
ignoreInitial: true,
178178
})
179179
watcher.on('change', async (file) => {
180180
logger.info(`file ${chalk.magenta(file)} is modified`)
181-
await watcher.close()
182181
await restart()
183182
})
183+
watchers.push(watcher)
184184
},
185185
}
186186

packages/@vuepress/cli/src/commands/dev/dev.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,5 +119,5 @@ export const dev = async (
119119
watchers.push(configWatcher)
120120
}
121121

122-
await app.pluginApi.hooks.onWatched.process(app, restart)
122+
await app.pluginApi.hooks.onWatched.process(app, watchers, restart)
123123
}

packages/@vuepress/core/src/types/plugin-api/hooks.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import type { Page } from '../page'
44

55
// util type
66
type PromiseOrNot<T> = Promise<T> | T
7+
type Closable = { close(): void }
78

89
// base hook type
910
export type Hook<
@@ -51,7 +52,7 @@ export type ExtendsPageDataHook = Hook<
5152
export interface Hooks {
5253
onInitialized: LifeCycleHook
5354
onPrepared: LifeCycleHook
54-
onWatched: LifeCycleHook<[restart: () => Promise<void>]>
55+
onWatched: LifeCycleHook<[watchers: Closable[], restart: () => Promise<void>]>
5556
onGenerated: LifeCycleHook
5657
extendsMarkdown: ExtendsMarkdownHook
5758
extendsPageData: ExtendsPageDataHook

0 commit comments

Comments
 (0)