Skip to content

Commit 77de5e4

Browse files
committed
Bugfix: Issue Quramy#97 - Ignore add/change messages from Chokidar on files that don't match the pattern.
1 parent 0609bee commit 77de5e4

File tree

3 files changed

+24
-0
lines changed

3 files changed

+24
-0
lines changed

package-lock.json

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
"glob": "^10.3.10",
4141
"icss-replace-symbols": "^1.1.0",
4242
"is-there": "^4.4.2",
43+
"minimatch": "^9.0.3",
4344
"mkdirp": "^3.0.0",
4445
"postcss": "^8.0.0",
4546
"postcss-modules-extract-imports": "^3.0.0",

src/run.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import chalk from 'chalk';
22
import chokidar from 'chokidar';
33
import { glob } from 'glob';
4+
import { minimatch } from 'minimatch';
5+
46
import { DtsCreator } from './dts-creator';
57
import { DtsContent } from './dts-content';
68

@@ -41,6 +43,21 @@ export async function run(searchDir: string, options: RunOptions = {}): Promise<
4143

4244
const writeFile = async (f: string): Promise<void> => {
4345
try {
46+
// If we're watching recheck the file against the pattern since
47+
// chokidar does not filter files inside symlinks and we don't
48+
// know (without checking every parent) if the file is inside a
49+
// symlink.
50+
//
51+
// Chokidar issue:
52+
//
53+
// https://github.com/paulmillr/chokidar/issues/967
54+
//
55+
// When that's fixed this can be removed (from deleteFile too),
56+
// but the issue is 2 years old already (reported 2020).
57+
if (!!options.watch && !minimatch(f, filesPattern)) {
58+
return;
59+
}
60+
4461
const content: DtsContent = await creator.create(f, undefined, !!options.watch);
4562
await content.writeFile();
4663

@@ -54,6 +71,11 @@ export async function run(searchDir: string, options: RunOptions = {}): Promise<
5471

5572
const deleteFile = async (f: string): Promise<void> => {
5673
try {
74+
// Recheck patterh, see writeFile for explanation.
75+
if (!!options.watch && !minimatch(f, filesPattern)) {
76+
return;
77+
}
78+
5779
const content: DtsContent = await creator.create(f, undefined, !!options.watch, true);
5880

5981
await content.deleteFile();

0 commit comments

Comments
 (0)