8000 Fix: Add support for gulp.watch usage w/o opts or callback · gulpjs/gulp@9fc4125 · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Commit 9fc4125

Browse files
jmmphated
authored andcommitted
Fix: Add support for gulp.watch usage w/o opts or callback
1 parent 83f5632 commit 9fc4125

File tree

3 files changed

+13
-5
lines changed

3 files changed

+13
-5
lines changed

docs/API.md

+7-5
Original file line numberDiff line numberDiff line change
@@ -504,7 +504,7 @@ Type: `Array`, `String` or `Function`
504504
A task name, a function or an array of either.
505505

506506

507-
### gulp.watch(glob[, opts], fn)
507+
### gulp.watch(glob[, opts][, fn])
508508

509509
Watch files and do something when a file changes.
510510
File watching is provided by the [`chokidar`][chokidar] module.
@@ -515,7 +515,7 @@ Please report any file watching problems directly to its
515515
gulp.watch('js/**/*.js', gulp.parallel('uglify', 'reload'));
516516
```
517517

518-
In the example, `gulp.watch` runs the function returned by gulp.parallel each
518+
In the example, `gulp.watch` runs the function returned by `gulp.parallel` each
519519
time a file with the `js` extension in `js/` is updated.
520520

521521
#### glob
@@ -548,12 +548,14 @@ Read about the full set of options in [`chokidar`'s README][chokidar].
548548
#### fn
549549
Type: `Function`
550550

551-
An [async](#async-support) function to run when a file changes.
551+
An [async](#async-support) function to run when a file changes. Does not provide
552+
access to the `path` parameter.
552553

553554
`gulp.watch` returns a wrapped [chokidar] FSWatcher object. If provided,
554555
the callback will be triggered upon any `add`, `change`, or `unlink` event.
555556
Listeners can also be set directly for any of [chokidar]'s events, such as
556-
`addDir`, `unlinkDir`, and `error`.
557+
`addDir`, `unlinkDir`, and `error`. You must set listeners directly to get
558+
access to chokidar's callback parameters, such as `path`.
557559

558560
```js
559561
var watcher = gulp.watch('js/**/*.js', gulp.parallel('uglify', 'reload'));
@@ -569,7 +571,7 @@ watcher.on('unlink', function(path) {
569571
##### path
570572
Type: `String`
571573

572-
The relative path of the document.
574+
Path to the file. If `opts.cwd` is set, `path` is relative to it.
573575

574576
##### stats
575577
Type: `Object`

index.js

+2
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ Gulp.prototype.watch = function(glob, opt, task) {
3535
opt = {};
3636
}
3737

38+
opt = opt || {};
39+
3840
var fn;
3941
if (typeof task === 'function') {
4042
fn = this.parallel(task);

test/watch.js

+4
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,10 @@ describe('gulp', function() {
126126
updateTempFile(tempFile);
127127
});
128128

129+
it('should work without options or callback', function() {
130+
gulp.watch('x');
131+
});
132+
129133
it('should run many tasks: w/ options', function(done) {
130134
var tempFile = path.join(outpath, 'watch-task-options.txt');
131135
var a = 0;

0 commit comments

Comments
 (0)
0