mirror of https://github.com/webpack/webpack.git
				
				
				
			refactor to single write per update
throttle unimportant updates
This commit is contained in:
		
							parent
							
								
									f29991bda4
								
							
						
					
					
						commit
						cae07597f6
					
				|  | @ -68,8 +68,8 @@ const createDefaultHandler = profile => { | |||
| 					const diff = now - lastStateTime; | ||||
| 					if (diff >= 1) { | ||||
| 						const stateMsg = `${diff}ms ${lastState}`; | ||||
| 						goToLineStart(stateMsg); | ||||
| 						process.stderr.write(stateMsg + "\n"); | ||||
| 						goToLineStartAndWrite(stateMsg); | ||||
| 						process.stderr.write("\n"); | ||||
| 						lineCaretPosition = 0; | ||||
| 					} | ||||
| 				} | ||||
|  | @ -78,14 +78,13 @@ const createDefaultHandler = profile => { | |||
| 			} | ||||
| 		} | ||||
| 		if (lastMessage !== msg) { | ||||
| 			goToLineStart(msg); | ||||
| 			msg = msg.substring(0, maxLineLength); | ||||
| 			process.stderr.write(msg); | ||||
| 			goToLineStartAndWrite(msg); | ||||
| 			lastMessage = msg; | ||||
| 		} | ||||
| 	}; | ||||
| 
 | ||||
| 	const goToLineStart = nextMessage => { | ||||
| 	const goToLineStartAndWrite = nextMessage => { | ||||
| 		let str = ""; | ||||
| 		for (; lineCaretPosition > nextMessage.length; lineCaretPosition--) { | ||||
| 			str += "\b \b"; | ||||
|  | @ -94,7 +93,7 @@ const createDefaultHandler = profile => { | |||
| 			str += "\b"; | ||||
| 		} | ||||
| 		lineCaretPosition = nextMessage.length; | ||||
| 		if (str) process.stderr.write(str); | ||||
| 		if (str) process.stderr.write(str + nextMessage); | ||||
| 	}; | ||||
| 
 | ||||
| 	return defaultHandler; | ||||
|  | @ -193,6 +192,11 @@ class ProgressPlugin { | |||
| 		let doneModules = 0; | ||||
| 		let doneEntries = 0; | ||||
| 		const activeModules = new Set(); | ||||
| 		let lastUpdate = 0; | ||||
| 
 | ||||
| 		const updateThrottled = () => { | ||||
| 			if (lastUpdate + 500 < Date.now()) update(); | ||||
| 		}; | ||||
| 
 | ||||
| 		const update = () => { | ||||
| 			/** @type {string[]} */ | ||||
|  | @ -214,11 +218,12 @@ class ProgressPlugin { | |||
| 				items.push(lastActiveModule); | ||||
| 			} | ||||
| 			handler(percentage, "building", ...items); | ||||
| 			lastUpdate = Date.now(); | ||||
| 		}; | ||||
| 
 | ||||
| 		const moduleAdd = module => { | ||||
| 			moduleCount++; | ||||
| 			if (moduleCount % 100 === 0) update(); | ||||
| 			if (moduleCount % 100 === 0) updateThrottled(); | ||||
| 		}; | ||||
| 
 | ||||
| 		const moduleBuild = module => { | ||||
|  | @ -234,7 +239,7 @@ class ProgressPlugin { | |||
| 
 | ||||
| 		const entryAdd = (entry, name) => { | ||||
| 			entriesCount++; | ||||
| 			if (entriesCount % 10 === 0) update(); | ||||
| 			if (entriesCount % 10 === 0) updateThrottled(); | ||||
| 		}; | ||||
| 
 | ||||
| 		const moduleDone = module => { | ||||
|  | @ -248,11 +253,12 @@ class ProgressPlugin { | |||
| 						for (const m of activeModules) { | ||||
| 							lastActiveModule = m; | ||||
| 						} | ||||
| 						if (doneModules % 100 !== 0) update(); | ||||
| 						update(); | ||||
| 						return; | ||||
| 					} | ||||
| 				} | ||||
| 			} | ||||
| 			if (doneModules % 100 === 0) update(); | ||||
| 			if (doneModules % 100 === 0) updateThrottled(); | ||||
| 		}; | ||||
| 
 | ||||
| 		const entryDone = (entry, name) => { | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue