Skip to content

Commit 59a4990

Browse files
authoredMay 16, 2020
Merge pull request #153 from coreyward/update-chokidar
Update chokidar to 3.3.0
2 parents 88e13a6 + f53f6c7 commit 59a4990

9 files changed

+182
-257
lines changed
 

‎.travis.yml

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ os:
44
- linux
55
- osx
66
node_js:
7+
- "14"
78
- "12"
89
- "10"
910
- "8"

‎appveyor.yml

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ init:
77
# what combinations to test
88
environment:
99
matrix:
10+
- nodejs_version: 14
1011
- nodejs_version: 12
1112
- nodejs_version: 10
1213
- nodejs_version: 8

‎chokidar2/index.js

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = require("chokidar");

‎chokidar2/package.json

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"name": "chokidar2",
3+
"version": "2.0.0",
4+
"private": true,
5+
"engines": {
6+
"node": "<8.10.0"
7+
},
8+
"dependencies": {
9+
"chokidar": "^2.1.8"
10+
}
11+
}

‎lib/DirectoryWatcher.js

+5-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
var EventEmitter = require("events").EventEmitter;
88
var async = require("neo-async");
9-
var chokidar = require("chokidar");
9+
var chokidar = require("./chokidar");
1010
var fs = require("graceful-fs");
1111
var path = require("path");
1212

@@ -282,7 +282,8 @@ DirectoryWatcher.prototype.onDirectoryUnlinked = function onDirectoryUnlinked(di
282282
}
283283
};
284284

285-
DirectoryWatcher.prototype.onWatcherError = function onWatcherError(/* err */) {
285+
DirectoryWatcher.prototype.onWatcherError = function onWatcherError(err) {
286+
console.warn("Error from chokidar (" + this.path + "): " + err);
286287
};
287288

288289
DirectoryWatcher.prototype.doInitialScan = function doInitialScan() {
@@ -356,7 +357,8 @@ DirectoryWatcher.prototype.getTimes = function() {
356357

357358
DirectoryWatcher.prototype.close = function() {
358359
this.initialScan = false;
359-
this.watcher.close();
360+
var p = this.watcher.close();
361+
if(p && p.catch) p.catch(this.onWatcherError.bind(this));
360362
if(this.nestedWatching) {
361363
Object.keys(this.directories).forEach(function(dir) {
362364
this.directories[dir].close();

‎lib/chokidar.js

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
var v3Err;
2+
try {
3+
module.exports = require("chokidar");
4+
return;
5+
} catch(e) {
6+
v3Err = e;
7+
}
8+
9+
var v2Err;
10+
try {
11+
module.exports = require("chokidar2");
12+
return;
13+
} catch(e) {
14+
v2Err = e;
15+
}
16+
17+
throw new Error(
18+
"No version of chokidar is available. Tried chokidar@2 and chokidar@3.\n" +
19+
"You could try to manually install any chokidar version.\n" +
20+
"chokidar@3: " + v3Err + "\n" +
21+
"chokidar@2: " + v2Err + "\n"
22+
)

‎package.json

+4-1
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,11 @@
3636
"rimraf": "^2.6.2",
3737
"should": "^8.3.1"
3838
},
39+
"optionalDependencies": {
40+
"chokidar": "^3.4.0",
41+
"chokidar2": "file:./chokidar2"
42+
},
3943
"dependencies": {
40-
"chokidar": "^2.1.8",
4144
"graceful-fs": "^4.1.2",
4245
"neo-async": "^2.5.0"
4346
}

‎test/Assumption.js

+34-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
require("should");
55
var path = require("path");
66
var fs = require("fs");
7-
var chokidar = require("chokidar");
7+
var chokidar = require("../lib/chokidar");
88
var TestHelper = require("./helpers/TestHelper");
99
var Watchpack = require("../lib/watchpack");
1010

@@ -188,4 +188,37 @@ describe("Assumption", function() {
188188
});
189189
});
190190
});
191+
192+
[1, 10, 20, 50, 100, 200, 300, 400, 500].reverse().forEach(function(delay) {
193+
it("should not fire events after watcher has been closed after " + delay + "ms delay", function(done) {
194+
var watcher = watcherToClose = chokidar.watch(fixtures, {
195+
ignoreInitial: true,
196+
persistent: true,
197+
followSymlinks: false,
198+
depth: 0,
199+
atomic: false,
200+
alwaysStat: true,
201+
ignorePermissionErrors: true
202+
});
203+
watcher.on("add", function(arg) {
204+
done(new Error("should not be emitted " + arg));
205+
done = function() {};
206+
});
207+
watcher.on("change", function(arg) {
208+
done(new Error("should not be emitted " + arg));
209+
done = function() {};
210+
});
211+
watcher.on("error", function(err) {
212+
done(err);
213+
done = function() {};
214+
});
215+
testHelper.tick(delay, function() {
216+
watcher.close();
217+
testHelper.file("watch-test-file-close");
218+
testHelper.tick(500, function() {
219+
done();
220+
});
221+
});
222+
});
223+
});
191224
});

‎yarn.lock

+103-252
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)
Please sign in to comment.