Skip to content

Commit 1ab52b6

Browse files
authored
fix(cli): use a separate ignore matcher to ignore watched files (#1681)
1 parent 73a87c7 commit 1ab52b6

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

packages/cli/src/commands/dev/watchPageFiles.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -54,24 +54,24 @@ export const watchPageFiles = (app: App): FSWatcher[] => {
5454
const sourceDir = app.dir.source()
5555
const tempDir = app.dir.temp()
5656
const cacheDir = app.dir.cache()
57-
const isPageMatch = picomatch(pagePatterns, {
58-
ignore: ignorePatterns,
59-
cwd: sourceDir,
60-
})
57+
const ignoreMatcher = picomatch(ignorePatterns, { cwd: sourceDir })
58+
const pageMatcher = picomatch(pagePatterns, { cwd: sourceDir })
6159
const pagesWatcher = chokidar.watch('.', {
6260
cwd: sourceDir,
6361
ignored: (filepath, stats) => {
64-
// ignore node_modules
65-
if (filepath.includes('node_modules')) {
62+
// This is important so that folders like node_modules will be ignored immediately without traversing their children
63+
if (ignoreMatcher(filepath)) {
6664
return true
6765
}
68-
// ignore internal temp files
69-
if (filepath.startsWith(tempDir) || filepath.startsWith(cacheDir)) {
70-
return true
66+
67+
// ignore internal temp and cache directories
68+
if (stats?.isDirectory()) {
69+
return filepath === tempDir || filepath === cacheDir
7170
}
71+
7272
// ignore non-matched files
7373
return (
74-
!!stats?.isFile() && !isPageMatch(path.relative(sourceDir, filepath))
74+
!!stats?.isFile() && !pageMatcher(path.relative(sourceDir, filepath))
7575
)
7676
},
7777
ignoreInitial: true,

0 commit comments

Comments
 (0)