Skip to content

Commit 11caedf

Browse files
committedApr 26, 2020
use chokidar 2 or 3 depending on node.js version
1 parent f6d5f77 commit 11caedf

File tree

7 files changed

+1033
-17
lines changed

7 files changed

+1033
-17
lines changed
 

‎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

+3-2
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

@@ -357,7 +357,8 @@ DirectoryWatcher.prototype.getTimes = function() {
357357

358358
DirectoryWatcher.prototype.close = function() {
359359
this.initialScan = false;
360-
this.watcher.close().catch(this.onWatcherError.bind(this));
360+
var p = this.watcher.close();
361+
if(p && p.catch) p.catch(this.onWatcherError.bind(this));
361362
if(this.nestedWatching) {
362363
Object.keys(this.directories).forEach(function(dir) {
363364
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-
"dependencies": {
39+
"optionalDependencies": {
4040
"chokidar": "^3.3.0",
41+
"chokidar2": "file:./chokidar2"
42+
},
43+
"dependencies": {
4144
"graceful-fs": "^4.1.2",
4245
"neo-async": "^2.5.0"
4346
},

‎test/Assumption.js

+1-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

‎yarn.lock

+991-13
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)
Please sign in to comment.