| 
									
										
										
										
											2013-01-31 01:49:25 +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-06 13:02:52 +08:00
										 |  |  | "use strict"; | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-06 13:02:52 +08:00
										 |  |  | const CachedInputFileSystem = require("enhanced-resolve/lib/CachedInputFileSystem"); | 
					
						
							| 
									
										
										
										
											2019-06-11 19:09:42 +08:00
										 |  |  | const fs = require("graceful-fs"); | 
					
						
							| 
									
										
										
										
											2019-07-22 14:23:40 +08:00
										 |  |  | const createConsoleLogger = require("../logging/createConsoleLogger"); | 
					
						
							| 
									
										
										
										
											2018-07-30 23:08:51 +08:00
										 |  |  | const NodeWatchFileSystem = require("./NodeWatchFileSystem"); | 
					
						
							| 
									
										
										
										
											2019-07-28 01:48:10 +08:00
										 |  |  | const nodeConsole = require("./nodeConsole"); | 
					
						
							| 
									
										
										
										
											2017-01-06 13:02:52 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-09 05:59:19 +08:00
										 |  |  | /** @typedef {import("../Compiler")} Compiler */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-06 13:02:52 +08:00
										 |  |  | class NodeEnvironmentPlugin { | 
					
						
							| 
									
										
										
										
											2019-07-22 14:23:40 +08:00
										 |  |  | 	constructor(options) { | 
					
						
							|  |  |  | 		this.options = options || {}; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-09 05:59:19 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {Compiler} compiler the compiler instance | 
					
						
							|  |  |  | 	 * @returns {void} | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2017-01-06 13:02:52 +08:00
										 |  |  | 	apply(compiler) { | 
					
						
							| 
									
										
										
										
											2019-07-22 14:23:40 +08:00
										 |  |  | 		compiler.infrastructureLogger = createConsoleLogger( | 
					
						
							|  |  |  | 			Object.assign( | 
					
						
							|  |  |  | 				{ | 
					
						
							|  |  |  | 					level: "info", | 
					
						
							| 
									
										
										
										
											2019-07-28 01:48:10 +08:00
										 |  |  | 					debug: false, | 
					
						
							|  |  |  | 					console: nodeConsole | 
					
						
							| 
									
										
										
										
											2019-07-22 14:23:40 +08:00
										 |  |  | 				}, | 
					
						
							|  |  |  | 				this.options.infrastructureLogging | 
					
						
							|  |  |  | 			) | 
					
						
							|  |  |  | 		); | 
					
						
							| 
									
										
										
										
											2019-07-05 06:41:30 +08:00
										 |  |  | 		compiler.inputFileSystem = new CachedInputFileSystem(fs, 60000); | 
					
						
							| 
									
										
										
										
											2017-01-06 13:02:52 +08:00
										 |  |  | 		const inputFileSystem = compiler.inputFileSystem; | 
					
						
							| 
									
										
										
										
											2019-06-11 19:09:42 +08:00
										 |  |  | 		compiler.outputFileSystem = fs; | 
					
						
							|  |  |  | 		compiler.intermediateFileSystem = fs; | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		compiler.watchFileSystem = new NodeWatchFileSystem( | 
					
						
							|  |  |  | 			compiler.inputFileSystem | 
					
						
							|  |  |  | 		); | 
					
						
							|  |  |  | 		compiler.hooks.beforeRun.tap("NodeEnvironmentPlugin", compiler => { | 
					
						
							| 
									
										
										
										
											2018-11-09 05:59:19 +08:00
										 |  |  | 			if (compiler.inputFileSystem === inputFileSystem) { | 
					
						
							|  |  |  | 				inputFileSystem.purge(); | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2017-01-06 13:02:52 +08:00
										 |  |  | 		}); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2018-11-09 05:59:19 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | module.exports = NodeEnvironmentPlugin; |