Skip to content

Commit

Permalink
refactor!: reduce dependencies
Browse files Browse the repository at this point in the history
Upgrade chokidar to v4
  • Loading branch information
posva committed Jan 26, 2025
1 parent c632393 commit 46a629d
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 9 deletions.
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -136,11 +136,12 @@
"@rollup/pluginutils": "^5.1.4",
"@vue-macros/common": "^1.16.1",
"ast-walker-scope": "^0.6.2",
"chokidar": "^3.6.0",
"chokidar": "^4.0.3",
"fast-glob": "^3.3.3",
"json5": "^2.2.3",
"local-pkg": "^1.0.0",
"magic-string": "^0.30.17",
"micromatch": "^4.0.8",
"mlly": "^1.7.4",
"pathe": "^2.0.2",
"scule": "^1.3.0",
Expand All @@ -160,6 +161,7 @@
"@posva/prompts": "^2.4.4",
"@shikijs/vitepress-twoslash": "2.1.0",
"@tanstack/vue-query": "^5.64.2",
"@types/micromatch": "^4.0.9",
"@types/node": "^22.10.10",
"@vitest/coverage-v8": "^3.0.4",
"@vitest/ui": "^3.0.4",
Expand Down
22 changes: 20 additions & 2 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 21 additions & 6 deletions src/core/RoutesFolderWatcher.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import chokidar from 'chokidar'
import { type FSWatcher, watch as fsWatch } from 'chokidar'
import micromatch from 'micromatch'
import { resolve } from 'pathe'
import {
ResolvedOptions,
Expand All @@ -17,23 +18,37 @@ export class RoutesFolderWatcher {
filePatterns: string[]
exclude: string[]

watcher: chokidar.FSWatcher
watcher: FSWatcher

constructor(folderOptions: RoutesFolderOptionResolved) {
this.src = folderOptions.src
this.path = folderOptions.path
this.exclude = folderOptions.exclude
this.extensions = folderOptions.extensions
this.filePatterns = folderOptions.filePatterns
console.log(
'🚀 ~ file: RoutesFolderWatcher.ts ~ line 86 ~ RoutesFolderWatcher ~ constructor ~ this.filePatterns',
this.filePatterns
)

this.watcher = chokidar.watch(folderOptions.pattern, {
this.watcher = fsWatch('.', {
cwd: this.src,
ignoreInitial: true,
// disableGlobbing: true,
ignorePermissionErrors: true,
ignored: this.exclude,
ignored: (filepath, stats) => {
// let folders pass, they are ignored by the glob pattern
if (stats?.isDirectory()) {
return false
}

const isMatch = micromatch.isMatch(filepath, this.filePatterns, {
cwd: this.src,
ignore: this.exclude,
})

return !isMatch
},

// useFsEvents: true,
// TODO: allow user options
})
}
Expand Down

0 comments on commit 46a629d

Please sign in to comment.