Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update chokidar to 3.3.0 #153

Merged
merged 8 commits into from
May 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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