| 
									
										
										
										
											2015-10-29 06:26:52 +08:00
										 |  |  | /* | 
					
						
							|  |  |  | 	MIT License http://www.opensource.org/licenses/mit-license.php
 | 
					
						
							|  |  |  | 	Author Tobias Koppers @sokra | 
					
						
							|  |  |  | */ | 
					
						
							| 
									
										
										
										
											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
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-04 14:20:51 +08:00
										 |  |  | class WatchIgnorePlugin { | 
					
						
							|  |  |  | 	constructor(paths) { | 
					
						
							| 
									
										
										
										
											2017-11-11 20:05:55 +08:00
										 |  |  | 		validateOptions(schema, paths, "Watch Ignore Plugin"); | 
					
						
							| 
									
										
										
										
											2017-01-04 14:20:51 +08:00
										 |  |  | 		this.paths = paths; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	apply(compiler) { | 
					
						
							| 
									
										
										
										
											2017-12-06 22:01:25 +08:00
										 |  |  | 		compiler.hooks.afterEnvironment.tap("WatchIgnorePlugin", () => { | 
					
						
							| 
									
										
										
										
											2017-01-04 14:20:51 +08:00
										 |  |  | 			compiler.watchFileSystem = new IgnoringWatchFileSystem(compiler.watchFileSystem, this.paths); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2015-03-05 15:18:11 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | module.exports = WatchIgnorePlugin; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											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) { | 
					
						
							|  |  |  | 		const ignored = path => this.paths.some(p => p instanceof RegExp ? p.test(path) : path.indexOf(p) === 0); | 
					
						
							| 
									
										
										
										
											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-01-03 19:48:46 +08:00
										 |  |  | 		const watcher = this.wfs.watch(files.filter(notIgnored), dirs.filter(notIgnored), missing, startTime, options, (err, filesModified, dirsModified, missingModified, fileTimestamps, dirTimestamps) => { | 
					
						
							| 
									
										
										
										
											2017-01-04 14:20:51 +08:00
										 |  |  | 			if(err) return callback(err); | 
					
						
							| 
									
										
										
										
											2015-03-05 15:18:11 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-01-22 20:52:43 +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
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2015-03-05 15:18:11 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-01-22 20:52:43 +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
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2015-03-05 15:18:11 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-04 14:20:51 +08:00
										 |  |  | 			callback(err, filesModified, dirsModified, missingModified, fileTimestamps, dirTimestamps); | 
					
						
							|  |  |  | 		}, callbackUndelayed); | 
					
						
							| 
									
										
										
										
											2018-01-03 19:48:46 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		return { | 
					
						
							|  |  |  | 			close: () => watcher.close(), | 
					
						
							|  |  |  | 			pause: () => watcher.pause(), | 
					
						
							|  |  |  | 			getContextTimestamps: () => { | 
					
						
							|  |  |  | 				const dirTimestamps = watcher.getContextTimestamps(); | 
					
						
							| 
									
										
										
										
											2018-01-22 20:52:43 +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; | 
					
						
							|  |  |  | 			}, | 
					
						
							|  |  |  | 			getFileTimestamps: () => { | 
					
						
							|  |  |  | 				const fileTimestamps = watcher.getFileTimestamps(); | 
					
						
							| 
									
										
										
										
											2018-01-22 20:52:43 +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
										 |  |  | 	} | 
					
						
							|  |  |  | } |