@@ -39,85 +39,91 @@ function watch() {
39
39
var promises = [ ] ;
40
40
var watchedFiles = [ ] ;
41
41
42
- dirs . forEach ( function ( dir ) {
43
- var promise = new Promise ( function ( resolve ) {
44
- var dotFilePattern = / [ / \\ ] \. / ;
45
- var ignored = Array . from ( rootIgnored ) ;
46
-
47
- // don't ignore dotfiles if explicitly watched.
48
- if ( ! dir . match ( dotFilePattern ) ) {
49
- ignored . push ( dotFilePattern ) ;
50
- }
42
+ const promise = new Promise ( function ( resolve ) {
43
+ const dotFilePattern = / [ / \\ ] \. / ;
44
+ var ignored = Array . from ( rootIgnored ) ;
45
+ const addDotFile = dirs . filter ( dir => dir . match ( dotFilePattern ) ) ;
46
+
47
+ // don't ignore dotfiles if explicitly watched.
48
+ if ( addDotFile . length === 0 ) {
49
+ ignored . push ( dotFilePattern ) ;
50
+ }
51
51
52
+ dirs = dirs . map ( dir => {
52
53
// if the directory is a file, it somehow causes
53
54
// windows to lose the filename upon change
54
55
if ( fs . statSync ( dir ) . isFile ( ) ) {
55
56
dir = path . dirname ( dir ) ;
56
57
}
57
58
58
- var watchOptions = {
59
- ignorePermissionErrors : true ,
60
- cwd : dir ,
61
- ignored : ignored ,
62
- persistent : true ,
63
- usePolling : config . options . legacyWatch || false ,
64
- interval : config . options . pollingInterval ,
65
- } ;
66
-
67
- if ( utils . isWindows ) {
68
- watchOptions . disableGlobbing = true ;
69
- }
59
+ return dir ;
60
+ } ) ;
70
61
71
- if ( process . env . TEST ) {
72
- watchOptions . useFsEvents = false ;
73
- }
62
+ var watchOptions = {
63
+ ignorePermissionErrors : true ,
64
+ cwd : process . cwd ( ) , // dir,
65
+ ignored : ignored ,
66
+ persistent : true ,
67
+ usePolling : config . options . legacyWatch || false ,
68
+ interval : config . options . pollingInterval ,
69
+ } ;
74
70
75
- var watcher = chokidar . watch (
76
- dir ,
77
- Object . assign ( { } , watchOptions , config . watchOptions || { } )
78
- ) ;
71
+ if ( utils . isWindows ) {
72
+ watchOptions . disableGlobbing = true ;
73
+ }
79
74
80
- watcher . ready = false ;
75
+ if ( process . env . TEST ) {
76
+ watchOptions . useFsEvents = false ;
77
+ }
81
78
82
- var total = 0 ;
79
+ var watcher = chokidar . watch (
80
+ dirs ,
81
+ Object . assign ( { } , watchOptions , config . watchOptions || { } )
82
+ ) ;
83
83
84
- watcher . on ( 'change' , filterAndRestart ) ;
85
- watcher . on ( 'add' , function ( file ) {
86
- if ( watcher . ready ) {
87
- return filterAndRestart ( file ) ;
88
- }
84
+ watcher . ready = false ;
89
85
90
- watchedFiles . push ( file ) ;
91
- watchedFiles = Array . from ( new Set ( watchedFiles ) ) ; // ensure no dupes
92
- total = watchedFiles . length ;
93
- bus . emit ( 'watching' , file ) ;
94
- debug ( 'watching dir: %s' , file ) ;
95
- } ) ;
96
- watcher . on ( 'ready' , function ( ) {
97
- watcher . ready = true ;
98
- resolve ( total ) ;
99
- debugRoot ( 'watch is complete' ) ;
100
- } ) ;
86
+ var total = 0 ;
101
87
102
- watcher . on ( 'error' , function ( error ) {
103
- if ( error . code === 'EINVAL' ) {
104
- utils . log . error (
105
- 'Internal watch failed. Likely cause: too many ' +
106
- 'files being watched (perhaps from the root of a drive?\n' +
107
- 'See https://github.com/paulmillr/chokidar/issues/229 for details'
108
- ) ;
109
- } else {
110
- utils . log . error ( 'Internal watch failed: ' + error . message ) ;
111
- process . exit ( 1 ) ;
112
- }
113
- } ) ;
88
+ watcher . on ( 'change' , filterAndRestart ) ;
89
+ watcher . on ( 'add' , function ( file ) {
90
+ if ( watcher . ready ) {
91
+ return filterAndRestart ( file ) ;
92
+ }
114
93
115
- watchers . push ( watcher ) ;
94
+ watchedFiles . push ( file ) ;
95
+ watchedFiles = Array . from ( new Set ( watchedFiles ) ) ; // ensure no dupes
96
+ total = watchedFiles . length ;
97
+ bus . emit ( 'watching' , file ) ;
98
+ debug ( 'watching dir: %s' , file ) ;
99
+ } ) ;
100
+ watcher . on ( 'ready' , function ( ) {
101
+ watcher . ready = true ;
102
+ resolve ( total ) ;
103
+ debugRoot ( 'watch is complete' ) ;
116
104
} ) ;
117
- promises . push ( promise ) ;
105
+
106
+ watcher . on ( 'error' , function ( error ) {
107
+ if ( error . code === 'EINVAL' ) {
108
+ utils . log . error (
109
+ 'Internal watch failed. Likely cause: too many ' +
110
+ 'files being watched (perhaps from the root of a drive?\n' +
111
+ 'See https://github.com/paulmillr/chokidar/issues/229 for details'
112
+ ) ;
113
+ } else {
114
+ utils . log . error ( 'Internal watch failed: ' + error . message ) ;
115
+ process . exit ( 1 ) ;
116
+ }
117
+ } ) ;
118
+
119
+ watchers . push ( watcher ) ;
118
120
} ) ;
119
121
120
- return Promise . all ( promises ) . then ( function ( res ) {
122
+ return promise . catch ( e => {
123
+ setTimeout ( ( ) => {
124
+ throw e ;
125
+ } ) ;
126
+ } ) . then ( function ( res ) {
121
127
utils . log . detail ( `watching ${ watchedFiles . length } file${
122
128
watchedFiles . length === 1 ? '' : 's' } `) ;
123
129
return watchedFiles ;
0 commit comments