• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

vuepress / vuepress-next / 7163313360

11 Dec 2023 05:25AM CUT coverage: 67.837% (-1.3%) from 69.176%
7163313360

Pull #1449

github

web-flow
Merge 4941993a9 into b82d48e1e
Pull Request #1449: feat: remove vuepress-vite and vuepress-webpack package and support --bundler option, close #1446

325 of 462 branches covered (0.0%)

Branch coverage included in aggregate %.

2 of 26 new or added lines in 4 files covered. (7.69%)

1 existing line in 1 file now uncovered.

641 of 962 relevant lines covered (66.63%)

47.76 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

2.17
/packages/cli/src/commands/dev/watchPageFiles.ts
1
import type { App, Page } from '@vuepress/core'
2
import { colors, logger } from '@vuepress/utils'
3
import chokidar from 'chokidar'
4
import type { FSWatcher } from 'chokidar'
5
import { handlePageAdd } from './handlePageAdd.js'
6
import { handlePageChange } from './handlePageChange.js'
7
import { handlePageUnlink } from './handlePageUnlink.js'
8
import { createPageDepsHelper } from './pageDepsHelper.js'
9

10
/**
11
 * Watch page files and deps, return file watchers
12
 */
13
export const watchPageFiles = (app: App): FSWatcher[] => {
3✔
14
  // watch page deps
15
  const depsWatcher = chokidar.watch([], {
×
16
    disableGlobbing: true,
17
    ignoreInitial: true,
18
  })
19
  const depsHelper = createPageDepsHelper()
×
20
  const addDeps = (page: Page): void => {
×
21
    const depsToAdd = depsHelper.add(page)
×
22
    depsWatcher.add(depsToAdd)
×
23
  }
24
  const removeDeps = (page: Page): void => {
×
25
    const depsToRemove = depsHelper.remove(page)
×
26
    depsWatcher.unwatch(depsToRemove)
×
27
  }
28
  const depsListener = async (dep: string): Promise<void> => {
×
29
    const pagePaths = depsHelper.get(dep)
×
30
    if (!pagePaths) return
×
31
    for (const filePathRelative of pagePaths) {
×
32
      logger.info(
×
33
        `dependency of page ${colors.magenta(filePathRelative)} is modified`,
34
      )
35
      await handlePageChange(app, app.dir.source(filePathRelative))
×
36
    }
37
  }
38
  depsWatcher.on('add', depsListener)
×
39
  depsWatcher.on('change', depsListener)
×
40
  depsWatcher.on('unlink', depsListener)
×
41
  app.pages.forEach((page) => addDeps(page))
×
42

43
  // watch page files
44
  const pagesWatcher = chokidar.watch(app.options.pagePatterns, {
×
45
    cwd: app.dir.source(),
46
    ignoreInitial: true,
47
  })
48
  pagesWatcher.on('add', async (filePathRelative) => {
×
49
    logger.info(`page ${colors.magenta(filePathRelative)} is created`)
×
50
    const page = await handlePageAdd(app, app.dir.source(filePathRelative))
×
51
    if (page === null) return
×
52
    addDeps(page)
×
53
  })
54
  pagesWatcher.on('change', async (filePathRelative) => {
×
55
    logger.info(`page ${colors.magenta(filePathRelative)} is modified`)
×
56
    const result = await handlePageChange(app, app.dir.source(filePathRelative))
×
57
    if (result === null) return
×
58
    const [pageOld, pageNew] = result
×
59
    removeDeps(pageOld)
×
60
    addDeps(pageNew)
×
61
  })
62
  pagesWatcher.on('unlink', async (filePathRelative) => {
×
63
    logger.info(`page ${colors.magenta(filePathRelative)} is removed`)
×
64
    const page = await handlePageUnlink(app, app.dir.source(filePathRelative))
×
65
    if (page === null) return
×
66
    removeDeps(page)
×
67
  })
68

69
  return [pagesWatcher, depsWatcher]
×
70
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc