{"size": 847, "ext": "js", "max_stars_repo_path": "node_modules/af-webpack/lib/getUserConfig/watch.js", "max_stars_repo_name": "mybsktb/ant-d", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "node_modules/af-webpack/lib/getUserConfig/watch.js", "max_issues_repo_name": "mybsktb/ant-d", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "node_modules/af-webpack/lib/getUserConfig/watch.js", "max_forks_repo_name": "mybsktb/ant-d", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 20.1666666667, "max_line_length": 85, "alphanum_fraction": 0.6741440378}
"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.watch = watch;
exports.unwatch = unwatch;

var _keys = _interopRequireDefault(require("@babel/runtime/core-js/object/keys"));

var _chokidar = _interopRequireDefault(require("chokidar"));

// 按 key 存，值为数组
var watchers = {};

function watch(key, files) {
  if (!watchers[key]) {
    watchers[key] = [];
  }

  var watcher = _chokidar.default.watch(files, {
    ignoreInitial: true
  });

  watchers[key].push(watcher);
  return watcher;
}

function unwatch(key) {
  if (!key) {
    return (0, _keys.default)(watchers).forEach(unwatch);
  }

  if (watchers[key]) {
    watchers[key].forEach(function (watcher) {
      watcher.close();
    });
    delete watchers[key];
  }
}