【问题标题】:Node.js issue with ES6 and chokidarES6 和 chokidar 的 Node.js 问题
【发布时间】:2016-12-20 13:53:07
【问题描述】:

我在使用 npm 模块 chokidar 时遇到了一点问题。问题是 watcher.getWatched() 的值返回 null。我是否缺少与 ES6 和此运算符相关的内容?

我有一个入口文件.js

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 类如下

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;

【问题讨论】:

标签: node.js npm ecmascript-6


【解决方案1】:

这个链接很有帮助,我必须等待准备好的事件

https://github.com/paulmillr/chokidar/issues/487

【讨论】:

    猜你喜欢
    • 2018-01-09
    • 2013-10-21
    • 2016-11-29
    • 2016-05-27
    • 1970-01-01
    • 2021-12-28
    • 2013-02-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多