Skip to content

Commit

Permalink
feat!: update to chokidar v4 (#18453)
Browse files Browse the repository at this point in the history
Co-authored-by: 翠 / green <[email protected]>
  • Loading branch information
bluwy and sapphi-red authored Oct 29, 2024
1 parent a0336bd commit 192d555
Show file tree
Hide file tree
Showing 16 changed files with 181 additions and 483 deletions.
4 changes: 2 additions & 2 deletions docs/config/server-options.md
Original file line number Diff line number Diff line change
Expand Up @@ -205,11 +205,11 @@ export default defineConfig({

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

File system watcher options to pass on to [chokidar](https://github.com/paulmillr/chokidar#api).
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).

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.

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.
If set to `null`, no files will be watched. `server.watcher` will not watch any files and calling `add` will have no effect.

::: warning Watching files in `node_modules`

Expand Down
4 changes: 2 additions & 2 deletions docs/guide/api-javascript.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,8 @@ interface ViteDevServer {
httpServer: http.Server | null
/**
* Chokidar watcher instance. If `config.server.watch` is set to `null`,
* returns a noop event emitter.
* https://github.com/paulmillr/chokidar#api
* it will not watch any files and calling `add` will have no effect.
* https://github.com/paulmillr/chokidar#getting-started
*/
watcher: FSWatcher
/**
Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@
"vite": "workspace:*"
},
"patchedDependencies": {
"[email protected]": "patches/[email protected]",
"[email protected]": "patches/[email protected]",
"[email protected]": "patches/[email protected]",
"[email protected]": "patches/[email protected]"
Expand Down
154 changes: 2 additions & 152 deletions packages/vite/LICENSE.md
Original file line number Diff line number Diff line change
Expand Up @@ -418,29 +418,6 @@ Repositories: chalk/ansi-regex, sindresorhus/bundle-name, sindresorhus/default-b
---------------------------------------

## anymatch
License: ISC
By: Elan Shanker
Repository: https://github.com/micromatch/anymatch

> The ISC License
>
> Copyright (c) 2019 Elan Shanker, Paul Miller (https://paulmillr.com)
>
> Permission to use, copy, modify, and/or distribute this software for any
> purpose with or without fee is hereby granted, provided that the above
> copyright notice and this permission notice appear in all copies.
>
> THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
> WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
> MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
> ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
> WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
> ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
> IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
---------------------------------------

## artichokie
License: MIT
By: sapphi-red, Evan You
Expand Down Expand Up @@ -498,23 +475,6 @@ Repository: https://github.com/davidbonnet/astring.git
---------------------------------------

## binary-extensions, is-binary-path
License: MIT
By: Sindre Sorhus
Repositories: sindresorhus/binary-extensions, sindresorhus/is-binary-path

> MIT License
>
> Copyright (c) 2019 Sindre Sorhus <[email protected]> (https://sindresorhus.com), Paul Miller (https://paulmillr.com)
>
> 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:
>
> The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
>
> 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.
---------------------------------------

## braces, fill-range, is-number, micromatch
License: MIT
By: Jon Schlinkert, Brian Woodward, Elan Shanker, Eugene Sharygin, hemanth.hm
Expand Down Expand Up @@ -587,12 +547,12 @@ Repository: egoist/cac

## chokidar
License: MIT
By: Paul Miller, Elan Shanker
By: Paul Miller
Repository: git+https://github.com/paulmillr/chokidar.git

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

## glob-parent
License: ISC
By: Gulp Team, Elan Shanker, Blaine Bublitz
Repository: gulpjs/glob-parent

> The ISC License
>
> Copyright (c) 2015, 2019 Elan Shanker
>
> Permission to use, copy, modify, and/or distribute this software for any
> purpose with or without fee is hereby granted, provided that the above
> copyright notice and this permission notice appear in all copies.
>
> THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
> WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
> MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
> ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
> WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
> ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
> IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
---------------------------------------

## http-proxy
License: MIT
By: Charlie Robbins, jcrugzz <[email protected]>
Expand Down Expand Up @@ -1253,64 +1190,6 @@ Repository: git+https://github.com/css-modules/icss-utils.git
---------------------------------------

## is-extglob
License: MIT
By: Jon Schlinkert
Repository: jonschlinkert/is-extglob

> The MIT License (MIT)
>
> Copyright (c) 2014-2016, Jon Schlinkert
>
> 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:
>
> The above copyright notice and this permission notice shall be included in
> all copies or substantial portions of the Software.
>
> 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.
---------------------------------------

## is-glob
License: MIT
By: Jon Schlinkert, Brian Woodward, Daniel Perez
Repository: micromatch/is-glob

> The MIT License (MIT)
>
> Copyright (c) 2014-2017, Jon Schlinkert.
>
> 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:
>
> The above copyright notice and this permission notice shall be included in
> all copies or substantial portions of the Software.
>
> 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.
---------------------------------------

## is-reference
License: MIT
By: Rich Harris
Expand Down Expand Up @@ -1611,35 +1490,6 @@ Repository: vercel/ms
---------------------------------------

## normalize-path
License: MIT
By: Jon Schlinkert, Blaine Bublitz
Repository: jonschlinkert/normalize-path

> The MIT License (MIT)
>
> Copyright (c) 2014-2018, Jon Schlinkert.
>
> 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:
>
> The above copyright notice and this permission notice shall be included in
> all copies or substantial portions of the Software.
>
> 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.
---------------------------------------

## object-assign, pify
License: MIT
By: Sindre Sorhus
Expand Down
5 changes: 1 addition & 4 deletions packages/vite/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,6 @@
"postcss": "^8.4.47",
"rollup": "^4.23.0"
},
"optionalDependencies": {
"fsevents": "~2.3.3"
},
"devDependencies": {
"@ampproject/remapping": "^2.3.0",
"@babel/parser": "^7.26.1",
Expand All @@ -108,7 +105,7 @@
"@types/pnpapi": "^0.0.5",
"artichokie": "^0.2.1",
"cac": "^6.7.14",
"chokidar": "^3.6.0",
"chokidar": "^4.0.1",
"connect": "^3.7.0",
"convert-source-map": "^2.0.0",
"cors": "^2.8.5",
Expand Down
11 changes: 1 addition & 10 deletions packages/vite/rollup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ const nodeConfig = defineConfig({
},
external: [
/^vite\//,
'fsevents',
'lightningcss',
'rollup/parseAst',
// postcss-load-config
Expand All @@ -110,13 +109,6 @@ const nodeConfig = defineConfig({
// generate code that force require them upfront for side effects.
// Shim them with eval() so rollup can skip these calls.
shimDepsPlugin({
// chokidar -> fsevents
'fsevents-handler.js': [
{
src: `require('fsevents')`,
replacement: `__require('fsevents')`,
},
],
// postcss-import -> sugarss
'process-content.js': [
{
Expand Down Expand Up @@ -172,7 +164,6 @@ const moduleRunnerConfig = defineConfig({
'module-runner': path.resolve(__dirname, 'src/module-runner/index.ts'),
},
external: [
'fsevents',
'lightningcss',
'rollup/parseAst',
...Object.keys(pkg.dependencies),
Expand All @@ -198,7 +189,7 @@ const cjsConfig = defineConfig({
freeze: false,
sourcemap: false,
},
external: ['fsevents', ...Object.keys(pkg.dependencies)],
external: Object.keys(pkg.dependencies),
plugins: [...createSharedNodePlugins({}), bundleSizeLimit(175)],
})

Expand Down
1 change: 0 additions & 1 deletion packages/vite/scripts/dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ const serverOptions: BuildOptions = {
external: [
...Object.keys(packageJSON.dependencies),
...Object.keys(packageJSON.peerDependencies),
...Object.keys(packageJSON.optionalDependencies),
...Object.keys(packageJSON.devDependencies),
],
}
Expand Down
1 change: 1 addition & 0 deletions packages/vite/src/node/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -769,6 +769,7 @@ async function buildEnvironment(
resolvedOutDirs,
emptyOutDir,
environment.config.cacheDir,
true /* isRollupChokidar3 */,
)

const { watch } = await import('rollup')
Expand Down
6 changes: 1 addition & 5 deletions packages/vite/src/node/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,11 +210,7 @@ export type {
export type { Connect } from 'dep-types/connect'
export type { WebSocket, WebSocketAlias } from 'dep-types/ws'
export type { HttpProxy } from 'dep-types/http-proxy'
export type {
FSWatcher,
WatchOptions,
AwaitWriteFinishOptions,
} from 'dep-types/chokidar'
export type { FSWatcher, WatchOptions } from 'dep-types/chokidar'
export type { Terser } from 'dep-types/terser'
export type { RollupCommonJSOptions } from 'dep-types/commonjs'
export type { RollupDynamicImportVarsOptions } from 'dep-types/dynamicImportVars'
Expand Down
6 changes: 3 additions & 3 deletions packages/vite/src/node/server/__tests__/watcher.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { fileURLToPath } from 'node:url'
import { afterEach, describe, expect, it, vi } from 'vitest'
import { type ViteDevServer, createServer } from '../index'

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

describe('watcher configuration', () => {
let server: ViteDevServer | undefined
Expand All @@ -21,7 +21,7 @@ describe('watcher configuration', () => {
watch: null,
},
})
expect(server.watcher.getWatched.toString()).toMatch(stubGetWatchedCode)
expect(server.watcher.add.toString()).toMatch(stubGetWatchedCode)
})

it('when watcher is not disabled, return chokidar watcher', async () => {
Expand All @@ -30,7 +30,7 @@ describe('watcher configuration', () => {
watch: {},
},
})
expect(server.watcher.getWatched.toString()).not.toMatch(stubGetWatchedCode)
expect(server.watcher.add.toString()).not.toMatch(stubGetWatchedCode)
})

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

0 comments on commit 192d555

Please sign in to comment.