Skip to content

Commit dc05e42

Browse files
chore(deps)!: upgrade to chokidar v4 (#453)
Co-authored-by: Stian Jensen <me@stianj.com>
1 parent a0d3281 commit dc05e42

File tree

5 files changed

+60
-57
lines changed

5 files changed

+60
-57
lines changed

packages/vite-plugin-checker/package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,18 @@
3333
},
3434
"dependencies": {
3535
"@babel/code-frame": "^7.26.2",
36-
"chokidar": "^3.6.0",
36+
"chokidar": "^4.0.3",
3737
"colorette": "^2.0.20",
3838
"npm-run-path": "^6.0.0",
39+
"picomatch": "^4.0.2",
3940
"strip-ansi": "^7.1.0",
4041
"tiny-invariant": "^1.3.3",
4142
"tinyglobby": "^0.2.11",
4243
"vscode-uri": "^3.1.0"
4344
},
4445
"devDependencies": {
4546
"@types/eslint": "^7.29.0",
47+
"@types/picomatch": "^3.0.2",
4648
"@vue/language-core": "~2.2.2",
4749
"meow": "^13.2.0",
4850
"stylelint": "^16.14.1",

packages/vite-plugin-checker/src/checkers/eslint/main.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import invariant from 'tiny-invariant'
88

99
import { Checker } from '../../Checker.js'
1010
import { FileDiagnosticManager } from '../../FileDiagnosticManager.js'
11+
import { createIgnore } from '../../glob.js'
1112
import {
1213
composeCheckerSummary,
1314
consoleLog,
@@ -141,18 +142,18 @@ const createDiagnostic: CreateDiagnostic<'eslint'> = (pluginConfig) => {
141142
}
142143

143144
// initial lint
144-
const files = options._.slice(1)
145+
const files = options._.slice(1) as string[]
145146
const diagnostics = await eslint.lintFiles(files)
146147

147148
manager.initWith(diagnostics.flatMap((p) => normalizeEslintDiagnostic(p)))
148149
dispatchDiagnostics()
149150

150151
// watch lint
151-
const watcher = chokidar.watch([], {
152+
const watcher = chokidar.watch(root, {
152153
cwd: root,
153-
ignored: (path: string) => path.includes('node_modules'),
154+
ignored: createIgnore(root, files),
154155
})
155-
watcher.add(files)
156+
156157
watcher.on('change', async (filePath) => {
157158
handleFileChange(filePath, 'change')
158159
})

packages/vite-plugin-checker/src/checkers/stylelint/main.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { translateOptions } from './options.js'
77

88
import { Checker } from '../../Checker.js'
99
import { FileDiagnosticManager } from '../../FileDiagnosticManager.js'
10+
import { createIgnore } from '../../glob.js'
1011
import {
1112
composeCheckerSummary,
1213
consoleLog,
@@ -121,11 +122,11 @@ const createDiagnostic: CreateDiagnostic<'stylelint'> = (pluginConfig) => {
121122
dispatchDiagnostics()
122123

123124
// watch lint
124-
const watcher = chokidar.watch([], {
125+
const watcher = chokidar.watch(root, {
125126
cwd: root,
126-
ignored: (path: string) => path.includes('node_modules'),
127+
ignored: createIgnore(root, translatedOptions.files),
127128
})
128-
watcher.add(translatedOptions.files as string)
129+
129130
watcher.on('change', async (filePath) => {
130131
handleFileChange(filePath, 'change')
131132
})
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import { type Stats, statSync } from 'node:fs'
2+
import { join, relative, resolve } from 'node:path'
3+
import picomatch from 'picomatch'
4+
5+
export function createIgnore(_root: string, pattern: string | string[] = []) {
6+
const paths = Array.isArray(pattern) ? pattern : [pattern]
7+
const root = _root.replace(/\\/g, '/')
8+
9+
const globs = paths.flatMap((f) => {
10+
const resolvedPath = resolve(root, f)
11+
const relativePath = relative(root, resolvedPath).replace(/\\/g, '/')
12+
try {
13+
const isDirectory =
14+
!relativePath.includes('*') && statSync(resolvedPath).isDirectory()
15+
if (isDirectory) {
16+
return [relativePath, join(relativePath, '**/*').replace(/\\/g, '/')]
17+
}
18+
} catch {}
19+
return [relativePath]
20+
})
21+
22+
const matcher = picomatch(globs, { cwd: root })
23+
24+
return (path: string, _stats?: Stats) => {
25+
if (path.includes('node_modules')) {
26+
return true
27+
}
28+
const relativePath = relative(root, path).replace(/\\/g, '/')
29+
return (
30+
!!relativePath &&
31+
!matcher(relativePath) &&
32+
!(_stats ?? statSync(path)).isDirectory()
33+
)
34+
}
35+
}

pnpm-lock.yaml

Lines changed: 13 additions & 49 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)