| 
									
										
										
										
											2017-12-31 23:19:18 +08:00
										 |  |  | /* | 
					
						
							|  |  |  | 	MIT License http://www.opensource.org/licenses/mit-license.php
 | 
					
						
							|  |  |  | 	Author Tobias Koppers @sokra | 
					
						
							|  |  |  | */ | 
					
						
							| 
									
										
										
										
											2018-07-30 23:08:51 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-31 23:19:18 +08:00
										 |  |  | "use strict"; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | const Stats = require("./Stats"); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-10 18:34:59 +08:00
										 |  |  | /** @typedef {import("../declarations/WebpackOptions").WatchOptions} WatchOptions */ | 
					
						
							|  |  |  | /** @typedef {import("./Compilation")} Compilation */ | 
					
						
							| 
									
										
										
										
											2018-09-27 13:22:19 +08:00
										 |  |  | /** @typedef {import("./Compiler")} Compiler */ | 
					
						
							| 
									
										
										
										
											2021-07-16 19:05:18 +08:00
										 |  |  | /** @typedef {import("./FileSystemInfo").FileSystemInfoEntry} FileSystemInfoEntry */ | 
					
						
							| 
									
										
										
										
											2023-06-22 05:55:05 +08:00
										 |  |  | /** @typedef {import("./WebpackError")} WebpackError */ | 
					
						
							|  |  |  | /** @typedef {import("./logging/Logger").Logger} Logger */ | 
					
						
							| 
									
										
										
										
											2024-03-14 02:23:33 +08:00
										 |  |  | /** @typedef {import("./util/fs").WatchFileSystem} WatchFileSystem */ | 
					
						
							| 
									
										
										
										
											2018-12-10 18:34:59 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							|  |  |  |  * @template T | 
					
						
							|  |  |  |  * @callback Callback | 
					
						
							| 
									
										
										
										
											2024-02-21 22:05:29 +08:00
										 |  |  |  * @param {Error | null} err | 
					
						
							| 
									
										
										
										
											2018-12-10 18:34:59 +08:00
										 |  |  |  * @param {T=} result | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2018-09-27 13:22:19 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-31 23:19:18 +08:00
										 |  |  | class Watching { | 
					
						
							| 
									
										
										
										
											2018-09-27 13:22:19 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {Compiler} compiler the compiler | 
					
						
							| 
									
										
										
										
											2018-12-10 18:34:59 +08:00
										 |  |  | 	 * @param {WatchOptions} watchOptions options | 
					
						
							|  |  |  | 	 * @param {Callback<Stats>} handler completion handler | 
					
						
							| 
									
										
										
										
											2018-09-27 13:22:19 +08:00
										 |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2017-12-31 23:19:18 +08:00
										 |  |  | 	constructor(compiler, watchOptions, handler) { | 
					
						
							|  |  |  | 		this.startTime = null; | 
					
						
							|  |  |  | 		this.invalid = false; | 
					
						
							|  |  |  | 		this.handler = handler; | 
					
						
							| 
									
										
										
										
											2018-12-10 18:34:59 +08:00
										 |  |  | 		/** @type {Callback<void>[]} */ | 
					
						
							| 
									
										
										
										
											2017-12-31 23:19:18 +08:00
										 |  |  | 		this.callbacks = []; | 
					
						
							| 
									
										
										
										
											2020-07-15 20:48:40 +08:00
										 |  |  | 		/** @type {Callback<void>[] | undefined} */ | 
					
						
							|  |  |  | 		this._closeCallbacks = undefined; | 
					
						
							| 
									
										
										
										
											2017-12-31 23:19:18 +08:00
										 |  |  | 		this.closed = false; | 
					
						
							| 
									
										
										
										
											2019-06-01 00:53:33 +08:00
										 |  |  | 		this.suspended = false; | 
					
						
							| 
									
										
										
										
											2021-02-14 02:53:50 +08:00
										 |  |  | 		this.blocked = false; | 
					
						
							|  |  |  | 		this._isBlocked = () => false; | 
					
						
							|  |  |  | 		this._onChange = () => {}; | 
					
						
							|  |  |  | 		this._onInvalid = () => {}; | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		if (typeof watchOptions === "number") { | 
					
						
							| 
									
										
										
										
											2017-12-31 23:19:18 +08:00
										 |  |  | 			this.watchOptions = { | 
					
						
							|  |  |  | 				aggregateTimeout: watchOptions | 
					
						
							|  |  |  | 			}; | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		} else if (watchOptions && typeof watchOptions === "object") { | 
					
						
							| 
									
										
										
										
											2019-06-19 19:16:05 +08:00
										 |  |  | 			this.watchOptions = { ...watchOptions }; | 
					
						
							| 
									
										
										
										
											2017-12-31 23:19:18 +08:00
										 |  |  | 		} else { | 
					
						
							|  |  |  | 			this.watchOptions = {}; | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2019-12-12 23:33:43 +08:00
										 |  |  | 		if (typeof this.watchOptions.aggregateTimeout !== "number") { | 
					
						
							| 
									
										
										
										
											2021-12-23 05:42:57 +08:00
										 |  |  | 			this.watchOptions.aggregateTimeout = 20; | 
					
						
							| 
									
										
										
										
											2019-12-12 23:33:43 +08:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2017-12-31 23:19:18 +08:00
										 |  |  | 		this.compiler = compiler; | 
					
						
							| 
									
										
										
										
											2021-02-14 02:53:50 +08:00
										 |  |  | 		this.running = false; | 
					
						
							|  |  |  | 		this._initial = true; | 
					
						
							| 
									
										
										
										
											2021-04-09 23:51:58 +08:00
										 |  |  | 		this._invalidReported = true; | 
					
						
							| 
									
										
										
										
											2021-02-14 02:53:50 +08:00
										 |  |  | 		this._needRecords = true; | 
					
						
							| 
									
										
										
										
											2019-10-21 21:35:38 +08:00
										 |  |  | 		this.watcher = undefined; | 
					
						
							|  |  |  | 		this.pausedWatcher = undefined; | 
					
						
							| 
									
										
										
										
											2023-06-22 05:55:05 +08:00
										 |  |  | 		/** @type {Set<string> | undefined} */ | 
					
						
							| 
									
										
										
										
											2021-05-18 19:31:02 +08:00
										 |  |  | 		this._collectedChangedFiles = undefined; | 
					
						
							| 
									
										
										
										
											2023-06-22 05:55:05 +08:00
										 |  |  | 		/** @type {Set<string> | undefined} */ | 
					
						
							| 
									
										
										
										
											2021-05-18 19:31:02 +08:00
										 |  |  | 		this._collectedRemovedFiles = undefined; | 
					
						
							| 
									
										
										
										
											2019-10-21 21:35:38 +08:00
										 |  |  | 		this._done = this._done.bind(this); | 
					
						
							| 
									
										
										
										
											2021-02-14 02:53:50 +08:00
										 |  |  | 		process.nextTick(() => { | 
					
						
							|  |  |  | 			if (this._initial) this._invalidate(); | 
					
						
							| 
									
										
										
										
											2017-12-31 23:19:18 +08:00
										 |  |  | 		}); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-16 19:05:18 +08:00
										 |  |  | 	/** | 
					
						
							| 
									
										
										
										
											2023-06-22 05:55:05 +08:00
										 |  |  | 	 * @param {ReadonlySet<string>=} changedFiles changed files | 
					
						
							|  |  |  | 	 * @param {ReadonlySet<string>=} removedFiles removed files | 
					
						
							| 
									
										
										
										
											2021-07-16 19:05:18 +08:00
										 |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2021-05-18 19:31:02 +08:00
										 |  |  | 	_mergeWithCollected(changedFiles, removedFiles) { | 
					
						
							|  |  |  | 		if (!changedFiles) return; | 
					
						
							|  |  |  | 		if (!this._collectedChangedFiles) { | 
					
						
							|  |  |  | 			this._collectedChangedFiles = new Set(changedFiles); | 
					
						
							|  |  |  | 			this._collectedRemovedFiles = new Set(removedFiles); | 
					
						
							|  |  |  | 		} else { | 
					
						
							|  |  |  | 			for (const file of changedFiles) { | 
					
						
							|  |  |  | 				this._collectedChangedFiles.add(file); | 
					
						
							| 
									
										
										
										
											2023-06-22 05:55:05 +08:00
										 |  |  | 				/** @type {Set<string>} */ | 
					
						
							|  |  |  | 				(this._collectedRemovedFiles).delete(file); | 
					
						
							| 
									
										
										
										
											2021-05-18 19:31:02 +08:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2023-06-22 05:55:05 +08:00
										 |  |  | 			for (const file of /** @type {ReadonlySet<string>} */ (removedFiles)) { | 
					
						
							| 
									
										
										
										
											2021-05-18 19:31:02 +08:00
										 |  |  | 				this._collectedChangedFiles.delete(file); | 
					
						
							| 
									
										
										
										
											2023-06-22 05:55:05 +08:00
										 |  |  | 				/** @type {Set<string>} */ | 
					
						
							|  |  |  | 				(this._collectedRemovedFiles).add(file); | 
					
						
							| 
									
										
										
										
											2021-05-18 19:31:02 +08:00
										 |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-16 19:05:18 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {ReadonlyMap<string, FileSystemInfoEntry | "ignore">=} fileTimeInfoEntries info for files | 
					
						
							|  |  |  | 	 * @param {ReadonlyMap<string, FileSystemInfoEntry | "ignore">=} contextTimeInfoEntries info for directories | 
					
						
							|  |  |  | 	 * @param {ReadonlySet<string>=} changedFiles changed files | 
					
						
							|  |  |  | 	 * @param {ReadonlySet<string>=} removedFiles removed files | 
					
						
							|  |  |  | 	 * @returns {void} | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2021-05-18 19:31:02 +08:00
										 |  |  | 	_go(fileTimeInfoEntries, contextTimeInfoEntries, changedFiles, removedFiles) { | 
					
						
							| 
									
										
										
										
											2021-02-14 02:53:50 +08:00
										 |  |  | 		this._initial = false; | 
					
						
							| 
									
										
										
										
											2021-06-28 17:35:14 +08:00
										 |  |  | 		if (this.startTime === null) this.startTime = Date.now(); | 
					
						
							| 
									
										
										
										
											2017-12-31 23:19:18 +08:00
										 |  |  | 		this.running = true; | 
					
						
							| 
									
										
										
										
											2021-05-18 19:31:02 +08:00
										 |  |  | 		if (this.watcher) { | 
					
						
							|  |  |  | 			this.pausedWatcher = this.watcher; | 
					
						
							| 
									
										
										
										
											2021-05-19 22:18:37 +08:00
										 |  |  | 			this.lastWatcherStartTime = Date.now(); | 
					
						
							| 
									
										
										
										
											2021-05-18 19:31:02 +08:00
										 |  |  | 			this.watcher.pause(); | 
					
						
							|  |  |  | 			this.watcher = null; | 
					
						
							| 
									
										
										
										
											2021-05-19 22:18:37 +08:00
										 |  |  | 		} else if (!this.lastWatcherStartTime) { | 
					
						
							|  |  |  | 			this.lastWatcherStartTime = Date.now(); | 
					
						
							| 
									
										
										
										
											2021-05-18 19:31:02 +08:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2021-05-19 22:18:37 +08:00
										 |  |  | 		this.compiler.fsStartTime = Date.now(); | 
					
						
							| 
									
										
										
										
											2021-11-25 16:27:04 +08:00
										 |  |  | 		if ( | 
					
						
							|  |  |  | 			changedFiles && | 
					
						
							|  |  |  | 			removedFiles && | 
					
						
							|  |  |  | 			fileTimeInfoEntries && | 
					
						
							|  |  |  | 			contextTimeInfoEntries | 
					
						
							|  |  |  | 		) { | 
					
						
							|  |  |  | 			this._mergeWithCollected(changedFiles, removedFiles); | 
					
						
							|  |  |  | 			this.compiler.fileTimestamps = fileTimeInfoEntries; | 
					
						
							|  |  |  | 			this.compiler.contextTimestamps = contextTimeInfoEntries; | 
					
						
							|  |  |  | 		} else if (this.pausedWatcher) { | 
					
						
							|  |  |  | 			if (this.pausedWatcher.getInfo) { | 
					
						
							|  |  |  | 				const { | 
					
						
							|  |  |  | 					changes, | 
					
						
							|  |  |  | 					removals, | 
					
						
							|  |  |  | 					fileTimeInfoEntries, | 
					
						
							|  |  |  | 					contextTimeInfoEntries | 
					
						
							|  |  |  | 				} = this.pausedWatcher.getInfo(); | 
					
						
							|  |  |  | 				this._mergeWithCollected(changes, removals); | 
					
						
							|  |  |  | 				this.compiler.fileTimestamps = fileTimeInfoEntries; | 
					
						
							|  |  |  | 				this.compiler.contextTimestamps = contextTimeInfoEntries; | 
					
						
							|  |  |  | 			} else { | 
					
						
							|  |  |  | 				this._mergeWithCollected( | 
					
						
							| 
									
										
										
										
											2021-05-18 19:31:02 +08:00
										 |  |  | 					this.pausedWatcher.getAggregatedChanges && | 
					
						
							| 
									
										
										
										
											2021-11-25 16:27:04 +08:00
										 |  |  | 						this.pausedWatcher.getAggregatedChanges(), | 
					
						
							| 
									
										
										
										
											2021-05-18 19:31:02 +08:00
										 |  |  | 					this.pausedWatcher.getAggregatedRemovals && | 
					
						
							| 
									
										
										
										
											2021-11-25 16:27:04 +08:00
										 |  |  | 						this.pausedWatcher.getAggregatedRemovals() | 
					
						
							|  |  |  | 				); | 
					
						
							|  |  |  | 				this.compiler.fileTimestamps = | 
					
						
							|  |  |  | 					this.pausedWatcher.getFileTimeInfoEntries(); | 
					
						
							|  |  |  | 				this.compiler.contextTimestamps = | 
					
						
							|  |  |  | 					this.pausedWatcher.getContextTimeInfoEntries(); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2021-05-19 22:18:37 +08:00
										 |  |  | 		this.compiler.modifiedFiles = this._collectedChangedFiles; | 
					
						
							|  |  |  | 		this._collectedChangedFiles = undefined; | 
					
						
							|  |  |  | 		this.compiler.removedFiles = this._collectedRemovedFiles; | 
					
						
							|  |  |  | 		this._collectedRemovedFiles = undefined; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-31 23:38:33 +08:00
										 |  |  | 		const run = () => { | 
					
						
							| 
									
										
										
										
											2021-02-14 02:53:50 +08:00
										 |  |  | 			if (this.compiler.idle) { | 
					
						
							|  |  |  | 				return this.compiler.cache.endIdle(err => { | 
					
						
							|  |  |  | 					if (err) return this._done(err); | 
					
						
							|  |  |  | 					this.compiler.idle = false; | 
					
						
							|  |  |  | 					run(); | 
					
						
							|  |  |  | 				}); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			if (this._needRecords) { | 
					
						
							|  |  |  | 				return this.compiler.readRecords(err => { | 
					
						
							|  |  |  | 					if (err) return this._done(err); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 					this._needRecords = false; | 
					
						
							|  |  |  | 					run(); | 
					
						
							|  |  |  | 				}); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			this.invalid = false; | 
					
						
							| 
									
										
										
										
											2021-04-09 23:51:58 +08:00
										 |  |  | 			this._invalidReported = false; | 
					
						
							| 
									
										
										
										
											2018-09-27 13:22:19 +08:00
										 |  |  | 			this.compiler.hooks.watchRun.callAsync(this.compiler, err => { | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 				if (err) return this._done(err); | 
					
						
							| 
									
										
										
										
											2024-02-21 22:05:29 +08:00
										 |  |  | 				/** | 
					
						
							|  |  |  | 				 * @param {Error | null} err error | 
					
						
							|  |  |  | 				 * @param {Compilation=} _compilation compilation | 
					
						
							|  |  |  | 				 * @returns {void} | 
					
						
							|  |  |  | 				 */ | 
					
						
							|  |  |  | 				const onCompiled = (err, _compilation) => { | 
					
						
							|  |  |  | 					if (err) return this._done(err, _compilation); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 					const compilation = /** @type {Compilation} */ (_compilation); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-14 02:53:50 +08:00
										 |  |  | 					if (this.invalid) return this._done(null, compilation); | 
					
						
							| 
									
										
										
										
											2017-12-31 23:19:18 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-27 13:22:19 +08:00
										 |  |  | 					if (this.compiler.hooks.shouldEmit.call(compilation) === false) { | 
					
						
							|  |  |  | 						return this._done(null, compilation); | 
					
						
							|  |  |  | 					} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-05 20:49:42 +08:00
										 |  |  | 					process.nextTick(() => { | 
					
						
							| 
									
										
										
										
											2019-07-26 19:44:28 +08:00
										 |  |  | 						const logger = compilation.getLogger("webpack.Compiler"); | 
					
						
							| 
									
										
										
										
											2019-07-26 17:09:14 +08:00
										 |  |  | 						logger.time("emitAssets"); | 
					
						
							| 
									
										
										
										
											2019-01-05 20:49:42 +08:00
										 |  |  | 						this.compiler.emitAssets(compilation, err => { | 
					
						
							| 
									
										
										
										
											2019-07-26 17:09:14 +08:00
										 |  |  | 							logger.timeEnd("emitAssets"); | 
					
						
							| 
									
										
										
										
											2020-07-31 23:38:33 +08:00
										 |  |  | 							if (err) return this._done(err, compilation); | 
					
						
							|  |  |  | 							if (this.invalid) return this._done(null, compilation); | 
					
						
							| 
									
										
										
										
											2017-12-31 23:19:18 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-07-26 17:09:14 +08:00
										 |  |  | 							logger.time("emitRecords"); | 
					
						
							| 
									
										
										
										
											2019-01-05 20:49:42 +08:00
										 |  |  | 							this.compiler.emitRecords(err => { | 
					
						
							| 
									
										
										
										
											2019-07-26 17:09:14 +08:00
										 |  |  | 								logger.timeEnd("emitRecords"); | 
					
						
							| 
									
										
										
										
											2020-07-31 23:38:33 +08:00
										 |  |  | 								if (err) return this._done(err, compilation); | 
					
						
							| 
									
										
										
										
											2018-01-25 20:56:50 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-05 20:49:42 +08:00
										 |  |  | 								if (compilation.hooks.needAdditionalPass.call()) { | 
					
						
							|  |  |  | 									compilation.needAdditionalPass = true; | 
					
						
							| 
									
										
										
										
											2018-09-27 13:22:19 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-03-14 02:23:33 +08:00
										 |  |  | 									compilation.startTime = /** @type {number} */ ( | 
					
						
							|  |  |  | 										this.startTime | 
					
						
							|  |  |  | 									); | 
					
						
							| 
									
										
										
										
											2020-09-04 04:01:25 +08:00
										 |  |  | 									compilation.endTime = Date.now(); | 
					
						
							| 
									
										
										
										
											2019-07-26 17:09:14 +08:00
										 |  |  | 									logger.time("done hook"); | 
					
						
							| 
									
										
										
										
											2020-09-04 04:01:25 +08:00
										 |  |  | 									const stats = new Stats(compilation); | 
					
						
							| 
									
										
										
										
											2019-01-05 20:49:42 +08:00
										 |  |  | 									this.compiler.hooks.done.callAsync(stats, err => { | 
					
						
							| 
									
										
										
										
											2019-12-28 22:15:06 +08:00
										 |  |  | 										logger.timeEnd("done hook"); | 
					
						
							| 
									
										
										
										
											2020-07-31 23:38:33 +08:00
										 |  |  | 										if (err) return this._done(err, compilation); | 
					
						
							| 
									
										
										
										
											2019-01-05 20:49:42 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 										this.compiler.hooks.additionalPass.callAsync(err => { | 
					
						
							| 
									
										
										
										
											2020-07-31 23:38:33 +08:00
										 |  |  | 											if (err) return this._done(err, compilation); | 
					
						
							| 
									
										
										
										
											2019-01-05 20:49:42 +08:00
										 |  |  | 											this.compiler.compile(onCompiled); | 
					
						
							|  |  |  | 										}); | 
					
						
							| 
									
										
										
										
											2018-09-27 13:22:19 +08:00
										 |  |  | 									}); | 
					
						
							| 
									
										
										
										
											2019-01-05 20:49:42 +08:00
										 |  |  | 									return; | 
					
						
							|  |  |  | 								} | 
					
						
							|  |  |  | 								return this._done(null, compilation); | 
					
						
							|  |  |  | 							}); | 
					
						
							| 
									
										
										
										
											2018-09-27 13:22:19 +08:00
										 |  |  | 						}); | 
					
						
							| 
									
										
										
										
											2017-12-31 23:19:18 +08:00
										 |  |  | 					}); | 
					
						
							| 
									
										
										
										
											2018-09-27 13:22:19 +08:00
										 |  |  | 				}; | 
					
						
							|  |  |  | 				this.compiler.compile(onCompiled); | 
					
						
							|  |  |  | 			}); | 
					
						
							| 
									
										
										
										
											2020-07-31 23:38:33 +08:00
										 |  |  | 		}; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-14 02:53:50 +08:00
										 |  |  | 		run(); | 
					
						
							| 
									
										
										
										
											2017-12-31 23:19:18 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-10 18:34:59 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {Compilation} compilation the compilation | 
					
						
							|  |  |  | 	 * @returns {Stats} the compilation stats | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2017-12-31 23:19:18 +08:00
										 |  |  | 	_getStats(compilation) { | 
					
						
							|  |  |  | 		const stats = new Stats(compilation); | 
					
						
							|  |  |  | 		return stats; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-10 18:34:59 +08:00
										 |  |  | 	/** | 
					
						
							| 
									
										
										
										
											2023-06-22 05:55:05 +08:00
										 |  |  | 	 * @param {(Error | null)=} err an optional error | 
					
						
							| 
									
										
										
										
											2018-12-10 18:34:59 +08:00
										 |  |  | 	 * @param {Compilation=} compilation the compilation | 
					
						
							|  |  |  | 	 * @returns {void} | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2017-12-31 23:19:18 +08:00
										 |  |  | 	_done(err, compilation) { | 
					
						
							|  |  |  | 		this.running = false; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-03-14 02:23:33 +08:00
										 |  |  | 		const logger = | 
					
						
							|  |  |  | 			/** @type {Logger} */ | 
					
						
							|  |  |  | 			(compilation && compilation.getLogger("webpack.Watching")); | 
					
						
							| 
									
										
										
										
											2020-07-31 23:38:33 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-03-14 02:23:33 +08:00
										 |  |  | 		/** @type {Stats | undefined} */ | 
					
						
							|  |  |  | 		let stats = undefined; | 
					
						
							| 
									
										
										
										
											2020-07-31 23:38:33 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-06-22 05:55:05 +08:00
										 |  |  | 		/** | 
					
						
							|  |  |  | 		 * @param {Error} err error | 
					
						
							|  |  |  | 		 * @param {Callback<void>[]=} cbs callbacks | 
					
						
							|  |  |  | 		 */ | 
					
						
							| 
									
										
										
										
											2021-05-17 19:49:43 +08:00
										 |  |  | 		const handleError = (err, cbs) => { | 
					
						
							| 
									
										
										
										
											2017-12-31 23:19:18 +08:00
										 |  |  | 			this.compiler.hooks.failed.call(err); | 
					
						
							| 
									
										
										
										
											2018-09-27 13:22:19 +08:00
										 |  |  | 			this.compiler.cache.beginIdle(); | 
					
						
							| 
									
										
										
										
											2020-07-31 23:38:33 +08:00
										 |  |  | 			this.compiler.idle = true; | 
					
						
							| 
									
										
										
										
											2023-06-22 05:55:05 +08:00
										 |  |  | 			this.handler(err, /** @type {Stats} */ (stats)); | 
					
						
							| 
									
										
										
										
											2021-05-17 19:49:43 +08:00
										 |  |  | 			if (!cbs) { | 
					
						
							|  |  |  | 				cbs = this.callbacks; | 
					
						
							|  |  |  | 				this.callbacks = []; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			for (const cb of cbs) cb(err); | 
					
						
							| 
									
										
										
										
											2020-07-31 23:38:33 +08:00
										 |  |  | 		}; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-14 02:53:50 +08:00
										 |  |  | 		if ( | 
					
						
							|  |  |  | 			this.invalid && | 
					
						
							|  |  |  | 			!this.suspended && | 
					
						
							|  |  |  | 			!this.blocked && | 
					
						
							|  |  |  | 			!(this._isBlocked() && (this.blocked = true)) | 
					
						
							|  |  |  | 		) { | 
					
						
							| 
									
										
										
										
											2020-07-31 23:38:33 +08:00
										 |  |  | 			if (compilation) { | 
					
						
							| 
									
										
										
										
											2024-03-14 02:23:33 +08:00
										 |  |  | 				logger.time("storeBuildDependencies"); | 
					
						
							| 
									
										
										
										
											2020-07-31 23:38:33 +08:00
										 |  |  | 				this.compiler.cache.storeBuildDependencies( | 
					
						
							|  |  |  | 					compilation.buildDependencies, | 
					
						
							|  |  |  | 					err => { | 
					
						
							| 
									
										
										
										
											2024-03-14 02:23:33 +08:00
										 |  |  | 						logger.timeEnd("storeBuildDependencies"); | 
					
						
							| 
									
										
										
										
											2020-07-31 23:38:33 +08:00
										 |  |  | 						if (err) return handleError(err); | 
					
						
							|  |  |  | 						this._go(); | 
					
						
							|  |  |  | 					} | 
					
						
							|  |  |  | 				); | 
					
						
							|  |  |  | 			} else { | 
					
						
							|  |  |  | 				this._go(); | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2017-12-31 23:19:18 +08:00
										 |  |  | 			return; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-04 04:01:25 +08:00
										 |  |  | 		if (compilation) { | 
					
						
							| 
									
										
										
										
											2024-03-14 02:23:33 +08:00
										 |  |  | 			compilation.startTime = /** @type {number} */ (this.startTime); | 
					
						
							| 
									
										
										
										
											2020-09-04 04:01:25 +08:00
										 |  |  | 			compilation.endTime = Date.now(); | 
					
						
							|  |  |  | 			stats = new Stats(compilation); | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2021-06-28 17:35:14 +08:00
										 |  |  | 		this.startTime = null; | 
					
						
							| 
									
										
										
										
											2020-07-31 23:38:33 +08:00
										 |  |  | 		if (err) return handleError(err); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-05-17 19:49:43 +08:00
										 |  |  | 		const cbs = this.callbacks; | 
					
						
							|  |  |  | 		this.callbacks = []; | 
					
						
							| 
									
										
										
										
											2024-03-14 02:23:33 +08:00
										 |  |  | 		logger.time("done hook"); | 
					
						
							| 
									
										
										
										
											2023-06-22 05:55:05 +08:00
										 |  |  | 		this.compiler.hooks.done.callAsync(/** @type {Stats} */ (stats), err => { | 
					
						
							| 
									
										
										
										
											2024-03-14 02:23:33 +08:00
										 |  |  | 			logger.timeEnd("done hook"); | 
					
						
							| 
									
										
										
										
											2021-05-17 19:49:43 +08:00
										 |  |  | 			if (err) return handleError(err, cbs); | 
					
						
							| 
									
										
										
										
											2024-03-14 02:23:33 +08:00
										 |  |  | 			this.handler(null, stats); | 
					
						
							|  |  |  | 			logger.time("storeBuildDependencies"); | 
					
						
							| 
									
										
										
										
											2020-07-31 23:38:33 +08:00
										 |  |  | 			this.compiler.cache.storeBuildDependencies( | 
					
						
							| 
									
										
										
										
											2023-06-22 05:55:05 +08:00
										 |  |  | 				/** @type {Compilation} */ | 
					
						
							|  |  |  | 				(compilation).buildDependencies, | 
					
						
							| 
									
										
										
										
											2020-07-31 23:38:33 +08:00
										 |  |  | 				err => { | 
					
						
							| 
									
										
										
										
											2024-03-14 02:23:33 +08:00
										 |  |  | 					logger.timeEnd("storeBuildDependencies"); | 
					
						
							| 
									
										
										
										
											2021-05-17 19:49:43 +08:00
										 |  |  | 					if (err) return handleError(err, cbs); | 
					
						
							| 
									
										
										
										
											2024-03-14 02:23:33 +08:00
										 |  |  | 					logger.time("beginIdle"); | 
					
						
							| 
									
										
										
										
											2020-07-31 23:38:33 +08:00
										 |  |  | 					this.compiler.cache.beginIdle(); | 
					
						
							|  |  |  | 					this.compiler.idle = true; | 
					
						
							| 
									
										
										
										
											2024-03-14 02:23:33 +08:00
										 |  |  | 					logger.timeEnd("beginIdle"); | 
					
						
							| 
									
										
										
										
											2020-07-31 23:38:33 +08:00
										 |  |  | 					process.nextTick(() => { | 
					
						
							|  |  |  | 						if (!this.closed) { | 
					
						
							|  |  |  | 							this.watch( | 
					
						
							| 
									
										
										
										
											2023-06-22 05:55:05 +08:00
										 |  |  | 								/** @type {Compilation} */ | 
					
						
							|  |  |  | 								(compilation).fileDependencies, | 
					
						
							|  |  |  | 								/** @type {Compilation} */ | 
					
						
							|  |  |  | 								(compilation).contextDependencies, | 
					
						
							|  |  |  | 								/** @type {Compilation} */ | 
					
						
							|  |  |  | 								(compilation).missingDependencies | 
					
						
							| 
									
										
										
										
											2020-07-31 23:38:33 +08:00
										 |  |  | 							); | 
					
						
							|  |  |  | 						} | 
					
						
							|  |  |  | 					}); | 
					
						
							| 
									
										
										
										
											2021-05-17 19:49:43 +08:00
										 |  |  | 					for (const cb of cbs) cb(null); | 
					
						
							| 
									
										
										
										
											2023-06-22 05:55:05 +08:00
										 |  |  | 					this.compiler.hooks.afterDone.call(/** @type {Stats} */ (stats)); | 
					
						
							| 
									
										
										
										
											2019-01-05 20:49:42 +08:00
										 |  |  | 				} | 
					
						
							| 
									
										
										
										
											2020-07-31 23:38:33 +08:00
										 |  |  | 			); | 
					
						
							| 
									
										
										
										
											2018-01-25 20:56:50 +08:00
										 |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2017-12-31 23:19:18 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-21 21:35:38 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {Iterable<string>} files watched files | 
					
						
							|  |  |  | 	 * @param {Iterable<string>} dirs watched directories | 
					
						
							| 
									
										
										
										
											2020-03-10 09:59:46 +08:00
										 |  |  | 	 * @param {Iterable<string>} missing watched existence entries | 
					
						
							| 
									
										
										
										
											2019-10-21 21:35:38 +08:00
										 |  |  | 	 * @returns {void} | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2017-12-31 23:19:18 +08:00
										 |  |  | 	watch(files, dirs, missing) { | 
					
						
							|  |  |  | 		this.pausedWatcher = null; | 
					
						
							| 
									
										
										
										
											2024-03-14 02:23:33 +08:00
										 |  |  | 		this.watcher = | 
					
						
							|  |  |  | 			/** @type {WatchFileSystem} */ | 
					
						
							|  |  |  | 			(this.compiler.watchFileSystem).watch( | 
					
						
							|  |  |  | 				files, | 
					
						
							|  |  |  | 				dirs, | 
					
						
							|  |  |  | 				missing, | 
					
						
							|  |  |  | 				/** @type {number} */ (this.lastWatcherStartTime), | 
					
						
							|  |  |  | 				this.watchOptions, | 
					
						
							|  |  |  | 				( | 
					
						
							|  |  |  | 					err, | 
					
						
							| 
									
										
										
										
											2021-05-18 19:31:02 +08:00
										 |  |  | 					fileTimeInfoEntries, | 
					
						
							|  |  |  | 					contextTimeInfoEntries, | 
					
						
							|  |  |  | 					changedFiles, | 
					
						
							|  |  |  | 					removedFiles | 
					
						
							| 
									
										
										
										
											2024-03-14 02:23:33 +08:00
										 |  |  | 				) => { | 
					
						
							|  |  |  | 					if (err) { | 
					
						
							|  |  |  | 						this.compiler.modifiedFiles = undefined; | 
					
						
							|  |  |  | 						this.compiler.removedFiles = undefined; | 
					
						
							|  |  |  | 						this.compiler.fileTimestamps = undefined; | 
					
						
							|  |  |  | 						this.compiler.contextTimestamps = undefined; | 
					
						
							|  |  |  | 						this.compiler.fsStartTime = undefined; | 
					
						
							|  |  |  | 						return this.handler(err); | 
					
						
							|  |  |  | 					} | 
					
						
							|  |  |  | 					this._invalidate( | 
					
						
							|  |  |  | 						fileTimeInfoEntries, | 
					
						
							|  |  |  | 						contextTimeInfoEntries, | 
					
						
							|  |  |  | 						changedFiles, | 
					
						
							|  |  |  | 						removedFiles | 
					
						
							|  |  |  | 					); | 
					
						
							|  |  |  | 					this._onChange(); | 
					
						
							|  |  |  | 				}, | 
					
						
							|  |  |  | 				(fileName, changeTime) => { | 
					
						
							|  |  |  | 					if (!this._invalidReported) { | 
					
						
							|  |  |  | 						this._invalidReported = true; | 
					
						
							|  |  |  | 						this.compiler.hooks.invalid.call(fileName, changeTime); | 
					
						
							|  |  |  | 					} | 
					
						
							|  |  |  | 					this._onInvalid(); | 
					
						
							| 
									
										
										
										
											2021-04-09 23:51:58 +08:00
										 |  |  | 				} | 
					
						
							| 
									
										
										
										
											2024-03-14 02:23:33 +08:00
										 |  |  | 			); | 
					
						
							| 
									
										
										
										
											2017-12-31 23:19:18 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-10 18:34:59 +08:00
										 |  |  | 	/** | 
					
						
							| 
									
										
										
										
											2020-07-31 23:38:33 +08:00
										 |  |  | 	 * @param {Callback<void>=} callback signals when the build has completed again | 
					
						
							| 
									
										
										
										
											2018-12-10 18:34:59 +08:00
										 |  |  | 	 * @returns {void} | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2017-12-31 23:19:18 +08:00
										 |  |  | 	invalidate(callback) { | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		if (callback) { | 
					
						
							| 
									
										
										
										
											2017-12-31 23:19:18 +08:00
										 |  |  | 			this.callbacks.push(callback); | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2021-04-09 23:51:58 +08:00
										 |  |  | 		if (!this._invalidReported) { | 
					
						
							|  |  |  | 			this._invalidReported = true; | 
					
						
							| 
									
										
										
										
											2021-02-14 02:53:50 +08:00
										 |  |  | 			this.compiler.hooks.invalid.call(null, Date.now()); | 
					
						
							| 
									
										
										
										
											2018-01-03 19:48:46 +08:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2021-05-17 19:49:43 +08:00
										 |  |  | 		this._onChange(); | 
					
						
							| 
									
										
										
										
											2018-12-10 18:34:59 +08:00
										 |  |  | 		this._invalidate(); | 
					
						
							| 
									
										
										
										
											2018-01-03 19:48:46 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-06-22 05:55:05 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {ReadonlyMap<string, FileSystemInfoEntry | "ignore">=} fileTimeInfoEntries info for files | 
					
						
							|  |  |  | 	 * @param {ReadonlyMap<string, FileSystemInfoEntry | "ignore">=} contextTimeInfoEntries info for directories | 
					
						
							|  |  |  | 	 * @param {ReadonlySet<string>=} changedFiles changed files | 
					
						
							|  |  |  | 	 * @param {ReadonlySet<string>=} removedFiles removed files | 
					
						
							|  |  |  | 	 * @returns {void} | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2021-05-18 19:31:02 +08:00
										 |  |  | 	_invalidate( | 
					
						
							|  |  |  | 		fileTimeInfoEntries, | 
					
						
							|  |  |  | 		contextTimeInfoEntries, | 
					
						
							|  |  |  | 		changedFiles, | 
					
						
							|  |  |  | 		removedFiles | 
					
						
							|  |  |  | 	) { | 
					
						
							|  |  |  | 		if (this.suspended || (this._isBlocked() && (this.blocked = true))) { | 
					
						
							|  |  |  | 			this._mergeWithCollected(changedFiles, removedFiles); | 
					
						
							| 
									
										
										
										
											2021-02-14 02:53:50 +08:00
										 |  |  | 			return; | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2019-06-03 23:49:22 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		if (this.running) { | 
					
						
							| 
									
										
										
										
											2021-05-19 22:18:37 +08:00
										 |  |  | 			this._mergeWithCollected(changedFiles, removedFiles); | 
					
						
							| 
									
										
										
										
											2017-12-31 23:19:18 +08:00
										 |  |  | 			this.invalid = true; | 
					
						
							|  |  |  | 		} else { | 
					
						
							| 
									
										
										
										
											2021-05-18 19:31:02 +08:00
										 |  |  | 			this._go( | 
					
						
							|  |  |  | 				fileTimeInfoEntries, | 
					
						
							|  |  |  | 				contextTimeInfoEntries, | 
					
						
							|  |  |  | 				changedFiles, | 
					
						
							|  |  |  | 				removedFiles | 
					
						
							|  |  |  | 			); | 
					
						
							| 
									
										
										
										
											2017-12-31 23:19:18 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-01 00:53:33 +08:00
										 |  |  | 	suspend() { | 
					
						
							|  |  |  | 		this.suspended = true; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	resume() { | 
					
						
							|  |  |  | 		if (this.suspended) { | 
					
						
							|  |  |  | 			this.suspended = false; | 
					
						
							| 
									
										
										
										
											2021-02-14 02:53:50 +08:00
										 |  |  | 			this._invalidate(); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-10 18:34:59 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {Callback<void>} callback signals when the watcher is closed | 
					
						
							|  |  |  | 	 * @returns {void} | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2017-12-31 23:19:18 +08:00
										 |  |  | 	close(callback) { | 
					
						
							| 
									
										
										
										
											2020-07-15 20:48:40 +08:00
										 |  |  | 		if (this._closeCallbacks) { | 
					
						
							|  |  |  | 			if (callback) { | 
					
						
							|  |  |  | 				this._closeCallbacks.push(callback); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			return; | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2023-06-22 05:55:05 +08:00
										 |  |  | 		/** | 
					
						
							| 
									
										
										
										
											2024-02-21 22:05:29 +08:00
										 |  |  | 		 * @param {WebpackError | null} err error if any | 
					
						
							| 
									
										
										
										
											2023-06-22 05:55:05 +08:00
										 |  |  | 		 * @param {Compilation=} compilation compilation if any | 
					
						
							|  |  |  | 		 */ | 
					
						
							| 
									
										
										
										
											2020-07-31 23:38:33 +08:00
										 |  |  | 		const finalCallback = (err, compilation) => { | 
					
						
							| 
									
										
										
										
											2020-06-25 17:44:11 +08:00
										 |  |  | 			this.running = false; | 
					
						
							| 
									
										
										
										
											2018-03-07 17:15:46 +08:00
										 |  |  | 			this.compiler.running = false; | 
					
						
							| 
									
										
										
										
											2020-09-19 12:25:02 +08:00
										 |  |  | 			this.compiler.watching = undefined; | 
					
						
							| 
									
										
										
										
											2018-10-24 01:52:32 +08:00
										 |  |  | 			this.compiler.watchMode = false; | 
					
						
							| 
									
										
										
										
											2019-10-21 21:35:38 +08:00
										 |  |  | 			this.compiler.modifiedFiles = undefined; | 
					
						
							|  |  |  | 			this.compiler.removedFiles = undefined; | 
					
						
							| 
									
										
										
										
											2018-09-28 03:28:07 +08:00
										 |  |  | 			this.compiler.fileTimestamps = undefined; | 
					
						
							|  |  |  | 			this.compiler.contextTimestamps = undefined; | 
					
						
							| 
									
										
										
										
											2021-05-19 22:18:37 +08:00
										 |  |  | 			this.compiler.fsStartTime = undefined; | 
					
						
							| 
									
										
										
										
											2023-06-22 05:55:05 +08:00
										 |  |  | 			/** | 
					
						
							| 
									
										
										
										
											2024-02-21 22:05:29 +08:00
										 |  |  | 			 * @param {WebpackError | null} err error if any | 
					
						
							| 
									
										
										
										
											2023-06-22 05:55:05 +08:00
										 |  |  | 			 */ | 
					
						
							| 
									
										
										
										
											2021-08-30 21:01:24 +08:00
										 |  |  | 			const shutdown = err => { | 
					
						
							|  |  |  | 				this.compiler.hooks.watchClose.call(); | 
					
						
							| 
									
										
										
										
											2023-06-22 05:55:05 +08:00
										 |  |  | 				const closeCallbacks = | 
					
						
							|  |  |  | 					/** @type {Callback<void>[]} */ | 
					
						
							|  |  |  | 					(this._closeCallbacks); | 
					
						
							| 
									
										
										
										
											2021-08-30 21:01:24 +08:00
										 |  |  | 				this._closeCallbacks = undefined; | 
					
						
							|  |  |  | 				for (const cb of closeCallbacks) cb(err); | 
					
						
							| 
									
										
										
										
											2020-07-31 23:38:33 +08:00
										 |  |  | 			}; | 
					
						
							|  |  |  | 			if (compilation) { | 
					
						
							|  |  |  | 				const logger = compilation.getLogger("webpack.Watching"); | 
					
						
							|  |  |  | 				logger.time("storeBuildDependencies"); | 
					
						
							|  |  |  | 				this.compiler.cache.storeBuildDependencies( | 
					
						
							|  |  |  | 					compilation.buildDependencies, | 
					
						
							| 
									
										
										
										
											2021-08-30 21:01:24 +08:00
										 |  |  | 					err2 => { | 
					
						
							| 
									
										
										
										
											2020-07-31 23:38:33 +08:00
										 |  |  | 						logger.timeEnd("storeBuildDependencies"); | 
					
						
							| 
									
										
										
										
											2021-08-30 21:01:24 +08:00
										 |  |  | 						shutdown(err || err2); | 
					
						
							| 
									
										
										
										
											2020-07-31 23:38:33 +08:00
										 |  |  | 					} | 
					
						
							|  |  |  | 				); | 
					
						
							|  |  |  | 			} else { | 
					
						
							| 
									
										
										
										
											2021-08-30 21:01:24 +08:00
										 |  |  | 				shutdown(err); | 
					
						
							| 
									
										
										
										
											2020-07-31 23:38:33 +08:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2018-03-07 17:15:46 +08:00
										 |  |  | 		}; | 
					
						
							| 
									
										
										
										
											2017-12-31 23:19:18 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		this.closed = true; | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		if (this.watcher) { | 
					
						
							| 
									
										
										
										
											2017-12-31 23:19:18 +08:00
										 |  |  | 			this.watcher.close(); | 
					
						
							|  |  |  | 			this.watcher = null; | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		if (this.pausedWatcher) { | 
					
						
							| 
									
										
										
										
											2017-12-31 23:19:18 +08:00
										 |  |  | 			this.pausedWatcher.close(); | 
					
						
							|  |  |  | 			this.pausedWatcher = null; | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2020-07-15 20:48:40 +08:00
										 |  |  | 		this._closeCallbacks = []; | 
					
						
							| 
									
										
										
										
											2020-06-25 17:44:11 +08:00
										 |  |  | 		if (callback) { | 
					
						
							|  |  |  | 			this._closeCallbacks.push(callback); | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		if (this.running) { | 
					
						
							| 
									
										
										
										
											2017-12-31 23:19:18 +08:00
										 |  |  | 			this.invalid = true; | 
					
						
							| 
									
										
										
										
											2018-03-07 17:15:46 +08:00
										 |  |  | 			this._done = finalCallback; | 
					
						
							| 
									
										
										
										
											2017-12-31 23:19:18 +08:00
										 |  |  | 		} else { | 
					
						
							| 
									
										
										
										
											2024-02-21 22:05:29 +08:00
										 |  |  | 			finalCallback(null); | 
					
						
							| 
									
										
										
										
											2017-12-31 23:19:18 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | module.exports = Watching; |