@@ -4,15 +4,21 @@ import SourceNode from './wrappers/source-node';
4
4
import SourceNodeWrapper from './wrappers/source-node' ;
5
5
import bindFileEvent from './utils/bind-file-event' ;
6
6
import HeimdallLogger from 'heimdalljs-logger' ;
7
+ import { isAbsolute , relative } from 'path' ;
7
8
8
9
const logger = new HeimdallLogger ( 'broccoli:watcherAdapter' ) ;
9
10
10
11
class WatcherAdapter extends EventEmitter {
11
12
watchers : sane . Watcher [ ] ;
12
13
watchedNodes : SourceNodeWrapper [ ] ;
13
14
options : sane . Options ;
15
+ private ignored : string [ ] | undefined ;
14
16
15
- constructor ( watchedNodes : SourceNodeWrapper [ ] , options : sane . Options = { } ) {
17
+ constructor (
18
+ watchedNodes : SourceNodeWrapper [ ] ,
19
+ options : sane . Options = { } ,
20
+ ignored : string [ ] | undefined = undefined
21
+ ) {
16
22
super ( ) ;
17
23
if ( ! Array . isArray ( watchedNodes ) ) {
18
24
throw new TypeError (
@@ -29,13 +35,14 @@ class WatcherAdapter extends EventEmitter {
29
35
}
30
36
this . watchedNodes = watchedNodes ;
31
37
this . options = options ;
38
+ this . ignored = ignored ;
32
39
this . watchers = [ ] ;
33
40
}
34
41
35
42
watch ( ) {
36
43
const watchers = this . watchedNodes . map ( ( node : SourceNodeWrapper ) => {
37
44
const watchedPath = node . nodeInfo . sourceDirectory ;
38
- const watcher = sane ( watchedPath , this . options ) ;
45
+ const watcher = sane ( watchedPath , this . optionsFor ( watchedPath ) ) ;
39
46
this . watchers . push ( watcher ) ;
40
47
bindFileEvent ( this , watcher , node , 'change' ) ;
41
48
bindFileEvent ( this , watcher , node , 'add' ) ;
@@ -73,6 +80,26 @@ class WatcherAdapter extends EventEmitter {
73
80
// eslint-disable-next-line @typescript-eslint/no-empty-function
74
81
return Promise . all ( closing ) . then ( ( ) => { } ) ;
75
82
}
83
+
84
+ private optionsFor ( watchedPath : string ) : sane . Options {
85
+ let options = this . options ;
86
+ if ( this . ignored ) {
87
+ // we need to convert any absolute ignored paths to local paths that sit
88
+ // within the watchedPath
89
+ const localIgnored = this . ignored
90
+ . map ( ignoredAbsPath => {
91
+ const ignoredRelativePath = relative ( watchedPath , ignoredAbsPath ) ;
92
+ if ( ! ignoredRelativePath . startsWith ( '..' ) && ! isAbsolute ( ignoredRelativePath ) ) {
93
+ return ignoredRelativePath + '/**' ;
94
+ }
95
+ } )
96
+ . filter ( Boolean ) as string [ ] ;
97
+ if ( localIgnored . length > 0 ) {
98
+ options = Object . assign ( { } , options , { ignored : localIgnored } ) ;
99
+ }
100
+ }
101
+ return options ;
102
+ }
76
103
}
77
104
78
105
export = WatcherAdapter ;
0 commit comments