Skip to content

Commit

Permalink
Merge pull request #153 from coreyward/update-chokidar
Browse files Browse the repository at this point in the history
Update chokidar to 3.3.0
  • Loading branch information
sokra committed May 16, 2020
2 parents 88e13a6 + f53f6c7 commit 59a4990
Show file tree
Hide file tree
Showing 9 changed files with 182 additions and 257 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ os:
- linux
- osx
node_js:
- "14"
- "12"
- "10"
- "8"
Expand Down
1 change: 1 addition & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ init:
# what combinations to test
environment:
matrix:
- nodejs_version: 14
- nodejs_version: 12
- nodejs_version: 10
- nodejs_version: 8
Expand Down
1 change: 1 addition & 0 deletions chokidar2/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = require("chokidar");
11 changes: 11 additions & 0 deletions chokidar2/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"name": "chokidar2",
"version": "2.0.0",
"private": true,
"engines": {
"node": "<8.10.0"
},
"dependencies": {
"chokidar": "^2.1.8"
}
}
8 changes: 5 additions & 3 deletions lib/DirectoryWatcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

var EventEmitter = require("events").EventEmitter;
var async = require("neo-async");
var chokidar = require("chokidar");
var chokidar = require("./chokidar");
var fs = require("graceful-fs");
var path = require("path");

Expand Down Expand Up @@ -282,7 +282,8 @@ DirectoryWatcher.prototype.onDirectoryUnlinked = function onDirectoryUnlinked(di
}
};

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

DirectoryWatcher.prototype.doInitialScan = function doInitialScan() {
Expand Down Expand Up @@ -356,7 +357,8 @@ DirectoryWatcher.prototype.getTimes = function() {

DirectoryWatcher.prototype.close = function() {
this.initialScan = false;
this.watcher.close();
var p = this.watcher.close();
if(p && p.catch) p.catch(this.onWatcherError.bind(this));
if(this.nestedWatching) {
Object.keys(this.directories).forEach(function(dir) {
this.directories[dir].close();
Expand Down
22 changes: 22 additions & 0 deletions lib/chokidar.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
var v3Err;
try {
module.exports = require("chokidar");
return;
} catch(e) {
v3Err = e;
}

var v2Err;
try {
module.exports = require("chokidar2");
return;
} catch(e) {
v2Err = e;
}

throw new Error(
"No version of chokidar is available. Tried chokidar@2 and chokidar@3.\n" +
"You could try to manually install any chokidar version.\n" +
"chokidar@3: " + v3Err + "\n" +
"chokidar@2: " + v2Err + "\n"
)
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,11 @@
"rimraf": "^2.6.2",
"should": "^8.3.1"
},
"optionalDependencies": {
"chokidar": "^3.4.0",
"chokidar2": "file:./chokidar2"
},
"dependencies": {
"chokidar": "^2.1.8",
"graceful-fs": "^4.1.2",
"neo-async": "^2.5.0"
}
Expand Down
35 changes: 34 additions & 1 deletion test/Assumption.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
require("should");
var path = require("path");
var fs = require("fs");
var chokidar = require("chokidar");
var chokidar = require("../lib/chokidar");
var TestHelper = require("./helpers/TestHelper");
var Watchpack = require("../lib/watchpack");

Expand Down Expand Up @@ -188,4 +188,37 @@ describe("Assumption", function() {
});
});
});

[1, 10, 20, 50, 100, 200, 300, 400, 500].reverse().forEach(function(delay) {
it("should not fire events after watcher has been closed after " + delay + "ms delay", function(done) {
var watcher = watcherToClose = chokidar.watch(fixtures, {
ignoreInitial: true,
persistent: true,
followSymlinks: false,
depth: 0,
atomic: false,
alwaysStat: true,
ignorePermissionErrors: true
});
watcher.on("add", function(arg) {
done(new Error("should not be emitted " + arg));
done = function() {};
});
watcher.on("change", function(arg) {
done(new Error("should not be emitted " + arg));
done = function() {};
});
watcher.on("error", function(err) {
done(err);
done = function() {};
});
testHelper.tick(delay, function() {
watcher.close();
testHelper.file("watch-test-file-close");
testHelper.tick(500, function() {
done();
});
});
});
});
});
Loading

0 comments on commit 59a4990

Please sign in to comment.