Skip to content

Commit c2e1521

Browse files
authored
feat(cli): upgrade chokidar to v4 (close #1605) (#1661)
1 parent 5eea315 commit c2e1521

File tree

7 files changed

+157
-113
lines changed

7 files changed

+157
-113
lines changed

.vscode/settings.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
"cSpell.words": [
2121
"bumpp",
2222
"bundlerutils",
23+
"chokidar",
2324
"composables",
2425
"devtool",
2526
"envinfo",

packages/cli/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
"@vuepress/shared": "workspace:*",
4141
"@vuepress/utils": "workspace:*",
4242
"cac": "^6.7.14",
43-
"chokidar": "^3.6.0",
43+
"chokidar": "^4.0.3",
4444
"envinfo": "^7.14.0",
4545
"esbuild": "^0.25.8"
4646
},

packages/cli/src/commands/dev/watchPageFiles.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* eslint-disable @typescript-eslint/no-misused-promises */
22
import type { App, Page } from '@vuepress/core'
3-
import { colors, logger } from '@vuepress/utils'
3+
import { colors, logger, picomatch } from '@vuepress/utils'
44
import type { FSWatcher } from 'chokidar'
55
import chokidar from 'chokidar'
66
import { handlePageAdd } from './handlePageAdd.js'
@@ -14,7 +14,6 @@ import { createPageDepsHelper } from './pageDepsHelper.js'
1414
export const watchPageFiles = (app: App): FSWatcher[] => {
1515
// watch page deps
1616
const depsWatcher = chokidar.watch([], {
17-
disableGlobbing: true,
1817
ignoreInitial: true,
1918
})
2019
const depsHelper = createPageDepsHelper()
@@ -43,8 +42,19 @@ export const watchPageFiles = (app: App): FSWatcher[] => {
4342
})
4443

4544
// watch page files
46-
const pagesWatcher = chokidar.watch(app.options.pagePatterns, {
45+
const pagePatternsMatchers = app.options.pagePatterns.map((pattern) =>
46+
picomatch(pattern, {
47+
cwd: app.dir.source(),
48+
}),
49+
)
50+
const pagesWatcher = chokidar.watch('.', {
4751
cwd: app.dir.source(),
52+
ignored: (filepath, stats) => {
53+
// do not ignore non-file paths
54+
if (!stats?.isFile()) return false
55+
// ignore if the file does not match all patterns
56+
return pagePatternsMatchers.some((matcher) => !matcher(filepath))
57+
},
4858
ignoreInitial: true,
4959
})
5060
pagesWatcher.on('add', async (filePathRelative) => {

packages/utils/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,14 @@
3434
"@types/debug": "^4.1.12",
3535
"@types/fs-extra": "^11.0.4",
3636
"@types/hash-sum": "^1.0.2",
37+
"@types/picomatch": "^4.0.2",
3738
"@vuepress/shared": "workspace:*",
3839
"debug": "^4.4.1",
3940
"fs-extra": "^11.3.0",
4041
"hash-sum": "^2.0.0",
4142
"ora": "^8.2.0",
4243
"picocolors": "^1.1.1",
44+
"picomatch": "^4.0.3",
4345
"tinyglobby": "^0.2.14",
4446
"upath": "^2.0.1"
4547
},

packages/utils/src/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@ import fs from 'fs-extra'
33
import hash from 'hash-sum'
44
import ora from 'ora'
55
import colors from 'picocolors'
6+
import picomatch from 'picomatch'
67
import * as tinyglobby from 'tinyglobby'
78
import path from 'upath'
89

9-
export { debug, colors, fs, hash, ora, path, tinyglobby }
10+
export { debug, colors, fs, hash, ora, path, picomatch, tinyglobby }
1011

1112
export * from './console/index.js'
1213
export * from './module/index.js'

0 commit comments

Comments
 (0)