Skip to content

Commit

Permalink
types(vite): replace any with Matcher for chokidar WatchOptions#i…
Browse files Browse the repository at this point in the history
…gnored
  • Loading branch information
heyunfei.i committed Aug 16, 2021
1 parent 3f40bbb commit cd50620
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 2 deletions.
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
28 changes: 28 additions & 0 deletions packages/vite/types/anymatch.d.ts
@@ -0,0 +1,28 @@
type AnymatchFn = (testString: string) => boolean
type AnymatchPattern = string | RegExp | AnymatchFn
type AnymatchMatcher = AnymatchPattern | AnymatchPattern[]
type AnymatchTester = {
(testString: string | any[], returnIndex: true): number
(testString: string | any[]): boolean
}

type PicomatchOptions = { dot: boolean }

declare const anymatch: {
(matchers: AnymatchMatcher): AnymatchTester
(
matchers: AnymatchMatcher,
testString: null,
returnIndex: true | PicomatchOptions
): AnymatchTester
(
matchers: AnymatchMatcher,
testString: string | any[],
returnIndex: true | PicomatchOptions
): number
(matchers: AnymatchMatcher, testString: string | any[]): boolean
}

export { AnymatchMatcher as Matcher }
export { AnymatchTester as Tester }
export default anymatch
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?: string[]
ignored?: Matcher

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

0 comments on commit cd50620

Please sign in to comment.