From 1ca23b1980fd458b681e169d36fb56dbbdd7ea40 Mon Sep 17 00:00:00 2001 From: Andy Date: Mon, 2 Jan 2017 14:05:54 -0800 Subject: [PATCH] chokidar: Change event type to `string` (#13572) --- chokidar/chokidar-tests.ts | 30 ++++++++++++++++++------------ chokidar/index.d.ts | 3 ++- 2 files changed, 20 insertions(+), 13 deletions(-) diff --git a/chokidar/chokidar-tests.ts b/chokidar/chokidar-tests.ts index 9ff862789d..a67638e927 100644 --- a/chokidar/chokidar-tests.ts +++ b/chokidar/chokidar-tests.ts @@ -9,20 +9,25 @@ var watcher = chokidar.watch('file, dir, or glob', { var log = console.log.bind(console); +let str: string; +let any: any; +let stats: fs.Stats; + watcher - .on('add', function(path:string) { log('File', path, 'has been added'); }) - .on('addDir', function(path:string) { log('Directory', path, 'has been added'); }) - .on('change', function(path:string) { log('File', path, 'has been changed'); }) - .on('unlink', function(path:string) { log('File', path, 'has been removed'); }) - .on('unlinkDir', function(path:string) { log('Directory', path, 'has been removed'); }) - .on('error', function(error:any) { log('Error happened', error); }) - .on('ready', function() { log('Initial scan complete. Ready for changes.'); }) - .on('raw', function(event:Event, path:string, details:any) { log('Raw event info:', event, path, details); }) + .on('add', path => { str = path; }) + .on('addDir', path => { str = path; }) + .on('change', path => { str = path; }) + .on('unlink', path => { str = path; }) + .on('unlinkDir', path => { str = path; }) + .on('error', (error) => { any = error; }) + .on('ready', () => { }) + .on('raw', (event, path, details) => { str = event; str = path; any = details; }) // 'add', 'addDir' and 'change' events also receive stat() results as second // argument when available: http://nodejs.org/api/fs.html#fs_class_fs_stats -watcher.on('change', function(path:string, stats:fs.Stats) { - if (stats) console.log('File', path, 'changed size to', stats.size); +watcher.on('change', (path, _stats) => { + str = path; + stats = _stats; }); // Watch new files. @@ -36,6 +41,7 @@ watcher.unwatch('new-file*'); watcher.close(); // One-liner -require('chokidar').watch('.', {ignored: /[\/\\]\./}).on('all', function(event:string, path:string) { - console.log(event, path); +chokidar.watch('.', {ignored: /[\/\\]\./}).on('all', (event, path) => { + str = event; + str = path; }); \ No newline at end of file diff --git a/chokidar/index.d.ts b/chokidar/index.d.ts index 2fcfb22eaa..ab37a73948 100644 --- a/chokidar/index.d.ts +++ b/chokidar/index.d.ts @@ -18,7 +18,8 @@ declare module "chokidar" on(event: 'add', fn: (path: string, stats?: fs.Stats) => void): this; on(event: 'change', fn: (path: string, stats?: fs.Stats) => void): this; on(event: 'unlink', fn: (path: string) => void): this; - on(event: 'raw', fn: (event: Event, path:string, details:any) => void): this; + on(event: 'raw', fn: (event: string, path:string, details:any) => void): this; + on(event: 'all', fn: (event: string, path: string) => void): this; on(event: string, fn: (path: string) => void): this; close(): this; }