Skip to content

Commit

Permalink
fix: Matcher for chokidar WatchOptions#ignored (#4616)
Browse files Browse the repository at this point in the history
  • Loading branch information
hyf0 committed Aug 16, 2021
1 parent f75e508 commit 89e7a41
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 2 deletions.
1 change: 1 addition & 0 deletions packages/vite/src/node/index.ts
Expand Up @@ -83,3 +83,4 @@ export type { FSWatcher, WatchOptions } from 'types/chokidar'
export type { Terser } from 'types/terser'
export type { RollupCommonJSOptions } from 'types/commonjs'
export type { RollupDynamicImportVarsOptions } from 'types/dynamicImportVars'
export type { Matcher, AnymatchPattern, AnymatchFn } from 'types/anymatch'
6 changes: 5 additions & 1 deletion packages/vite/src/node/server/index.ts
Expand Up @@ -319,7 +319,11 @@ export async function createServer(

const { ignored = [], ...watchOptions } = serverConfig.watch || {}
const watcher = chokidar.watch(path.resolve(root), {
ignored: ['**/node_modules/**', '**/.git/**', ...ignored],
ignored: [
'**/node_modules/**',
'**/.git/**',
...(Array.isArray(ignored) ? ignored : [ignored])
],
ignoreInitial: true,
ignorePermissionErrors: true,
disableGlobbing: true,
Expand Down
5 changes: 5 additions & 0 deletions packages/vite/types/anymatch.d.ts
@@ -0,0 +1,5 @@
export type AnymatchFn = (testString: string) => boolean
export type AnymatchPattern = string | RegExp | AnymatchFn
type AnymatchMatcher = AnymatchPattern | AnymatchPattern[]

export { AnymatchMatcher as Matcher }
3 changes: 2 additions & 1 deletion packages/vite/types/chokidar.d.ts
Expand Up @@ -29,6 +29,7 @@ THE SOFTWARE.
/// <reference types="node" />

import * as fs from 'fs'
import { Matcher } from './anymatch'

export interface FSWatcher extends fs.FSWatcher {
options: WatchOptions
Expand Down Expand Up @@ -117,7 +118,7 @@ export interface WatchOptions {
* (the path), second time with two arguments (the path and the
* [`fs.Stats`](https://nodejs.org/api/fs.html#fs_class_fs_stats) object of that path).
*/
ignored?: any
ignored?: Matcher

/**
* If set to `false` then `add`/`addDir` events are also emitted for matching paths while
Expand Down

0 comments on commit 89e7a41

Please sign in to comment.