Skip to content

Commit ce4ce3e

Browse files
jtmthfTheLarkInn
authored andcommitted
Upgrade WatchIgnorePlugin to es6 (webpack#3693)
* Upgrade WatchIgnorePlugin to es6 * Improved test coverage for WatchIgnorePlugin Now tests ignoring of dirs
1 parent 879adef commit ce4ce3e

File tree

6 files changed

+42
-36
lines changed

6 files changed

+42
-36
lines changed

lib/WatchIgnorePlugin.js

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -2,48 +2,48 @@
22
MIT License http://www.opensource.org/licenses/mit-license.php
33
Author Tobias Koppers @sokra
44
*/
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+
}
717
}
818

919
module.exports = WatchIgnorePlugin;
1020

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+
}
1626

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);
2129

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);
2831

29-
var notIgnored = function(path) {
30-
return !ignored(path);
31-
};
32+
const ignoredFiles = files.filter(ignored);
33+
const ignoredDirs = dirs.filter(ignored);
3234

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);
3537

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+
});
3841

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+
});
4645

47-
callback(err, filesModified, dirsModified, missingModified, fileTimestamps, dirTimestamps);
48-
}, callbackUndelayed);
49-
};
46+
callback(err, filesModified, dirsModified, missingModified, fileTimestamps, dirTimestamps);
47+
}, callbackUndelayed);
48+
}
49+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export default 0;
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import value from "./file"
22
import a from "./a"
3-
it("should ignore change to file", function() {
3+
const req = require.context("./foo", false, /^.*\.js$/);
4+
it("should ignore change to file and directory", function() {
45
a.should.be.eql(+WATCH_STEP);
6+
req.keys().should.be.deepEqual(["./0.js"])
57
value.should.be.eql(1);
68
});
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export default 1;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export default 2;
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
var webpack = require("../../../../");
2+
var path = require("path");
23

34
module.exports = {
45
plugins: [
5-
new webpack.WatchIgnorePlugin([/file\.js$/])
6+
new webpack.WatchIgnorePlugin([/file\.js$/, /foo$/])
67
]
78
};

0 commit comments

Comments
 (0)