Skip to content

Commit 65f925c

Browse files
committed
replace filewatcher with chokidar
1 parent 65e6bc9 commit 65f925c

File tree

7 files changed

+151
-40
lines changed

7 files changed

+151
-40
lines changed

lib/cfg.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ module.exports = function (main, opts) {
3131
}
3232

3333
var ignoreWatch = ([]).concat(opts && opts['ignore-watch'] || []).concat(c.ignore || []);
34-
ignoreWatch.length && console.log('Ignore watch:', ignoreWatch)
34+
opts.debug && console.log('Ignore watch:', ignoreWatch)
3535
var ignore = ignoreWatch.concat(ignoreWatch.map(resolvePath));
3636
return {
3737
vm: c.vm !== false,

lib/child-require-hook.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ var waitForFile = function(fileName) {
3737

3838
var compile = (code, fileName) => {
3939
var compiledPath = getCompiledPath(code, fileName, compiledDir)
40-
process.send({
40+
process.send && process.send({
4141
compile: fileName,
4242
compiledPath: compiledPath
4343
})

lib/index.js

Lines changed: 39 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
var fork = require('child_process').fork
2-
var filewatcher = require('filewatcher')
2+
var chokidar = require('chokidar')
33
var ipc = require('./ipc')
44
var resolveMain = require('./resolveMain')
55
var compiler = require('./compiler')
@@ -38,22 +38,32 @@ module.exports = function(script, scriptArgs, nodeArgs, opts) {
3838
// Run ./dedupe.js as preload script
3939
if (cfg.dedupe) process.env.NODE_DEV_PRELOAD = __dirname + '/dedupe'
4040

41-
var watcher = filewatcher({
42-
forcePolling: opts.poll,
43-
interval: parseInt(opts.interval),
44-
debounce: parseInt(opts.debounce),
45-
recursive: process.platform !== 'linux'
46-
})
47-
var starting = false
48-
watcher.on('change', restart)
49-
50-
watcher.on('fallback', function(limit) {
51-
log.warn('node-dev ran out of file handles after watching %s files.', limit)
52-
log.warn('Falling back to polling which uses more CPU.')
53-
log.info('Run ulimit -n 10000 to increase the file descriptor limit.')
54-
if (cfg.deps) log.info('... or add `--no-deps` to use less file handles.')
55-
})
41+
// var watcher = filewatcher({
42+
// forcePolling: opts.poll,
43+
// interval: parseInt(opts.interval),
44+
// debounce: parseInt(opts.debounce),
45+
// recursive: process.platform !== 'linux'
46+
// })
47+
48+
function initWatcher () {
49+
var watcher = chokidar.watch([], {
50+
usePolling: opts.poll,
51+
interval: parseInt(opts.interval)
52+
})
53+
watcher.on('change', restart)
5654

55+
watcher.on('fallback', function(limit) {
56+
log.warn('node-dev ran out of file handles after watching %s files.', limit)
57+
log.warn('Falling back to polling which uses more CPU.')
58+
log.info('Run ulimit -n 10000 to increase the file descriptor limit.')
59+
if (cfg.deps) log.info('... or add `--no-deps` to use less file handles.')
60+
})
61+
return watcher
62+
}
63+
var watcher = initWatcher()
64+
65+
var starting = false
66+
5767
// Read for "rs" from command line
5868
if (opts.rs !== false) {
5969
const rl = readline.createInterface({
@@ -72,6 +82,7 @@ module.exports = function(script, scriptArgs, nodeArgs, opts) {
7282
/**
7383
* Run the wrapped script.
7484
*/
85+
var compileReqWatcher
7586
function start() {
7687
console.log(
7788
'Using ts-node version',
@@ -91,7 +102,14 @@ module.exports = function(script, scriptArgs, nodeArgs, opts) {
91102
env: process.env
92103
})
93104
starting = false
94-
var compileReqWatcher = filewatcher({ forcePolling: opts.poll })
105+
//var compileReqWatcher = filewatcher({ forcePolling: opts.poll })
106+
if (compileReqWatcher) {
107+
compileReqWatcher.close()
108+
}
109+
compileReqWatcher = chokidar.watch([], {
110+
usePolling: opts.poll,
111+
interval: parseInt(opts.interval)
112+
})
95113
var currentCompilePath
96114
fs.writeFileSync(compiler.getCompileReqFilePath(), '')
97115
compileReqWatcher.add(compiler.getCompileReqFilePath())
@@ -199,7 +217,10 @@ module.exports = function(script, scriptArgs, nodeArgs, opts) {
199217
return
200218
}
201219
log.debug('Removing all watchers from files')
202-
watcher.removeAll()
220+
//watcher.removeAll()ya
221+
222+
watcher.close()
223+
watcher = initWatcher()
203224
starting = true
204225
if (child) {
205226
log.debug('Child is still running, restart upon exit')

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "ts-node-dev",
3-
"version": "1.0.0-pre.44",
3+
"version": "1.0.0-pre.45",
44
"description": "Compiles your TS app and restarts when files are modified.",
55
"keywords": [
66
"restart",
@@ -43,9 +43,9 @@
4343
"test-docker": "docker run --rm -v ${PWD}:/app mhart/alpine-node:8.7.0 sh -c 'cd app && node ./bin/ts-node-dev --cache-directory .ts-node test/ts/big'"
4444
},
4545
"dependencies": {
46+
"chokidar": "^3.4.0",
4647
"dateformat": "~1.0.4-1.2.3",
4748
"dynamic-dedupe": "^0.3.0",
48-
"filewatcher": "~3.0.0",
4949
"minimist": "^1.1.3",
5050
"mkdirp": "^0.5.1",
5151
"node-notifier": "^5.4.0",

test/ts/dep.js

Lines changed: 0 additions & 3 deletions
This file was deleted.

test/ts/test-script.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ const obj: A = {
66
b: 2
77
}
88

9-
fn(1))
9+
fn(1)
10+
1011
console.log('test', str)
1112

1213

yarn.lock

Lines changed: 106 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,14 @@ ansi-styles@^2.2.1:
7171
version "2.2.1"
7272
resolved "https://registry.yarnpkg.com/ansi-styles/-/ansi-styles-2.2.1.tgz#b432dd3358b634cf75e1e4664368240533c1ddbe"
7373

74+
anymatch@~3.1.1:
75+
version "3.1.1"
76+
resolved "https://registry.yarnpkg.com/anymatch/-/anymatch-3.1.1.tgz#c55ecf02185e2469259399310c173ce31233b142"
77+
integrity sha512-mM8522psRCqzV+6LhomX5wgp25YVibjh8Wj23I5RPkPppSVSjyKD2A2mBJmWGa+KN7f2D6LNh9jkBCeyLktzjg==
78+
dependencies:
79+
normalize-path "^3.0.0"
80+
picomatch "^2.0.4"
81+
7482
append-transform@^0.4.0:
7583
version "0.4.0"
7684
resolved "https://registry.yarnpkg.com/append-transform/-/append-transform-0.4.0.tgz#d76ebf8ca94d276e247a36bad44a4b74ab611991"
@@ -175,6 +183,11 @@ bcrypt-pbkdf@^1.0.0:
175183
dependencies:
176184
tweetnacl "^0.14.3"
177185

186+
binary-extensions@^2.0.0:
187+
version "2.0.0"
188+
resolved "https://registry.yarnpkg.com/binary-extensions/-/binary-extensions-2.0.0.tgz#23c0df14f6a88077f5f986c0d167ec03c3d5537c"
189+
integrity sha512-Phlt0plgpIIBOGTT/ehfFnbNlfsDEiqmzE2KRXoX1bLIlir4X/MR+zSyBEkL05ffWgnRSf/DXv+WrUAVr93/ow==
190+
178191
bl@~0.9.0:
179192
version "0.9.5"
180193
resolved "https://registry.yarnpkg.com/bl/-/bl-0.9.5.tgz#c06b797af085ea00bc527afc8efcf11de2232054"
@@ -212,6 +225,13 @@ braces@^1.8.2:
212225
preserve "^0.2.0"
213226
repeat-element "^1.1.2"
214227

228+
braces@~3.0.2:
229+
version "3.0.2"
230+
resolved "https://registry.yarnpkg.com/braces/-/braces-3.0.2.tgz#3454e1a462ee8d599e236df336cd9ea4f8afe107"
231+
integrity sha512-b8um+L1RzM3WDSzvhm6gIz1yfTbBt6YTlcEKAvsmqCZZFw46z626lVj9j1yEPW33H5H+lBQpZMP1k8l+78Ha0A==
232+
dependencies:
233+
fill-range "^7.0.1"
234+
215235
buffer-from@^1.0.0:
216236
version "1.1.1"
217237
resolved "https://registry.yarnpkg.com/buffer-from/-/buffer-from-1.1.1.tgz#32713bc028f75c02fdb710d7c7bcec1f2c6070ef"
@@ -283,6 +303,21 @@ chalk@^1.0.0, chalk@^1.1.1, chalk@^1.1.3:
283303
strip-ansi "^3.0.0"
284304
supports-color "^2.0.0"
285305

306+
chokidar@^3.4.0:
307+
version "3.4.0"
308+
resolved "https://registry.yarnpkg.com/chokidar/-/chokidar-3.4.0.tgz#b30611423ce376357c765b9b8f904b9fba3c0be8"
309+
integrity sha512-aXAaho2VJtisB/1fg1+3nlLJqGOuewTzQpd/Tz0yTg2R0e4IGtshYvtjowyEumcBv2z+y4+kc75Mz7j5xJskcQ==
310+
dependencies:
311+
anymatch "~3.1.1"
312+
braces "~3.0.2"
313+
glob-parent "~5.1.0"
314+
is-binary-path "~2.1.0"
315+
is-glob "~4.0.1"
316+
normalize-path "~3.0.0"
317+
readdirp "~3.4.0"
318+
optionalDependencies:
319+
fsevents "~2.1.2"
320+
286321
circular-json@^0.3.1:
287322
version "0.3.1"
288323
resolved "https://registry.yarnpkg.com/circular-json/-/circular-json-0.3.1.tgz#be8b36aefccde8b3ca7aa2d6afc07a37242c0d2d"
@@ -444,10 +479,6 @@ dateformat@~1.0.4-1.2.3:
444479
get-stdin "^4.0.1"
445480
meow "^3.3.0"
446481

447-
debounce@^1.0.0:
448-
version "1.0.2"
449-
resolved "https://registry.yarnpkg.com/debounce/-/debounce-1.0.2.tgz#503cc674d8d7f737099664fb75ddbd36b9626dc6"
450-
451482
debug@^2.1.1, debug@^2.1.3, debug@^2.2.0:
452483
version "2.6.8"
453484
resolved "https://registry.yarnpkg.com/debug/-/debug-2.6.8.tgz#e731531ca2ede27d188222427da17821d68ff4fc"
@@ -803,12 +834,6 @@ filename-regex@^2.0.0:
803834
version "2.0.1"
804835
resolved "https://registry.yarnpkg.com/filename-regex/-/filename-regex-2.0.1.tgz#c1c4b9bee3e09725ddb106b75c1e301fe2f18b26"
805836

806-
filewatcher@~3.0.0:
807-
version "3.0.1"
808-
resolved "https://registry.yarnpkg.com/filewatcher/-/filewatcher-3.0.1.tgz#f4a1957355ddaf443ccd78a895f3d55e23c8a034"
809-
dependencies:
810-
debounce "^1.0.0"
811-
812837
fill-range@^2.1.0:
813838
version "2.2.3"
814839
resolved "https://registry.yarnpkg.com/fill-range/-/fill-range-2.2.3.tgz#50b77dfd7e469bc7492470963699fe7a8485a723"
@@ -819,6 +844,13 @@ fill-range@^2.1.0:
819844
repeat-element "^1.1.2"
820845
repeat-string "^1.5.2"
821846

847+
fill-range@^7.0.1:
848+
version "7.0.1"
849+
resolved "https://registry.yarnpkg.com/fill-range/-/fill-range-7.0.1.tgz#1919a6a7c75fe38b2c7c77e5198535da9acdda40"
850+
integrity sha512-qOo9F+dMUmC2Lcb4BbVvnKJxTPjCm+RRpe4gDuGrzkL7mEVl/djYSu2OdQ2Pa302N4oqkSg9ir6jaLWJ2USVpQ==
851+
dependencies:
852+
to-regex-range "^5.0.1"
853+
822854
find-cache-dir@^0.1.1:
823855
version "0.1.1"
824856
resolved "https://registry.yarnpkg.com/find-cache-dir/-/find-cache-dir-0.1.1.tgz#c8defae57c8a52a8a784f9e31c57c742e993a0b9"
@@ -888,6 +920,11 @@ fs.realpath@^1.0.0:
888920
version "1.0.0"
889921
resolved "https://registry.yarnpkg.com/fs.realpath/-/fs.realpath-1.0.0.tgz#1504ad2523158caa40db4a2787cb01411994ea4f"
890922

923+
fsevents@~2.1.2:
924+
version "2.1.3"
925+
resolved "https://registry.yarnpkg.com/fsevents/-/fsevents-2.1.3.tgz#fb738703ae8d2f9fe900c33836ddebee8b97f23e"
926+
integrity sha512-Auw9a4AxqWpa9GUfj370BMPzzyncfBABW8Mab7BGWBYDj4Isgq+cDKtx0i6u9jcX9pQDnswsaaOTgTmA5pEjuQ==
927+
891928
function-bind@^1.0.2:
892929
version "1.1.0"
893930
resolved "https://registry.yarnpkg.com/function-bind/-/function-bind-1.1.0.tgz#16176714c801798e4e8f2cf7f7529467bb4a5771"
@@ -929,6 +966,13 @@ glob-parent@^2.0.0:
929966
dependencies:
930967
is-glob "^2.0.0"
931968

969+
glob-parent@~5.1.0:
970+
version "5.1.1"
971+
resolved "https://registry.yarnpkg.com/glob-parent/-/glob-parent-5.1.1.tgz#b6c1ef417c4e5663ea498f1c45afac6916bbc229"
972+
integrity sha512-FnI+VGOpnlGHWZxthPGR+QhR78fuiK0sNLkHQv+bL9fQi57lNNdquIbna/WrfROrolq8GK5Ek6BiMwqL/voRYQ==
973+
dependencies:
974+
is-glob "^4.0.1"
975+
932976
glob@^5.0.15:
933977
version "5.0.15"
934978
resolved "https://registry.yarnpkg.com/glob/-/glob-5.0.15.tgz#1bc936b9e02f4a603fcc222ecf7633d30b8b93b1"
@@ -1110,6 +1154,13 @@ is-arrayish@^0.2.1:
11101154
version "0.2.1"
11111155
resolved "https://registry.yarnpkg.com/is-arrayish/-/is-arrayish-0.2.1.tgz#77c99840527aa8ecb1a8ba697b80645a7a926a9d"
11121156

1157+
is-binary-path@~2.1.0:
1158+
version "2.1.0"
1159+
resolved "https://registry.yarnpkg.com/is-binary-path/-/is-binary-path-2.1.0.tgz#ea1f7f3b80f064236e83470f86c09c254fb45b09"
1160+
integrity sha512-ZMERYes6pDydyuGidse7OsHxtbI7WVeUEozgR/g7rd0xUimYNlvZRE/K2MgZTjWy725IfelLeVcEM97mmtRGXw==
1161+
dependencies:
1162+
binary-extensions "^2.0.0"
1163+
11131164
is-buffer@^1.1.5:
11141165
version "1.1.5"
11151166
resolved "https://registry.yarnpkg.com/is-buffer/-/is-buffer-1.1.5.tgz#1f3b26ef613b214b88cbca23cc6c01d87961eecc"
@@ -1138,6 +1189,11 @@ is-extglob@^1.0.0:
11381189
version "1.0.0"
11391190
resolved "https://registry.yarnpkg.com/is-extglob/-/is-extglob-1.0.0.tgz#ac468177c4943405a092fc8f29760c6ffc6206c0"
11401191

1192+
is-extglob@^2.1.1:
1193+
version "2.1.1"
1194+
resolved "https://registry.yarnpkg.com/is-extglob/-/is-extglob-2.1.1.tgz#a88c02535791f02ed37c76a1b9ea9773c833f8c2"
1195+
integrity sha1-qIwCU1eR8C7TfHahueqXc8gz+MI=
1196+
11411197
is-finite@^1.0.0:
11421198
version "1.0.2"
11431199
resolved "https://registry.yarnpkg.com/is-finite/-/is-finite-1.0.2.tgz#cc6677695602be550ef11e8b4aa6305342b6d0aa"
@@ -1160,6 +1216,13 @@ is-glob@^2.0.0, is-glob@^2.0.1:
11601216
dependencies:
11611217
is-extglob "^1.0.0"
11621218

1219+
is-glob@^4.0.1, is-glob@~4.0.1:
1220+
version "4.0.1"
1221+
resolved "https://registry.yarnpkg.com/is-glob/-/is-glob-4.0.1.tgz#7567dbe9f2f5e2467bc77ab83c4a29482407a5dc"
1222+
integrity sha512-5G0tKtBTFImOqDnLB2hG6Bp2qcKEFduo4tZu9MT/H6NQv/ghhy30o55ufafxJ/LdH79LLs2Kfrn85TLKyA7BUg==
1223+
dependencies:
1224+
is-extglob "^2.1.1"
1225+
11631226
is-my-json-valid@^2.10.0, is-my-json-valid@^2.12.4:
11641227
version "2.16.0"
11651228
resolved "https://registry.yarnpkg.com/is-my-json-valid/-/is-my-json-valid-2.16.0.tgz#f079dd9bfdae65ee2038aae8acbc86ab109e3693"
@@ -1181,6 +1244,11 @@ is-number@^3.0.0:
11811244
dependencies:
11821245
kind-of "^3.0.2"
11831246

1247+
is-number@^7.0.0:
1248+
version "7.0.0"
1249+
resolved "https://registry.yarnpkg.com/is-number/-/is-number-7.0.0.tgz#7535345b896734d5f80c4d06c50955527a14f12b"
1250+
integrity sha512-41Cifkg6e8TylSpdtTpeLVMqvSBEVzTttHvERD741+pnZ8ANv0004MRL43QKPDlK9cGvNp6NZWZUBlbGXYxxng==
1251+
11841252
is-path-cwd@^1.0.0:
11851253
version "1.0.0"
11861254
resolved "https://registry.yarnpkg.com/is-path-cwd/-/is-path-cwd-1.0.0.tgz#d225ec23132e89edd38fda767472e62e65f1106d"
@@ -1551,6 +1619,11 @@ normalize-path@^2.0.1:
15511619
dependencies:
15521620
remove-trailing-separator "^1.0.1"
15531621

1622+
normalize-path@^3.0.0, normalize-path@~3.0.0:
1623+
version "3.0.0"
1624+
resolved "https://registry.yarnpkg.com/normalize-path/-/normalize-path-3.0.0.tgz#0dcd69ff23a1c9b11fd0978316644a0388216a65"
1625+
integrity sha512-6eZs5Ls3WtCisHWp9S2GUy8dqkpGi4BVSz3GaqiE6ezub0512ESztXUwUB6C6IKbQkY2Pnb/mD4WYojCRwcwLA==
1626+
15541627
number-is-nan@^1.0.0:
15551628
version "1.0.1"
15561629
resolved "https://registry.yarnpkg.com/number-is-nan/-/number-is-nan-1.0.1.tgz#097b602b53422a522c1afb8790318336941a011d"
@@ -1687,6 +1760,11 @@ path-type@^1.0.0:
16871760
pify "^2.0.0"
16881761
pinkie-promise "^2.0.0"
16891762

1763+
picomatch@^2.0.4, picomatch@^2.2.1:
1764+
version "2.2.2"
1765+
resolved "https://registry.yarnpkg.com/picomatch/-/picomatch-2.2.2.tgz#21f333e9b6b8eaff02468f5146ea406d345f4dad"
1766+
integrity sha512-q0M/9eZHzmr0AulXyPwNfZjtwZ/RBZlbN3K3CErVrk50T2ASYI7Bye0EvekFY3IP1Nt2DHu0re+V2ZHIpMkuWg==
1767+
16901768
pify@^2.0.0:
16911769
version "2.3.0"
16921770
resolved "https://registry.yarnpkg.com/pify/-/pify-2.3.0.tgz#ed141a6ac043a849ea588498e7dca8b15330e90c"
@@ -1801,6 +1879,13 @@ readable-stream@~1.0.26:
18011879
isarray "0.0.1"
18021880
string_decoder "~0.10.x"
18031881

1882+
readdirp@~3.4.0:
1883+
version "3.4.0"
1884+
resolved "https://registry.yarnpkg.com/readdirp/-/readdirp-3.4.0.tgz#9fdccdf9e9155805449221ac645e8303ab5b9ada"
1885+
integrity sha512-0xe001vZBnJEK+uKcj8qOhyAKPzIT+gStxWr3LCB0DwcXR5NZJ3IaC+yGnHCYzB/S7ov3m3EEbZI2zeNvX+hGQ==
1886+
dependencies:
1887+
picomatch "^2.2.1"
1888+
18041889
readline2@^1.0.1:
18051890
version "1.0.1"
18061891
resolved "https://registry.yarnpkg.com/readline2/-/readline2-1.0.1.tgz#41059608ffc154757b715d9989d199ffbf372e35"
@@ -2269,6 +2354,13 @@ tmatch@^2.0.1:
22692354
version "2.0.1"
22702355
resolved "https://registry.yarnpkg.com/tmatch/-/tmatch-2.0.1.tgz#0c56246f33f30da1b8d3d72895abaf16660f38cf"
22712356

2357+
to-regex-range@^5.0.1:
2358+
version "5.0.1"
2359+
resolved "https://registry.yarnpkg.com/to-regex-range/-/to-regex-range-5.0.1.tgz#1648c44aae7c8d988a326018ed72f5b4dd0392e4"
2360+
integrity sha512-65P7iz6X5yEr1cwcgvQxbbIw7Uk3gOy5dIdtZ4rDveLqhrdJP+Li/Hx6tyK0NEb+2GCyneCMJiGqrADCSNk8sQ==
2361+
dependencies:
2362+
is-number "^7.0.0"
2363+
22722364
touch@^1.0.0:
22732365
version "1.0.0"
22742366
resolved "https://registry.yarnpkg.com/touch/-/touch-1.0.0.tgz#449cbe2dbae5a8c8038e30d71fa0ff464947c4de"
@@ -2281,10 +2373,10 @@ tough-cookie@>=0.12.0, tough-cookie@~2.3.0:
22812373
dependencies:
22822374
punycode "^1.4.1"
22832375

2284-
tree-kill@^1.2.1:
2285-
version "1.2.1"
2286-
resolved "https://registry.yarnpkg.com/tree-kill/-/tree-kill-1.2.1.tgz#5398f374e2f292b9dcc7b2e71e30a5c3bb6c743a"
2287-
integrity sha512-4hjqbObwlh2dLyW4tcz0Ymw0ggoaVDMveUB9w8kFSQScdRLo0gxO9J7WFcUBo+W3C1TLdFIEwNOWebgZZ0RH9Q==
2376+
tree-kill@^1.2.2:
2377+
version "1.2.2"
2378+
resolved "https://registry.yarnpkg.com/tree-kill/-/tree-kill-1.2.2.tgz#4ca09a9092c88b73a7cdc5e8a01b507b0790a0cc"
2379+
integrity sha512-L0Orpi8qGpRG//Nd+H90vFB+3iHnue1zSSGmNOOCh1GLJ7rUKVwV2HvijphGQS2UmhUZewS9VgvxYIdgr+fG1A==
22882380

22892381
trim-newlines@^1.0.0:
22902382
version "1.0.0"

0 commit comments

Comments
 (0)