| 
									
										
										
										
											2015-10-29 06:26:52 +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-01-11 17:51:58 +08:00
										 |  |  | "use strict"; | 
					
						
							| 
									
										
										
										
											2017-01-04 14:20:51 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-29 17:19:28 +08:00
										 |  |  | const validateOptions = require("schema-utils"); | 
					
						
							| 
									
										
										
										
											2017-11-11 20:05:55 +08:00
										 |  |  | const schema = require("../schemas/plugins/WatchIgnorePlugin.json"); | 
					
						
							| 
									
										
										
										
											2017-10-28 05:23:38 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-20 16:13:55 +08:00
										 |  |  | /** @typedef {import("../declarations/plugins/WatchIgnorePlugin").WatchIgnorePluginOptions} WatchIgnorePluginOptions */ | 
					
						
							| 
									
										
										
										
											2018-11-09 05:59:19 +08:00
										 |  |  | /** @typedef {import("./Compiler")} Compiler */ | 
					
						
							| 
									
										
										
										
											2018-09-20 16:13:55 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-04 14:20:51 +08:00
										 |  |  | class IgnoringWatchFileSystem { | 
					
						
							|  |  |  | 	constructor(wfs, paths) { | 
					
						
							|  |  |  | 		this.wfs = wfs; | 
					
						
							|  |  |  | 		this.paths = paths; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2015-03-05 15:18:11 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-04 14:20:51 +08:00
										 |  |  | 	watch(files, dirs, missing, startTime, options, callback, callbackUndelayed) { | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		const ignored = path => | 
					
						
							| 
									
										
										
										
											2019-02-05 17:06:32 +08:00
										 |  |  | 			this.paths.some(p => | 
					
						
							|  |  |  | 				p instanceof RegExp ? p.test(path) : path.indexOf(p) === 0 | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 			); | 
					
						
							| 
									
										
										
										
											2015-03-05 15:18:11 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-04 14:20:51 +08:00
										 |  |  | 		const notIgnored = path => !ignored(path); | 
					
						
							| 
									
										
										
										
											2015-03-05 15:18:11 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-04 14:20:51 +08:00
										 |  |  | 		const ignoredFiles = files.filter(ignored); | 
					
						
							|  |  |  | 		const ignoredDirs = dirs.filter(ignored); | 
					
						
							| 
									
										
										
										
											2015-08-25 16:32:06 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		const watcher = this.wfs.watch( | 
					
						
							|  |  |  | 			files.filter(notIgnored), | 
					
						
							|  |  |  | 			dirs.filter(notIgnored), | 
					
						
							|  |  |  | 			missing, | 
					
						
							|  |  |  | 			startTime, | 
					
						
							|  |  |  | 			options, | 
					
						
							| 
									
										
										
										
											2019-01-05 21:58:06 +08:00
										 |  |  | 			(err, fileTimestamps, dirTimestamps, removedFiles) => { | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 				if (err) return callback(err); | 
					
						
							|  |  |  | 				for (const path of ignoredFiles) { | 
					
						
							|  |  |  | 					fileTimestamps.set(path, 1); | 
					
						
							|  |  |  | 				} | 
					
						
							| 
									
										
										
										
											2015-03-05 15:18:11 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 				for (const path of ignoredDirs) { | 
					
						
							|  |  |  | 					dirTimestamps.set(path, 1); | 
					
						
							|  |  |  | 				} | 
					
						
							| 
									
										
										
										
											2015-03-05 15:18:11 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-05 21:58:06 +08:00
										 |  |  | 				callback(err, fileTimestamps, dirTimestamps, removedFiles); | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 			}, | 
					
						
							|  |  |  | 			callbackUndelayed | 
					
						
							|  |  |  | 		); | 
					
						
							| 
									
										
										
										
											2018-01-03 19:48:46 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		return { | 
					
						
							|  |  |  | 			close: () => watcher.close(), | 
					
						
							|  |  |  | 			pause: () => watcher.pause(), | 
					
						
							| 
									
										
										
										
											2019-01-05 21:58:06 +08:00
										 |  |  | 			getContextInfoEntries: () => { | 
					
						
							|  |  |  | 				const dirTimestamps = watcher.getContextInfoEntries(); | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 				for (const path of ignoredDirs) { | 
					
						
							| 
									
										
										
										
											2018-01-23 15:30:22 +08:00
										 |  |  | 					dirTimestamps.set(path, 1); | 
					
						
							| 
									
										
										
										
											2018-01-22 20:52:43 +08:00
										 |  |  | 				} | 
					
						
							| 
									
										
										
										
											2018-01-03 19:48:46 +08:00
										 |  |  | 				return dirTimestamps; | 
					
						
							|  |  |  | 			}, | 
					
						
							| 
									
										
										
										
											2019-01-05 21:58:06 +08:00
										 |  |  | 			getFileTimeInfoEntries: () => { | 
					
						
							|  |  |  | 				const fileTimestamps = watcher.getFileTimeInfoEntries(); | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 				for (const path of ignoredFiles) { | 
					
						
							| 
									
										
										
										
											2018-01-23 15:30:22 +08:00
										 |  |  | 					fileTimestamps.set(path, 1); | 
					
						
							| 
									
										
										
										
											2018-01-22 20:52:43 +08:00
										 |  |  | 				} | 
					
						
							| 
									
										
										
										
											2018-01-03 19:48:46 +08:00
										 |  |  | 				return fileTimestamps; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		}; | 
					
						
							| 
									
										
										
										
											2017-01-04 14:20:51 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2018-07-31 14:17:44 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | class WatchIgnorePlugin { | 
					
						
							| 
									
										
										
										
											2018-09-20 16:13:55 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {WatchIgnorePluginOptions} paths list of paths | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2018-07-31 14:17:44 +08:00
										 |  |  | 	constructor(paths) { | 
					
						
							|  |  |  | 		validateOptions(schema, paths, "Watch Ignore Plugin"); | 
					
						
							|  |  |  | 		this.paths = paths; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-09 05:59:19 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {Compiler} compiler the compiler instance | 
					
						
							|  |  |  | 	 * @returns {void} | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2018-07-31 14:17:44 +08:00
										 |  |  | 	apply(compiler) { | 
					
						
							|  |  |  | 		compiler.hooks.afterEnvironment.tap("WatchIgnorePlugin", () => { | 
					
						
							|  |  |  | 			compiler.watchFileSystem = new IgnoringWatchFileSystem( | 
					
						
							|  |  |  | 				compiler.watchFileSystem, | 
					
						
							|  |  |  | 				this.paths | 
					
						
							|  |  |  | 			); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | module.exports = WatchIgnorePlugin; |