2016-12-20 4 views
0

npmモジュールのchokidarを使用して、少し問題があります。問題は、watcher.getWatched()の値がnullを返すことです。私はES6とこの演算子に関連する何かを逃していますか?Node.jsのES6とchokidarでの問題

私はエントリが

var chokidar = require('chokidar'); 
var FileSystemObject = require('../file-system-object'); 

class ChokidarWatcher { 
constructor(studentPath) { 
    this.StudentPath = studentPath; 
    this.Watcher = chokidar.watch(this.StudentPath, { 
     // atomic: true, 
     alwaysStat: true, 
     usePolling: true, 
     ignoreInitial: true, 
     ignored: function (path, stat) {     
      if (stat) { 
       var isDir = stat.isDirectory(); 
       var fso = new FileSystemObject(path, stat); 

       if (isDir) { 
        return (fso.name === 'node_modules' && studentPath === fso.dir) || 
         fso.name === 'bower_components' || /[\/\\]\./.test(path) 
       } else { 
        return fso.name === '.DS_Store' 
       } 
      } 

      return false 
     } 
    }); 
} 

GetMyWatcher() { 
    return this.Watcher; 
}; 

GetWatched() { 

    var items = []; 
    var watched = this.Watcher.getWatched(); 
    for (var dirpath in watched) { 
     items.push(new FileSystemObject(dirpath, true)) 

     for (var i = 0; i < watched[dirpath].length; i++) { 
      var name = watched[dirpath][i]; 
      var path = p.join(dirpath, name); 
      if (!watched[path]) { 
       // add file 
       items.push(new FileSystemObject(path, false)) 
      } 
     } 
    }   
    return items 
} 
} 

module.exports = ChokidarWatcher; 
+0

'getWatched' [決して' null'を返すように見える](https://github.com/paulmillr/chokidar/blob/master) /index.js#L682) – Bergi

+0

空の配列を返します。申し訳ありません –

答えて

0

このリンクは参考になりました、次のように

let ChokidarWatcher = require('./services/chokidarWatcher'); 
let FileSystemObject = require('./file-system-object'); 

module.exports = function (server) { 
    let studentPath = 'C:/Student2'; 
    let fswWatcher = new ChokidarWatcher(studentPath);  
    console.log(fswWatcher.GetWatched()); 
}; 

私はChokidarWatcherクラスを持っているfile.js持って、私はreadyイベント

https://github.com/paulmillr/chokidar/issues/487を待たなければなりませんでした

関連する問題