source: trip-planner-front/node_modules/watchpack/lib/getWatcherManager.js@ 8d391a1

Last change on this file since 8d391a1 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 1.4 KB
Line 
1/*
2 MIT License http://www.opensource.org/licenses/mit-license.php
3 Author Tobias Koppers @sokra
4*/
5"use strict";
6
7const path = require("path");
8const DirectoryWatcher = require("./DirectoryWatcher");
9
10class WatcherManager {
11 constructor(options) {
12 this.options = options;
13 this.directoryWatchers = new Map();
14 }
15
16 getDirectoryWatcher(directory) {
17 const watcher = this.directoryWatchers.get(directory);
18 if (watcher === undefined) {
19 const newWatcher = new DirectoryWatcher(this, directory, this.options);
20 this.directoryWatchers.set(directory, newWatcher);
21 newWatcher.on("closed", () => {
22 this.directoryWatchers.delete(directory);
23 });
24 return newWatcher;
25 }
26 return watcher;
27 }
28
29 watchFile(p, startTime) {
30 const directory = path.dirname(p);
31 if (directory === p) return null;
32 return this.getDirectoryWatcher(directory).watch(p, startTime);
33 }
34
35 watchDirectory(directory, startTime) {
36 return this.getDirectoryWatcher(directory).watch(directory, startTime);
37 }
38}
39
40const watcherManagers = new WeakMap();
41/**
42 * @param {object} options options
43 * @returns {WatcherManager} the watcher manager
44 */
45module.exports = options => {
46 const watcherManager = watcherManagers.get(options);
47 if (watcherManager !== undefined) return watcherManager;
48 const newWatcherManager = new WatcherManager(options);
49 watcherManagers.set(options, newWatcherManager);
50 return newWatcherManager;
51};
52module.exports.WatcherManager = WatcherManager;
Note: See TracBrowser for help on using the repository browser.