1
1
import chalk from 'chalk' ;
2
2
import chokidar from 'chokidar' ;
3
3
import { glob } from 'glob' ;
4
+ import { minimatch } from 'minimatch' ;
5
+
4
6
import { DtsCreator } from './dts-creator' ;
5
7
import { DtsContent } from './dts-content' ;
6
8
@@ -41,6 +43,21 @@ export async function run(searchDir: string, options: RunOptions = {}): Promise<
41
43
42
44
const writeFile = async ( f : string ) : Promise < void > => {
43
45
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
+
44
61
const content : DtsContent = await creator . create ( f , undefined , ! ! options . watch ) ;
45
62
await content . writeFile ( ) ;
46
63
@@ -54,6 +71,11 @@ export async function run(searchDir: string, options: RunOptions = {}): Promise<
54
71
55
72
const deleteFile = async ( f : string ) : Promise < void > => {
56
73
try {
74
+ // Recheck patterh, see writeFile for explanation.
75
+ if ( ! ! options . watch && ! minimatch ( f , filesPattern ) ) {
76
+ return ;
77
+ }
78
+
57
79
const content : DtsContent = await creator . create ( f , undefined , ! ! options . watch , true ) ;
58
80
59
81
await content . deleteFile ( ) ;
0 commit comments