| 
									
										
										
										
											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
										 |  |  | 
 | 
					
						
							|  |  |  | class WatchIgnorePlugin { | 
					
						
							|  |  |  | 	constructor(paths) { | 
					
						
							|  |  |  | 		this.paths = paths; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	apply(compiler) { | 
					
						
							|  |  |  | 		compiler.plugin("after-environment", () => { | 
					
						
							|  |  |  | 			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
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-04 14:20:51 +08:00
										 |  |  | 		this.wfs.watch(files.filter(notIgnored), dirs.filter(notIgnored), missing, startTime, options, (err, filesModified, dirsModified, missingModified, fileTimestamps, dirTimestamps) => { | 
					
						
							|  |  |  | 			if(err) return callback(err); | 
					
						
							| 
									
										
										
										
											2015-03-05 15:18:11 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-04 14:20:51 +08:00
										 |  |  | 			ignoredFiles.forEach(path => { | 
					
						
							|  |  |  | 				fileTimestamps[path] = 1; | 
					
						
							|  |  |  | 			}); | 
					
						
							| 
									
										
										
										
											2015-03-05 15:18:11 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-04 14:20:51 +08:00
										 |  |  | 			ignoredDirs.forEach(path => { | 
					
						
							|  |  |  | 				dirTimestamps[path] = 1; | 
					
						
							|  |  |  | 			}); | 
					
						
							| 
									
										
										
										
											2015-03-05 15:18:11 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-04 14:20:51 +08:00
										 |  |  | 			callback(err, filesModified, dirsModified, missingModified, fileTimestamps, dirTimestamps); | 
					
						
							|  |  |  | 		}, callbackUndelayed); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } |