@@ -3,9 +3,47 @@ const chokidar = require('chokidar');
3
3
const paths = JSON . parse ( process . argv [ 2 ] ) ;
4
4
const poll = process . argv [ 3 ] ? true : false ;
5
5
6
- const watcher = chokidar . watch ( paths , {
6
+ // Chokidar removed support for glob in version 4...
7
+ const chokidarPackagePath = require . resolve ( 'chokidar' ) . replace ( 'index.js' , 'package.json' ) ;
8
+ const chokidarVersion4 = require ( chokidarPackagePath ) . version . startsWith ( '4.' ) ;
9
+
10
+ const extractWildcardExtension = ( path ) => {
11
+ // Match patterns like *.php, **/*.blade.php
12
+ const match = path . match ( / \/ \* \. ( ( \w | \. ) + ) $ / ) ;
13
+
14
+ return match ? match [ 1 ] : null ;
15
+ } ;
16
+
17
+ const getPathBeforeWildcard = ( path ) => {
18
+ const match = path . match ( / ^ ( .* ?) ( \* | $ ) / ) ;
19
+
20
+ return match ? match [ 1 ] : path ;
21
+ } ;
22
+
23
+ const extractedPaths = paths . map ( path => {
24
+ return { path : getPathBeforeWildcard ( path ) , extension : extractWildcardExtension ( path ) } ;
25
+ } ) ;
26
+
27
+ const watcherPaths = chokidarVersion4 ? extractedPaths . map ( ep => ep . path ) : paths ;
28
+
29
+ const watcherIgnored = chokidarVersion4 ? ( path , stats ) => {
30
+ if ( ! stats ?. isFile ( ) ) {
31
+ return false ;
32
+ }
33
+
34
+ const matchedPattern = extractedPaths . find ( ep => path . startsWith ( ep . path ) ) ;
35
+
36
+ if ( ! matchedPattern ) {
37
+ return true ;
38
+ }
39
+
40
+ return matchedPattern . extension ? ! path . endsWith ( `.${ matchedPattern . extension } ` ) : false ;
41
+ } : undefined ;
42
+
43
+ const watcher = chokidar . watch ( watcherPaths , {
7
44
ignoreInitial : true ,
8
45
usePolling : poll ,
46
+ ignored : watcherIgnored ,
9
47
} ) ;
10
48
11
49
watcher
0 commit comments