|
2 | 2 | MIT License http://www.opensource.org/licenses/mit-license.php |
3 | 3 | Author Tobias Koppers @sokra |
4 | 4 | */ |
5 | | -function WatchIgnorePlugin(paths) { |
6 | | - this.paths = paths; |
| 5 | +"use strict" |
| 6 | + |
| 7 | +class WatchIgnorePlugin { |
| 8 | + constructor(paths) { |
| 9 | + this.paths = paths; |
| 10 | + } |
| 11 | + |
| 12 | + apply(compiler) { |
| 13 | + compiler.plugin("after-environment", () => { |
| 14 | + compiler.watchFileSystem = new IgnoringWatchFileSystem(compiler.watchFileSystem, this.paths); |
| 15 | + }); |
| 16 | + } |
7 | 17 | } |
8 | 18 |
|
9 | 19 | module.exports = WatchIgnorePlugin; |
10 | 20 |
|
11 | | -WatchIgnorePlugin.prototype.apply = function(compiler) { |
12 | | - compiler.plugin("after-environment", function() { |
13 | | - compiler.watchFileSystem = new IgnoringWatchFileSystem(compiler.watchFileSystem, this.paths); |
14 | | - }.bind(this)); |
15 | | -}; |
| 21 | +class IgnoringWatchFileSystem { |
| 22 | + constructor(wfs, paths) { |
| 23 | + this.wfs = wfs; |
| 24 | + this.paths = paths; |
| 25 | + } |
16 | 26 |
|
17 | | -function IgnoringWatchFileSystem(wfs, paths) { |
18 | | - this.wfs = wfs; |
19 | | - this.paths = paths; |
20 | | -} |
| 27 | + watch(files, dirs, missing, startTime, options, callback, callbackUndelayed) { |
| 28 | + const ignored = path => this.paths.some(p => p instanceof RegExp ? p.test(path) : path.indexOf(p) === 0); |
21 | 29 |
|
22 | | -IgnoringWatchFileSystem.prototype.watch = function(files, dirs, missing, startTime, options, callback, callbackUndelayed) { |
23 | | - var ignored = function(path) { |
24 | | - return this.paths.some(function(p) { |
25 | | - return p instanceof RegExp ? p.test(path) : path.indexOf(p) === 0; |
26 | | - }); |
27 | | - }.bind(this); |
| 30 | + const notIgnored = path => !ignored(path); |
28 | 31 |
|
29 | | - var notIgnored = function(path) { |
30 | | - return !ignored(path); |
31 | | - }; |
| 32 | + const ignoredFiles = files.filter(ignored); |
| 33 | + const ignoredDirs = dirs.filter(ignored); |
32 | 34 |
|
33 | | - var ignoredFiles = files.filter(ignored); |
34 | | - var ignoredDirs = dirs.filter(ignored); |
| 35 | + this.wfs.watch(files.filter(notIgnored), dirs.filter(notIgnored), missing, startTime, options, (err, filesModified, dirsModified, missingModified, fileTimestamps, dirTimestamps) => { |
| 36 | + if(err) return callback(err); |
35 | 37 |
|
36 | | - this.wfs.watch(files.filter(notIgnored), dirs.filter(notIgnored), missing, startTime, options, function(err, filesModified, dirsModified, missingModified, fileTimestamps, dirTimestamps) { |
37 | | - if(err) return callback(err); |
| 38 | + ignoredFiles.forEach(path => { |
| 39 | + fileTimestamps[path] = 1; |
| 40 | + }); |
38 | 41 |
|
39 | | - ignoredFiles.forEach(function(path) { |
40 | | - fileTimestamps[path] = 1; |
41 | | - }); |
42 | | - |
43 | | - ignoredDirs.forEach(function(path) { |
44 | | - dirTimestamps[path] = 1; |
45 | | - }); |
| 42 | + ignoredDirs.forEach(path => { |
| 43 | + dirTimestamps[path] = 1; |
| 44 | + }); |
46 | 45 |
|
47 | | - callback(err, filesModified, dirsModified, missingModified, fileTimestamps, dirTimestamps); |
48 | | - }, callbackUndelayed); |
49 | | -}; |
| 46 | + callback(err, filesModified, dirsModified, missingModified, fileTimestamps, dirTimestamps); |
| 47 | + }, callbackUndelayed); |
| 48 | + } |
| 49 | +} |
0 commit comments