Skip to content

Commit 743381f

Browse files
wclrbjornstar
andauthored
Poll interval (#250)
* add --interval option for polling * add --debounce option Co-authored-by: Bjorn Stromberg <bjorn@bjornstar.com>
1 parent 9f04ac5 commit 743381f

4 files changed

Lines changed: 43 additions & 1 deletion

File tree

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ node-dev src/server.ts
3232
There are a couple of command-line options that can be used to control which files are watched and what happens when they change:
3333

3434
- `--clear` - Clear the screen on restart
35+
- `--debounce` - Debounce change events by time in milliseconds (non-polling mode, default: 10)
3536
- `--dedupe` - [Dedupe dynamically](https://www.npmjs.org/package/dynamic-dedupe)
3637
- `--deps`:
3738
- `-1` - Watch the whole dependency tree
@@ -41,6 +42,7 @@ There are a couple of command-line options that can be used to control which fil
4142
- `--fork` - Hook into child_process.fork
4243
- `--graceful_ipc <msg>` - Send 'msg' as an IPC message instead of SIGTERM for restart/shutdown
4344
- `--ignore` - A file whose changes should not cause a restart
45+
- `--interval` - Polling interval in milliseconds (default: 1000)
4446
- `--notify=false` - Disable desktop notifications
4547
- `--poll` - Force polling for file changes (Caution! CPU-heavy!)
4648
- `--respawn` - Keep watching for changes after the script has exited

lib/cfg.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ const resolveMain = require('./resolve-main');
55

66
const defaultConfig = {
77
clear: false,
8+
debounce: 10,
89
dedupe: false,
910
deps: 1,
1011
extensions: {
@@ -15,6 +16,7 @@ const defaultConfig = {
1516
fork: true,
1617
graceful_ipc: '',
1718
ignore: [],
19+
interval: 1000,
1820
notify: true,
1921
poll: false,
2022
respawn: false,

lib/index.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,12 @@ module.exports = function (
1717
nodeArgs,
1818
{
1919
clear,
20+
debounce,
2021
dedupe,
2122
deps,
2223
graceful_ipc: gracefulIPC,
2324
ignore,
25+
interval,
2426
notify: notifyEnabled,
2527
poll: forcePolling,
2628
respawn,
@@ -57,7 +59,7 @@ module.exports = function (
5759
// Run ./dedupe.js as preload script
5860
if (dedupe) process.env.NODE_DEV_PRELOAD = localPath('dedupe');
5961

60-
const watcher = filewatcher({ forcePolling });
62+
const watcher = filewatcher({ debounce, forcePolling, interval });
6163
let isPaused = false;
6264

6365
// The child_process

test/cli.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,3 +103,39 @@ tap.test('--clear enables clear', t => {
103103
t.true(clear);
104104
t.done();
105105
});
106+
107+
tap.test('interval default', t => {
108+
const {
109+
opts: { interval }
110+
} = cli(['node', 'bin/node-dev', 'test']);
111+
112+
t.is(interval, 1000);
113+
t.done();
114+
});
115+
116+
tap.test('--interval=2000', t => {
117+
const {
118+
opts: { interval }
119+
} = cli(['node', 'bin/node-dev', '--interval=2000', 'test']);
120+
121+
t.is(interval, 2000);
122+
t.done();
123+
});
124+
125+
tap.test('debounce default', t => {
126+
const {
127+
opts: { debounce }
128+
} = cli(['node', 'bin/node-dev', 'test']);
129+
130+
t.is(debounce, 10);
131+
t.done();
132+
});
133+
134+
tap.test('--debounce=2000', t => {
135+
const {
136+
opts: { debounce }
137+
} = cli(['node', 'bin/node-dev', '--debounce=2000', 'test']);
138+
139+
t.is(debounce, 2000);
140+
t.done();
141+
});

0 commit comments

Comments
 (0)