Skip to content

Commit

Permalink
use chokidar 2 or 3 depending on node.js version
Browse files Browse the repository at this point in the history
  • Loading branch information
sokra committed Apr 26, 2020
1 parent f6d5f77 commit 11caedf
Show file tree
Hide file tree
Showing 7 changed files with 1,033 additions and 17 deletions.
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"
}
}
5 changes: 3 additions & 2 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 @@ -357,7 +357,8 @@ DirectoryWatcher.prototype.getTimes = function() {

DirectoryWatcher.prototype.close = function() {
this.initialScan = false;
this.watcher.close().catch(this.onWatcherError.bind(this));
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"
},
"dependencies": {
"optionalDependencies": {
"chokidar": "^3.3.0",
"chokidar2": "file:./chokidar2"
},
"dependencies": {
"graceful-fs": "^4.1.2",
"neo-async": "^2.5.0"
},
Expand Down
2 changes: 1 addition & 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

0 comments on commit 11caedf

Please sign in to comment.