MCPcopy
hub / github.com/webpack/webpack / watch

Method watch

lib/node/NodeWatchFileSystem.js:36–213  ·  view source on GitHub ↗

@type {WatchMethod}

(
		files,
		directories,
		missing,
		startTime,
		options,
		callback,
		callbackUndelayed
	)

Source from the content-addressed store, hash-verified

34
35 /** @type {WatchMethod} */
36 watch(
37 files,
38 directories,
39 missing,
40 startTime,
41 options,
42 callback,
43 callbackUndelayed
44 ) {
45 if (!files || typeof files[Symbol.iterator] !== "function") {
46 throw new Error("Invalid arguments: 'files'");
47 }
48 if (!directories || typeof directories[Symbol.iterator] !== "function") {
49 throw new Error("Invalid arguments: 'directories'");
50 }
51 if (!missing || typeof missing[Symbol.iterator] !== "function") {
52 throw new Error("Invalid arguments: 'missing'");
53 }
54 if (typeof callback !== "function") {
55 throw new Error("Invalid arguments: 'callback'");
56 }
57 if (typeof startTime !== "number" && startTime) {
58 throw new Error("Invalid arguments: 'startTime'");
59 }
60 if (typeof options !== "object") {
61 throw new Error("Invalid arguments: 'options'");
62 }
63 if (typeof callbackUndelayed !== "function" && callbackUndelayed) {
64 throw new Error("Invalid arguments: 'callbackUndelayed'");
65 }
66 const oldWatcher = this.watcher;
67 this.watcher = new Watchpack(options);
68
69 if (callbackUndelayed) {
70 this.watcher.once("change", callbackUndelayed);
71 }
72
73 const fetchTimeInfo = () => {
74 /** @type {TimeInfoEntries} */
75 const fileTimeInfoEntries = new Map();
76 /** @type {TimeInfoEntries} */
77 const contextTimeInfoEntries = new Map();
78 if (this.watcher) {
79 this.watcher.collectTimeInfoEntries(
80 fileTimeInfoEntries,
81 contextTimeInfoEntries
82 );
83 }
84 return { fileTimeInfoEntries, contextTimeInfoEntries };
85 };
86 const directoriesSet =
87 directories instanceof Set ? directories : new Set(directories);
88
89 // Watchpack reports a watched directory (a context dependency) in
90 // `changes` whenever its contents change, alongside the individual
91 // file events. The default `fs.purge(dir)` matches cache keys by
92 // prefix, so it would wipe the stat cache of every file inside the
93 // directory even though only file-level events actually invalidate

Callers

nothing calls this directly

Calls 2

callbackFunction · 0.50
closeMethod · 0.45

Tested by

no test coverage detected