Skip to content

Commit 192d555

Browse files
bluwysapphi-red
andauthored
feat!: update to chokidar v4 (#18453)
Co-authored-by: 翠 / green <green@sapphi.red>
1 parent a0336bd commit 192d555

16 files changed

Lines changed: 181 additions & 483 deletions

File tree

docs/config/server-options.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,11 +205,11 @@ export default defineConfig({
205205

206206
- **Type:** `object | null`
207207

208-
File system watcher options to pass on to [chokidar](https://github.com/paulmillr/chokidar#api).
208+
File system watcher options to pass on to [chokidar](https://github.com/paulmillr/chokidar#getting-started). If the `ignored` option is passed, Vite will also automatically convert any strings as [picomatch patterns](https://github.com/micromatch/picomatch#globbing-features).
209209

210210
The Vite server watcher watches the `root` and skips the `.git/`, `node_modules/`, and Vite's `cacheDir` and `build.outDir` directories by default. When updating a watched file, Vite will apply HMR and update the page only if needed.
211211

212-
If set to `null`, no files will be watched. `server.watcher` will provide a compatible event emitter, but calling `add` or `unwatch` will have no effect.
212+
If set to `null`, no files will be watched. `server.watcher` will not watch any files and calling `add` will have no effect.
213213

214214
::: warning Watching files in `node_modules`
215215

docs/guide/api-javascript.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,8 @@ interface ViteDevServer {
110110
httpServer: http.Server | null
111111
/**
112112
* Chokidar watcher instance. If `config.server.watch` is set to `null`,
113-
* returns a noop event emitter.
114-
* https://github.com/paulmillr/chokidar#api
113+
* it will not watch any files and calling `add` will have no effect.
114+
* https://github.com/paulmillr/chokidar#getting-started
115115
*/
116116
watcher: FSWatcher
117117
/**

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,6 @@
102102
"vite": "workspace:*"
103103
},
104104
"patchedDependencies": {
105-
"chokidar@3.6.0": "patches/chokidar@3.6.0.patch",
106105
"http-proxy@1.18.1": "patches/http-proxy@1.18.1.patch",
107106
"sirv@3.0.0": "patches/sirv@3.0.0.patch",
108107
"acorn@8.14.0": "patches/acorn@8.14.0.patch"

packages/vite/LICENSE.md

Lines changed: 2 additions & 152 deletions
Original file line numberDiff line numberDiff line change
@@ -418,29 +418,6 @@ Repositories: chalk/ansi-regex, sindresorhus/bundle-name, sindresorhus/default-b
418418
419419
---------------------------------------
420420

421-
## anymatch
422-
License: ISC
423-
By: Elan Shanker
424-
Repository: https://github.com/micromatch/anymatch
425-
426-
> The ISC License
427-
>
428-
> Copyright (c) 2019 Elan Shanker, Paul Miller (https://paulmillr.com)
429-
>
430-
> Permission to use, copy, modify, and/or distribute this software for any
431-
> purpose with or without fee is hereby granted, provided that the above
432-
> copyright notice and this permission notice appear in all copies.
433-
>
434-
> THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
435-
> WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
436-
> MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
437-
> ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
438-
> WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
439-
> ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
440-
> IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
441-
442-
---------------------------------------
443-
444421
## artichokie
445422
License: MIT
446423
By: sapphi-red, Evan You
@@ -498,23 +475,6 @@ Repository: https://github.com/davidbonnet/astring.git
498475
499476
---------------------------------------
500477

501-
## binary-extensions, is-binary-path
502-
License: MIT
503-
By: Sindre Sorhus
504-
Repositories: sindresorhus/binary-extensions, sindresorhus/is-binary-path
505-
506-
> MIT License
507-
>
508-
> Copyright (c) 2019 Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com), Paul Miller (https://paulmillr.com)
509-
>
510-
> Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
511-
>
512-
> The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
513-
>
514-
> THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
515-
516-
---------------------------------------
517-
518478
## braces, fill-range, is-number, micromatch
519479
License: MIT
520480
By: Jon Schlinkert, Brian Woodward, Elan Shanker, Eugene Sharygin, hemanth.hm
@@ -587,12 +547,12 @@ Repository: egoist/cac
587547

588548
## chokidar
589549
License: MIT
590-
By: Paul Miller, Elan Shanker
550+
By: Paul Miller
591551
Repository: git+https://github.com/paulmillr/chokidar.git
592552

593553
> The MIT License (MIT)
594554
>
595-
> Copyright (c) 2012-2019 Paul Miller (https://paulmillr.com), Elan Shanker
555+
> Copyright (c) 2012 Paul Miller (https://paulmillr.com), Elan Shanker
596556
>
597557
> Permission is hereby granted, free of charge, to any person obtaining a copy
598558
> of this software and associated documentation files (the “Software”), to deal
@@ -1186,29 +1146,6 @@ Repository: git+https://github.com/css-modules/generic-names.git
11861146
11871147
---------------------------------------
11881148

1189-
## glob-parent
1190-
License: ISC
1191-
By: Gulp Team, Elan Shanker, Blaine Bublitz
1192-
Repository: gulpjs/glob-parent
1193-
1194-
> The ISC License
1195-
>
1196-
> Copyright (c) 2015, 2019 Elan Shanker
1197-
>
1198-
> Permission to use, copy, modify, and/or distribute this software for any
1199-
> purpose with or without fee is hereby granted, provided that the above
1200-
> copyright notice and this permission notice appear in all copies.
1201-
>
1202-
> THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
1203-
> WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
1204-
> MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
1205-
> ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
1206-
> WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
1207-
> ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
1208-
> IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
1209-
1210-
---------------------------------------
1211-
12121149
## http-proxy
12131150
License: MIT
12141151
By: Charlie Robbins, jcrugzz <jcrugzz@gmail.com>
@@ -1253,64 +1190,6 @@ Repository: git+https://github.com/css-modules/icss-utils.git
12531190
12541191
---------------------------------------
12551192

1256-
## is-extglob
1257-
License: MIT
1258-
By: Jon Schlinkert
1259-
Repository: jonschlinkert/is-extglob
1260-
1261-
> The MIT License (MIT)
1262-
>
1263-
> Copyright (c) 2014-2016, Jon Schlinkert
1264-
>
1265-
> Permission is hereby granted, free of charge, to any person obtaining a copy
1266-
> of this software and associated documentation files (the "Software"), to deal
1267-
> in the Software without restriction, including without limitation the rights
1268-
> to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
1269-
> copies of the Software, and to permit persons to whom the Software is
1270-
> furnished to do so, subject to the following conditions:
1271-
>
1272-
> The above copyright notice and this permission notice shall be included in
1273-
> all copies or substantial portions of the Software.
1274-
>
1275-
> THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1276-
> IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1277-
> FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
1278-
> AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
1279-
> LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
1280-
> OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
1281-
> THE SOFTWARE.
1282-
1283-
---------------------------------------
1284-
1285-
## is-glob
1286-
License: MIT
1287-
By: Jon Schlinkert, Brian Woodward, Daniel Perez
1288-
Repository: micromatch/is-glob
1289-
1290-
> The MIT License (MIT)
1291-
>
1292-
> Copyright (c) 2014-2017, Jon Schlinkert.
1293-
>
1294-
> Permission is hereby granted, free of charge, to any person obtaining a copy
1295-
> of this software and associated documentation files (the "Software"), to deal
1296-
> in the Software without restriction, including without limitation the rights
1297-
> to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
1298-
> copies of the Software, and to permit persons to whom the Software is
1299-
> furnished to do so, subject to the following conditions:
1300-
>
1301-
> The above copyright notice and this permission notice shall be included in
1302-
> all copies or substantial portions of the Software.
1303-
>
1304-
> THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1305-
> IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1306-
> FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
1307-
> AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
1308-
> LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
1309-
> OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
1310-
> THE SOFTWARE.
1311-
1312-
---------------------------------------
1313-
13141193
## is-reference
13151194
License: MIT
13161195
By: Rich Harris
@@ -1611,35 +1490,6 @@ Repository: vercel/ms
16111490
16121491
---------------------------------------
16131492

1614-
## normalize-path
1615-
License: MIT
1616-
By: Jon Schlinkert, Blaine Bublitz
1617-
Repository: jonschlinkert/normalize-path
1618-
1619-
> The MIT License (MIT)
1620-
>
1621-
> Copyright (c) 2014-2018, Jon Schlinkert.
1622-
>
1623-
> Permission is hereby granted, free of charge, to any person obtaining a copy
1624-
> of this software and associated documentation files (the "Software"), to deal
1625-
> in the Software without restriction, including without limitation the rights
1626-
> to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
1627-
> copies of the Software, and to permit persons to whom the Software is
1628-
> furnished to do so, subject to the following conditions:
1629-
>
1630-
> The above copyright notice and this permission notice shall be included in
1631-
> all copies or substantial portions of the Software.
1632-
>
1633-
> THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1634-
> IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1635-
> FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
1636-
> AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
1637-
> LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
1638-
> OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
1639-
> THE SOFTWARE.
1640-
1641-
---------------------------------------
1642-
16431493
## object-assign, pify
16441494
License: MIT
16451495
By: Sindre Sorhus

packages/vite/package.json

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,6 @@
9090
"postcss": "^8.4.47",
9191
"rollup": "^4.23.0"
9292
},
93-
"optionalDependencies": {
94-
"fsevents": "~2.3.3"
95-
},
9693
"devDependencies": {
9794
"@ampproject/remapping": "^2.3.0",
9895
"@babel/parser": "^7.26.1",
@@ -108,7 +105,7 @@
108105
"@types/pnpapi": "^0.0.5",
109106
"artichokie": "^0.2.1",
110107
"cac": "^6.7.14",
111-
"chokidar": "^3.6.0",
108+
"chokidar": "^4.0.1",
112109
"connect": "^3.7.0",
113110
"convert-source-map": "^2.0.0",
114111
"cors": "^2.8.5",

packages/vite/rollup.config.ts

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,6 @@ const nodeConfig = defineConfig({
9696
},
9797
external: [
9898
/^vite\//,
99-
'fsevents',
10099
'lightningcss',
101100
'rollup/parseAst',
102101
// postcss-load-config
@@ -110,13 +109,6 @@ const nodeConfig = defineConfig({
110109
// generate code that force require them upfront for side effects.
111110
// Shim them with eval() so rollup can skip these calls.
112111
shimDepsPlugin({
113-
// chokidar -> fsevents
114-
'fsevents-handler.js': [
115-
{
116-
src: `require('fsevents')`,
117-
replacement: `__require('fsevents')`,
118-
},
119-
],
120112
// postcss-import -> sugarss
121113
'process-content.js': [
122114
{
@@ -172,7 +164,6 @@ const moduleRunnerConfig = defineConfig({
172164
'module-runner': path.resolve(__dirname, 'src/module-runner/index.ts'),
173165
},
174166
external: [
175-
'fsevents',
176167
'lightningcss',
177168
'rollup/parseAst',
178169
...Object.keys(pkg.dependencies),
@@ -198,7 +189,7 @@ const cjsConfig = defineConfig({
198189
freeze: false,
199190
sourcemap: false,
200191
},
201-
external: ['fsevents', ...Object.keys(pkg.dependencies)],
192+
external: Object.keys(pkg.dependencies),
202193
plugins: [...createSharedNodePlugins({}), bundleSizeLimit(175)],
203194
})
204195

packages/vite/scripts/dev.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ const serverOptions: BuildOptions = {
2424
external: [
2525
...Object.keys(packageJSON.dependencies),
2626
...Object.keys(packageJSON.peerDependencies),
27-
...Object.keys(packageJSON.optionalDependencies),
2827
...Object.keys(packageJSON.devDependencies),
2928
],
3029
}

packages/vite/src/node/build.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -769,6 +769,7 @@ async function buildEnvironment(
769769
resolvedOutDirs,
770770
emptyOutDir,
771771
environment.config.cacheDir,
772+
true /* isRollupChokidar3 */,
772773
)
773774

774775
const { watch } = await import('rollup')

packages/vite/src/node/index.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -210,11 +210,7 @@ export type {
210210
export type { Connect } from 'dep-types/connect'
211211
export type { WebSocket, WebSocketAlias } from 'dep-types/ws'
212212
export type { HttpProxy } from 'dep-types/http-proxy'
213-
export type {
214-
FSWatcher,
215-
WatchOptions,
216-
AwaitWriteFinishOptions,
217-
} from 'dep-types/chokidar'
213+
export type { FSWatcher, WatchOptions } from 'dep-types/chokidar'
218214
export type { Terser } from 'dep-types/terser'
219215
export type { RollupCommonJSOptions } from 'dep-types/commonjs'
220216
export type { RollupDynamicImportVarsOptions } from 'dep-types/dynamicImportVars'

packages/vite/src/node/server/__tests__/watcher.spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { fileURLToPath } from 'node:url'
33
import { afterEach, describe, expect, it, vi } from 'vitest'
44
import { type ViteDevServer, createServer } from '../index'
55

6-
const stubGetWatchedCode = /getWatched\(\) \{.+?return \{\};.+?\}/s
6+
const stubGetWatchedCode = /function\(\)\s*\{\s*return this;\s*\}/
77

88
describe('watcher configuration', () => {
99
let server: ViteDevServer | undefined
@@ -21,7 +21,7 @@ describe('watcher configuration', () => {
2121
watch: null,
2222
},
2323
})
24-
expect(server.watcher.getWatched.toString()).toMatch(stubGetWatchedCode)
24+
expect(server.watcher.add.toString()).toMatch(stubGetWatchedCode)
2525
})
2626

2727
it('when watcher is not disabled, return chokidar watcher', async () => {
@@ -30,7 +30,7 @@ describe('watcher configuration', () => {
3030
watch: {},
3131
},
3232
})
33-
expect(server.watcher.getWatched.toString()).not.toMatch(stubGetWatchedCode)
33+
expect(server.watcher.add.toString()).not.toMatch(stubGetWatchedCode)
3434
})
3535

3636
it('should watch the root directory, config file dependencies, dotenv files, and the public directory', async () => {

0 commit comments

Comments
 (0)