Skip to content

Commit 85ff818

Browse files
arvtmcw
authored andcommitted
Fix issue with watch and shallow (#532)
When doing `--shallow --watch` we called `generator` (which synchronously called `updateWatcher`/`addNewFiles`) but the watcher has not been created yet. Instead create the watcher first before `generator` is called. Fixes #531
1 parent b1f288d commit 85ff818

File tree

2 files changed

+20
-12
lines changed

2 files changed

+20
-12
lines changed

lib/commands/build.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,19 +86,19 @@ function build(documentation, parsedArgs, callback) {
8686
}
8787
}
8888

89-
generator();
9089
if (buildOptions.watch) {
9190
var watcher = chokidar.watch(inputs);
9291
watcher.on('all', debounce(generator, 300));
9392
}
93+
generator();
9494

9595
function updateWatcher() {
9696
documentation.expandInputs(inputs, options, addNewFiles);
9797
}
9898

9999
function addNewFiles(err, files) {
100100
watcher.add(files.map(function (data) {
101-
return data.file;
101+
return typeof data === 'string' ? data : data.file;
102102
}));
103103
}
104104
}

test/bin-watch-serve.js

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -73,13 +73,17 @@ test('--watch', options, function (t) {
7373
get('http://localhost:4001/', function (text) {
7474
t.ok(text.match(/apples/), 'sends an html index file');
7575
fs.writeFileSync(tmpFile, '/** a function */function bananas() {}');
76-
setTimeout(function () {
76+
function doGet() {
7777
get('http://localhost:4001/', function (text) {
78-
t.ok(text.match(/bananas/), 'updates the file content');
79-
docProcess.kill();
80-
t.end();
78+
if (text.match(/bananas/)) {
79+
docProcess.kill();
80+
t.end();
81+
} else {
82+
setTimeout(doGet, 100);
83+
}
8184
});
82-
}, 1000);
85+
}
86+
doGet();
8387
});
8488
});
8589
});
@@ -95,13 +99,17 @@ test('--watch', options, function (t) {
9599
get('http://localhost:4001/', function (text) {
96100
t.ok(text.match(/soup/), 'sends an html index file');
97101
fs.writeFileSync(b, '/** nuts */function nuts() {}');
98-
setTimeout(function () {
102+
function doGet() {
99103
get('http://localhost:4001/', function (text) {
100-
t.ok(text.match(/nuts/), 'updates the file content even behind a require');
101-
docProcess.kill();
102-
t.end();
104+
if (text.match(/nuts/)) {
105+
docProcess.kill();
106+
t.end();
107+
} else {
108+
setTimeout(doGet, 100);
109+
}
103110
});
104-
}, 1000);
111+
}
112+
doGet();
105113
});
106114
});
107115
});

0 commit comments

Comments
 (0)