| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | /* | 
					
						
							|  |  |  | 	MIT License http://www.opensource.org/licenses/mit-license.php
 | 
					
						
							|  |  |  | 	Author Tobias Koppers @sokra | 
					
						
							|  |  |  | */ | 
					
						
							|  |  |  | var async = require("async"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | var Tapable = require("tapable"); | 
					
						
							|  |  |  | var EntryModuleNotFoundError = require("./EntryModuleNotFoundError"); | 
					
						
							|  |  |  | var ModuleNotFoundError = require("./ModuleNotFoundError"); | 
					
						
							| 
									
										
										
										
											2016-06-24 07:51:52 +08:00
										 |  |  | var ModuleDependencyWarning = require("./ModuleDependencyWarning"); | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | var Module = require("./Module"); | 
					
						
							|  |  |  | var ArrayMap = require("./ArrayMap"); | 
					
						
							|  |  |  | var Chunk = require("./Chunk"); | 
					
						
							| 
									
										
										
										
											2016-07-13 17:03:14 +08:00
										 |  |  | var Entrypoint = require("./Entrypoint"); | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | var Stats = require("./Stats"); | 
					
						
							| 
									
										
										
										
											2014-06-03 03:23:53 +08:00
										 |  |  | var MainTemplate = require("./MainTemplate"); | 
					
						
							| 
									
										
										
										
											2014-06-03 05:40:50 +08:00
										 |  |  | var ChunkTemplate = require("./ChunkTemplate"); | 
					
						
							| 
									
										
										
										
											2014-06-03 06:14:46 +08:00
										 |  |  | var HotUpdateChunkTemplate = require("./HotUpdateChunkTemplate"); | 
					
						
							| 
									
										
										
										
											2014-06-03 14:45:26 +08:00
										 |  |  | var ModuleTemplate = require("./ModuleTemplate"); | 
					
						
							| 
									
										
										
										
											2015-05-11 00:43:47 +08:00
										 |  |  | var Dependency = require("./Dependency"); | 
					
						
							| 
									
										
										
										
											2015-06-27 17:34:17 +08:00
										 |  |  | var ChunkRenderError = require("./ChunkRenderError"); | 
					
						
							| 
									
										
										
										
											2015-12-30 00:44:55 +08:00
										 |  |  | var CachedSource = require("webpack-sources").CachedSource; | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | function Compilation(compiler) { | 
					
						
							|  |  |  | 	Tapable.call(this); | 
					
						
							|  |  |  | 	this.compiler = compiler; | 
					
						
							|  |  |  | 	this.resolvers = compiler.resolvers; | 
					
						
							|  |  |  | 	this.inputFileSystem = compiler.inputFileSystem; | 
					
						
							| 
									
										
										
										
											2014-06-03 03:23:53 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-02-13 21:42:34 +08:00
										 |  |  | 	var options = this.options = compiler.options; | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 	this.outputOptions = options && options.output; | 
					
						
							|  |  |  | 	this.bail = options && options.bail; | 
					
						
							| 
									
										
										
										
											2013-05-08 20:47:13 +08:00
										 |  |  | 	this.profile = options && options.profile; | 
					
						
							| 
									
										
										
										
											2016-11-24 06:14:09 +08:00
										 |  |  | 	this.performance = options && options.performance; | 
					
						
							| 
									
										
										
										
											2016-12-01 12:37:14 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-03 03:23:53 +08:00
										 |  |  | 	this.mainTemplate = new MainTemplate(this.outputOptions); | 
					
						
							| 
									
										
										
										
											2016-12-27 11:01:46 +08:00
										 |  |  | 	this.chunkTemplate = new ChunkTemplate(this.outputOptions); | 
					
						
							| 
									
										
										
										
											2014-06-03 06:14:46 +08:00
										 |  |  | 	this.hotUpdateChunkTemplate = new HotUpdateChunkTemplate(this.outputOptions); | 
					
						
							| 
									
										
										
										
											2014-06-03 14:45:26 +08:00
										 |  |  | 	this.moduleTemplate = new ModuleTemplate(this.outputOptions); | 
					
						
							| 
									
										
										
										
											2014-06-03 03:23:53 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 	this.entries = []; | 
					
						
							| 
									
										
										
										
											2013-05-22 16:12:53 +08:00
										 |  |  | 	this.preparedChunks = []; | 
					
						
							| 
									
										
										
										
											2016-07-13 17:03:14 +08:00
										 |  |  | 	this.entrypoints = {}; | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 	this.chunks = []; | 
					
						
							|  |  |  | 	this.namedChunks = {}; | 
					
						
							|  |  |  | 	this.modules = []; | 
					
						
							|  |  |  | 	this._modules = {}; | 
					
						
							|  |  |  | 	this.cache = null; | 
					
						
							| 
									
										
										
										
											2013-05-31 18:22:40 +08:00
										 |  |  | 	this.records = null; | 
					
						
							| 
									
										
										
										
											2016-07-18 06:41:26 +08:00
										 |  |  | 	this.nextFreeModuleIndex = undefined; | 
					
						
							|  |  |  | 	this.nextFreeModuleIndex2 = undefined; | 
					
						
							| 
									
										
										
										
											2013-07-01 19:59:02 +08:00
										 |  |  | 	this.additionalChunkAssets = []; | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 	this.assets = {}; | 
					
						
							|  |  |  | 	this.errors = []; | 
					
						
							|  |  |  | 	this.warnings = []; | 
					
						
							|  |  |  | 	this.children = []; | 
					
						
							|  |  |  | 	this.dependencyFactories = new ArrayMap(); | 
					
						
							|  |  |  | 	this.dependencyTemplates = new ArrayMap(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | module.exports = Compilation; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Compilation.prototype = Object.create(Tapable.prototype); | 
					
						
							| 
									
										
										
										
											2015-08-18 19:35:57 +08:00
										 |  |  | Compilation.prototype.constructor = Compilation; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-12-22 23:10:23 +08:00
										 |  |  | Compilation.prototype.templatesPlugin = function(name, fn) { | 
					
						
							|  |  |  | 	this.mainTemplate.plugin(name, fn); | 
					
						
							|  |  |  | 	this.chunkTemplate.plugin(name, fn); | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-10-28 23:21:29 +08:00
										 |  |  | Compilation.prototype.addModule = function(module, cacheGroup) { | 
					
						
							|  |  |  | 	cacheGroup = cacheGroup || "m"; | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 	var identifier = module.identifier(); | 
					
						
							| 
									
										
										
										
											2014-06-04 03:03:21 +08:00
										 |  |  | 	if(this._modules[identifier]) { | 
					
						
							|  |  |  | 		return false; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2013-10-28 23:21:29 +08:00
										 |  |  | 	if(this.cache && this.cache[cacheGroup + identifier]) { | 
					
						
							|  |  |  | 		var cacheModule = this.cache[cacheGroup + identifier]; | 
					
						
							| 
									
										
										
										
											2013-05-08 19:28:54 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 		var rebuild = true; | 
					
						
							|  |  |  | 		if(!cacheModule.error && cacheModule.cacheable && this.fileTimestamps && this.contextTimestamps) { | 
					
						
							|  |  |  | 			rebuild = cacheModule.needRebuild(this.fileTimestamps, this.contextTimestamps); | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2013-02-01 01:00:22 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 		if(!rebuild) { | 
					
						
							|  |  |  | 			cacheModule.disconnect(); | 
					
						
							|  |  |  | 			this._modules[identifier] = cacheModule; | 
					
						
							|  |  |  | 			this.modules.push(cacheModule); | 
					
						
							| 
									
										
										
										
											2013-03-05 18:05:13 +08:00
										 |  |  | 			cacheModule.errors.forEach(function(err) { | 
					
						
							|  |  |  | 				this.errors.push(err); | 
					
						
							|  |  |  | 			}, this); | 
					
						
							|  |  |  | 			cacheModule.warnings.forEach(function(err) { | 
					
						
							|  |  |  | 				this.warnings.push(err); | 
					
						
							|  |  |  | 			}, this); | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 			return cacheModule; | 
					
						
							| 
									
										
										
										
											2013-05-08 19:28:54 +08:00
										 |  |  | 		} else { | 
					
						
							|  |  |  | 			module.lastId = cacheModule.id; | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2016-12-05 06:47:19 +08:00
										 |  |  | 	module.unbuild(); | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 	this._modules[identifier] = module; | 
					
						
							| 
									
										
										
										
											2014-06-04 03:03:21 +08:00
										 |  |  | 	if(this.cache) { | 
					
						
							|  |  |  | 		this.cache[cacheGroup + identifier] = module; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 	this.modules.push(module); | 
					
						
							|  |  |  | 	return true; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Compilation.prototype.getModule = function(module) { | 
					
						
							|  |  |  | 	var identifier = module.identifier(); | 
					
						
							|  |  |  | 	return this._modules[identifier]; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-03-26 23:54:41 +08:00
										 |  |  | Compilation.prototype.findModule = function(identifier) { | 
					
						
							|  |  |  | 	return this._modules[identifier]; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-03 19:13:01 +08:00
										 |  |  | Compilation.prototype.buildModule = function(module, optional, origin, dependencies, thisCallback) { | 
					
						
							|  |  |  | 	var _this = this; | 
					
						
							| 
									
										
										
										
											2016-12-05 06:47:19 +08:00
										 |  |  | 	_this.applyPlugins1("build-module", module); | 
					
						
							| 
									
										
										
										
											2014-07-29 06:13:25 +08:00
										 |  |  | 	if(module.building) return module.building.push(thisCallback); | 
					
						
							| 
									
										
										
										
											2013-10-29 21:14:16 +08:00
										 |  |  | 	var building = module.building = [thisCallback]; | 
					
						
							| 
									
										
										
										
											2015-07-08 20:15:21 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-10-29 21:14:16 +08:00
										 |  |  | 	function callback(err) { | 
					
						
							|  |  |  | 		module.building = undefined; | 
					
						
							|  |  |  | 		building.forEach(function(cb) { | 
					
						
							|  |  |  | 			cb(err); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2016-07-03 19:13:01 +08:00
										 |  |  | 	module.build(_this.options, this, _this.resolvers.normal, _this.inputFileSystem, function(err) { | 
					
						
							| 
									
										
										
										
											2013-02-19 19:48:17 +08:00
										 |  |  | 		module.errors.forEach(function(err) { | 
					
						
							| 
									
										
										
										
											2016-07-03 19:13:01 +08:00
										 |  |  | 			err.origin = origin; | 
					
						
							|  |  |  | 			err.dependencies = dependencies; | 
					
						
							|  |  |  | 			if(optional) | 
					
						
							|  |  |  | 				_this.warnings.push(err); | 
					
						
							|  |  |  | 			else | 
					
						
							|  |  |  | 				_this.errors.push(err); | 
					
						
							| 
									
										
										
										
											2013-02-19 19:48:17 +08:00
										 |  |  | 		}, this); | 
					
						
							|  |  |  | 		module.warnings.forEach(function(err) { | 
					
						
							| 
									
										
										
										
											2016-07-03 19:13:01 +08:00
										 |  |  | 			err.origin = origin; | 
					
						
							|  |  |  | 			err.dependencies = dependencies; | 
					
						
							|  |  |  | 			_this.warnings.push(err); | 
					
						
							| 
									
										
										
										
											2013-02-19 19:48:17 +08:00
										 |  |  | 		}, this); | 
					
						
							| 
									
										
										
										
											2015-05-11 00:43:47 +08:00
										 |  |  | 		module.dependencies.sort(Dependency.compare); | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 		if(err) { | 
					
						
							| 
									
										
										
										
											2016-12-05 06:47:19 +08:00
										 |  |  | 			_this.applyPlugins2("failed-module", module, err); | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 			return callback(err); | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2016-12-05 06:47:19 +08:00
										 |  |  | 		_this.applyPlugins1("succeed-module", module); | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 		return callback(); | 
					
						
							| 
									
										
										
										
											2016-07-03 19:13:01 +08:00
										 |  |  | 	}); | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Compilation.prototype.processModuleDependencies = function(module, callback) { | 
					
						
							|  |  |  | 	var dependencies = []; | 
					
						
							| 
									
										
										
										
											2015-07-08 20:15:21 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 	function addDependency(dep) { | 
					
						
							|  |  |  | 		for(var i = 0; i < dependencies.length; i++) { | 
					
						
							| 
									
										
										
										
											2014-06-04 03:03:21 +08:00
										 |  |  | 			if(dep.isEqualResource(dependencies[i][0])) { | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 				return dependencies[i].push(dep); | 
					
						
							| 
									
										
										
										
											2014-06-04 03:03:21 +08:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		dependencies.push([dep]); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2015-07-08 20:15:21 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 	function addDependenciesBlock(block) { | 
					
						
							| 
									
										
										
										
											2014-06-04 03:03:21 +08:00
										 |  |  | 		if(block.dependencies) { | 
					
						
							|  |  |  | 			block.dependencies.forEach(addDependency); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		if(block.blocks) { | 
					
						
							|  |  |  | 			block.blocks.forEach(addDependenciesBlock); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		if(block.variables) { | 
					
						
							|  |  |  | 			block.variables.forEach(function(v) { | 
					
						
							|  |  |  | 				v.dependencies.forEach(addDependency); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	addDependenciesBlock(module); | 
					
						
							| 
									
										
										
										
											2013-10-28 23:21:29 +08:00
										 |  |  | 	this.addModuleDependencies(module, dependencies, this.bail, null, true, callback); | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Compilation.prototype.addModuleDependencies = function(module, dependencies, bail, cacheGroup, recursive, callback) { | 
					
						
							| 
									
										
										
										
											2015-11-11 06:31:03 +08:00
										 |  |  | 	var _this = this; | 
					
						
							|  |  |  | 	var start = _this.profile && +new Date(); | 
					
						
							| 
									
										
										
										
											2015-02-05 06:21:22 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 	var factories = []; | 
					
						
							|  |  |  | 	for(var i = 0; i < dependencies.length; i++) { | 
					
						
							| 
									
										
										
										
											2015-11-11 06:31:03 +08:00
										 |  |  | 		var factory = _this.dependencyFactories.get(dependencies[i][0].constructor); | 
					
						
							| 
									
										
										
										
											2014-06-04 03:03:21 +08:00
										 |  |  | 		if(!factory) { | 
					
						
							| 
									
										
										
										
											2015-10-18 16:53:38 +08:00
										 |  |  | 			return callback(new Error("No module factory available for dependency type: " + dependencies[i][0].constructor.name)); | 
					
						
							| 
									
										
										
										
											2014-06-04 03:03:21 +08:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 		factories[i] = [factory, dependencies[i]]; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2016-12-05 06:47:19 +08:00
										 |  |  | 	async.forEach(factories, function iteratorFactory(item, callback) { | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 		var dependencies = item[1]; | 
					
						
							| 
									
										
										
										
											2013-02-13 21:42:34 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 		var errorAndCallback = function errorAndCallback(err) { | 
					
						
							|  |  |  | 			err.origin = module; | 
					
						
							| 
									
										
										
										
											2015-11-11 06:31:03 +08:00
										 |  |  | 			_this.errors.push(err); | 
					
						
							| 
									
										
										
										
											2014-06-04 03:03:21 +08:00
										 |  |  | 			if(bail) { | 
					
						
							| 
									
										
										
										
											2013-10-28 23:21:29 +08:00
										 |  |  | 				callback(err); | 
					
						
							| 
									
										
										
										
											2014-06-04 03:03:21 +08:00
										 |  |  | 			} else { | 
					
						
							| 
									
										
										
										
											2013-10-28 23:21:29 +08:00
										 |  |  | 				callback(); | 
					
						
							| 
									
										
										
										
											2014-06-04 03:03:21 +08:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2015-11-11 06:31:03 +08:00
										 |  |  | 		}; | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 		var warningAndCallback = function warningAndCallback(err) { | 
					
						
							|  |  |  | 			err.origin = module; | 
					
						
							| 
									
										
										
										
											2015-11-11 06:31:03 +08:00
										 |  |  | 			_this.warnings.push(err); | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 			callback(); | 
					
						
							| 
									
										
										
										
											2015-11-11 06:31:03 +08:00
										 |  |  | 		}; | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		var factory = item[0]; | 
					
						
							| 
									
										
										
										
											2016-07-20 18:51:03 +08:00
										 |  |  | 		factory.create({ | 
					
						
							| 
									
										
										
										
											2016-09-14 18:04:42 +08:00
										 |  |  | 			contextInfo: { | 
					
						
							|  |  |  | 				issuer: module.nameForCondition && module.nameForCondition() | 
					
						
							|  |  |  | 			}, | 
					
						
							| 
									
										
										
										
											2016-07-20 18:51:03 +08:00
										 |  |  | 			context: module.context, | 
					
						
							|  |  |  | 			dependencies: dependencies | 
					
						
							| 
									
										
										
										
											2016-12-05 06:47:19 +08:00
										 |  |  | 		}, function factoryCallback(err, dependentModule) { | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 			function isOptional() { | 
					
						
							| 
									
										
										
										
											2014-06-04 03:03:21 +08:00
										 |  |  | 				return dependencies.filter(function(d) { | 
					
						
							|  |  |  | 					return !d.optional; | 
					
						
							| 
									
										
										
										
											2014-06-25 00:53:32 +08:00
										 |  |  | 				}).length === 0; | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2015-07-08 20:15:21 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 			function errorOrWarningAndCallback(err) { | 
					
						
							| 
									
										
										
										
											2014-06-04 03:03:21 +08:00
										 |  |  | 				if(isOptional()) { | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 					return warningAndCallback(err); | 
					
						
							| 
									
										
										
										
											2014-06-04 03:03:21 +08:00
										 |  |  | 				} else { | 
					
						
							| 
									
										
										
										
											2013-02-13 21:42:34 +08:00
										 |  |  | 					return errorAndCallback(err); | 
					
						
							| 
									
										
										
										
											2014-06-04 03:03:21 +08:00
										 |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			if(err) { | 
					
						
							| 
									
										
										
										
											2016-07-03 19:13:01 +08:00
										 |  |  | 				return errorOrWarningAndCallback(new ModuleNotFoundError(module, err, dependencies)); | 
					
						
							| 
									
										
										
										
											2014-06-04 03:03:21 +08:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2016-04-11 04:24:13 +08:00
										 |  |  | 			if(!dependentModule) { | 
					
						
							| 
									
										
										
										
											2015-04-04 05:39:58 +08:00
										 |  |  | 				return process.nextTick(callback); | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2015-11-11 06:31:03 +08:00
										 |  |  | 			if(_this.profile) { | 
					
						
							| 
									
										
										
										
											2016-04-11 04:24:13 +08:00
										 |  |  | 				if(!dependentModule.profile) { | 
					
						
							|  |  |  | 					dependentModule.profile = {}; | 
					
						
							| 
									
										
										
										
											2014-06-04 03:03:21 +08:00
										 |  |  | 				} | 
					
						
							| 
									
										
										
										
											2013-05-08 20:47:13 +08:00
										 |  |  | 				var afterFactory = +new Date(); | 
					
						
							| 
									
										
										
										
											2016-04-11 04:24:13 +08:00
										 |  |  | 				dependentModule.profile.factory = afterFactory - start; | 
					
						
							| 
									
										
										
										
											2013-05-08 20:47:13 +08:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2013-05-08 19:28:54 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-03 19:13:01 +08:00
										 |  |  | 			dependentModule.issuer = module; | 
					
						
							| 
									
										
										
										
											2016-04-11 04:24:13 +08:00
										 |  |  | 			var newModule = _this.addModule(dependentModule, cacheGroup); | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-04 01:12:19 +08:00
										 |  |  | 			if(!newModule) { // from cache
 | 
					
						
							| 
									
										
										
										
											2016-04-11 04:24:13 +08:00
										 |  |  | 				dependentModule = _this.getModule(dependentModule); | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-11 04:24:13 +08:00
										 |  |  | 				if(dependentModule.optional) { | 
					
						
							|  |  |  | 					dependentModule.optional = isOptional(); | 
					
						
							| 
									
										
										
										
											2014-07-03 06:00:06 +08:00
										 |  |  | 				} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 				dependencies.forEach(function(dep) { | 
					
						
							| 
									
										
										
										
											2016-04-11 04:24:13 +08:00
										 |  |  | 					dep.module = dependentModule; | 
					
						
							|  |  |  | 					dependentModule.addReason(module, dep); | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 				}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-11-11 06:31:03 +08:00
										 |  |  | 				if(_this.profile) { | 
					
						
							| 
									
										
										
										
											2014-06-04 03:03:21 +08:00
										 |  |  | 					if(!module.profile) { | 
					
						
							|  |  |  | 						module.profile = {}; | 
					
						
							|  |  |  | 					} | 
					
						
							| 
									
										
										
										
											2013-05-08 20:47:13 +08:00
										 |  |  | 					var time = +new Date() - start; | 
					
						
							| 
									
										
										
										
											2014-06-04 03:03:21 +08:00
										 |  |  | 					if(!module.profile.dependencies || time > module.profile.dependencies) { | 
					
						
							| 
									
										
										
										
											2013-05-08 20:47:13 +08:00
										 |  |  | 						module.profile.dependencies = time; | 
					
						
							| 
									
										
										
										
											2014-06-04 03:03:21 +08:00
										 |  |  | 					} | 
					
						
							| 
									
										
										
										
											2013-05-08 20:47:13 +08:00
										 |  |  | 				} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-04-04 05:39:58 +08:00
										 |  |  | 				return process.nextTick(callback); | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-04 01:12:19 +08:00
										 |  |  | 			if(newModule instanceof Module) { | 
					
						
							| 
									
										
										
										
											2015-11-11 06:31:03 +08:00
										 |  |  | 				if(_this.profile) { | 
					
						
							| 
									
										
										
										
											2016-04-11 04:24:13 +08:00
										 |  |  | 					newModule.profile = dependentModule.profile; | 
					
						
							| 
									
										
										
										
											2014-06-04 03:03:21 +08:00
										 |  |  | 				} | 
					
						
							| 
									
										
										
										
											2013-05-08 20:47:13 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-07-03 06:00:06 +08:00
										 |  |  | 				newModule.optional = isOptional(); | 
					
						
							| 
									
										
										
										
											2016-04-11 04:24:13 +08:00
										 |  |  | 				newModule.issuer = dependentModule.issuer; | 
					
						
							|  |  |  | 				dependentModule = newModule; | 
					
						
							| 
									
										
										
										
											2013-05-08 19:28:54 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 				dependencies.forEach(function(dep) { | 
					
						
							| 
									
										
										
										
											2016-04-11 04:24:13 +08:00
										 |  |  | 					dep.module = dependentModule; | 
					
						
							|  |  |  | 					dependentModule.addReason(module, dep); | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 				}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-11-11 06:31:03 +08:00
										 |  |  | 				if(_this.profile) { | 
					
						
							| 
									
										
										
										
											2015-02-05 06:21:22 +08:00
										 |  |  | 					var afterBuilding = +new Date(); | 
					
						
							|  |  |  | 					module.profile.building = afterBuilding - afterFactory; | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-04 03:03:21 +08:00
										 |  |  | 				if(recursive) { | 
					
						
							| 
									
										
										
										
											2016-04-11 04:24:13 +08:00
										 |  |  | 					return process.nextTick(_this.processModuleDependencies.bind(_this, dependentModule, callback)); | 
					
						
							| 
									
										
										
										
											2014-06-04 03:03:21 +08:00
										 |  |  | 				} else { | 
					
						
							| 
									
										
										
										
											2015-04-04 05:39:58 +08:00
										 |  |  | 					return process.nextTick(callback); | 
					
						
							| 
									
										
										
										
											2014-06-04 03:03:21 +08:00
										 |  |  | 				} | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2013-05-08 19:28:54 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-11 04:24:13 +08:00
										 |  |  | 			dependentModule.optional = isOptional(); | 
					
						
							| 
									
										
										
										
											2014-07-03 06:00:06 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-18 20:42:11 +08:00
										 |  |  | 			dependencies.forEach(function(dep) { | 
					
						
							| 
									
										
										
										
											2016-04-11 04:24:13 +08:00
										 |  |  | 				dep.module = dependentModule; | 
					
						
							|  |  |  | 				dependentModule.addReason(module, dep); | 
					
						
							| 
									
										
										
										
											2013-05-18 20:42:11 +08:00
										 |  |  | 			}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-03 19:13:01 +08:00
										 |  |  | 			_this.buildModule(dependentModule, isOptional(), module, dependencies, function(err) { | 
					
						
							| 
									
										
										
										
											2014-06-04 03:03:21 +08:00
										 |  |  | 				if(err) { | 
					
						
							|  |  |  | 					return errorOrWarningAndCallback(err); | 
					
						
							|  |  |  | 				} | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-11-11 06:31:03 +08:00
										 |  |  | 				if(_this.profile) { | 
					
						
							| 
									
										
										
										
											2013-05-08 20:47:13 +08:00
										 |  |  | 					var afterBuilding = +new Date(); | 
					
						
							| 
									
										
										
										
											2016-04-11 04:24:13 +08:00
										 |  |  | 					dependentModule.profile.building = afterBuilding - afterFactory; | 
					
						
							| 
									
										
										
										
											2013-05-08 20:47:13 +08:00
										 |  |  | 				} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-04 03:03:21 +08:00
										 |  |  | 				if(recursive) { | 
					
						
							| 
									
										
										
										
											2016-04-11 04:24:13 +08:00
										 |  |  | 					_this.processModuleDependencies(dependentModule, callback); | 
					
						
							| 
									
										
										
										
											2014-06-04 03:03:21 +08:00
										 |  |  | 				} else { | 
					
						
							| 
									
										
										
										
											2013-10-28 23:21:29 +08:00
										 |  |  | 					return callback(); | 
					
						
							| 
									
										
										
										
											2014-06-04 03:03:21 +08:00
										 |  |  | 				} | 
					
						
							| 
									
										
										
										
											2015-11-11 06:31:03 +08:00
										 |  |  | 			}); | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-11-11 06:31:03 +08:00
										 |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2016-12-05 06:47:19 +08:00
										 |  |  | 	}, function finalCallbackAddModuleDependencies(err) { | 
					
						
							| 
									
										
										
										
											2016-05-17 01:40:37 +08:00
										 |  |  | 		// In V8, the Error objects keep a reference to the functions on the stack. These warnings &
 | 
					
						
							|  |  |  | 		// errors are created inside closures that keep a reference to the Compilation, so errors are
 | 
					
						
							|  |  |  | 		// leaking the Compilation object. Setting _this to null workarounds the following issue in V8.
 | 
					
						
							|  |  |  | 		// https://bugs.chromium.org/p/chromium/issues/detail?id=612191
 | 
					
						
							|  |  |  | 		_this = null; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-04 03:03:21 +08:00
										 |  |  | 		if(err) { | 
					
						
							| 
									
										
										
										
											2014-07-07 22:11:40 +08:00
										 |  |  | 			return callback(err); | 
					
						
							| 
									
										
										
										
											2014-06-04 03:03:21 +08:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-12-05 06:47:19 +08:00
										 |  |  | 		return process.nextTick(callback); | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 	}); | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-13 19:34:00 +08:00
										 |  |  | Compilation.prototype._addModuleChain = function process(context, dependency, onModule, callback) { | 
					
						
							| 
									
										
										
										
											2015-02-05 06:21:22 +08:00
										 |  |  | 	var start = this.profile && +new Date(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 	var errorAndCallback = this.bail ? function errorAndCallback(err) { | 
					
						
							|  |  |  | 		callback(err); | 
					
						
							|  |  |  | 	} : function errorAndCallback(err) { | 
					
						
							| 
									
										
										
										
											2013-05-13 19:34:00 +08:00
										 |  |  | 		err.dependencies = [dependency]; | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 		this.errors.push(err); | 
					
						
							|  |  |  | 		callback(); | 
					
						
							|  |  |  | 	}.bind(this); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-18 16:53:38 +08:00
										 |  |  | 	if(typeof dependency !== "object" || dependency === null || !dependency.constructor) { | 
					
						
							| 
									
										
										
										
											2013-05-13 19:34:00 +08:00
										 |  |  | 		throw new Error("Parameter 'dependency' must be a Dependency"); | 
					
						
							| 
									
										
										
										
											2014-06-04 03:03:21 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-18 16:53:38 +08:00
										 |  |  | 	var moduleFactory = this.dependencyFactories.get(dependency.constructor); | 
					
						
							| 
									
										
										
										
											2014-06-04 03:03:21 +08:00
										 |  |  | 	if(!moduleFactory) { | 
					
						
							| 
									
										
										
										
											2015-10-18 16:53:38 +08:00
										 |  |  | 		throw new Error("No dependency factory available for this dependency type: " + dependency.constructor.name); | 
					
						
							| 
									
										
										
										
											2014-06-04 03:03:21 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-20 18:51:03 +08:00
										 |  |  | 	moduleFactory.create({ | 
					
						
							|  |  |  | 		context: context, | 
					
						
							|  |  |  | 		dependencies: [dependency] | 
					
						
							|  |  |  | 	}, function(err, module) { | 
					
						
							| 
									
										
										
										
											2014-06-04 03:03:21 +08:00
										 |  |  | 		if(err) { | 
					
						
							|  |  |  | 			return errorAndCallback(new EntryModuleNotFoundError(err)); | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-13 19:34:00 +08:00
										 |  |  | 		if(this.profile) { | 
					
						
							| 
									
										
										
										
											2014-06-04 03:03:21 +08:00
										 |  |  | 			if(!module.profile) { | 
					
						
							|  |  |  | 				module.profile = {}; | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2013-05-13 19:34:00 +08:00
										 |  |  | 			var afterFactory = +new Date(); | 
					
						
							|  |  |  | 			module.profile.factory = afterFactory - start; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 		var result = this.addModule(module); | 
					
						
							|  |  |  | 		if(!result) { | 
					
						
							| 
									
										
										
										
											2013-05-13 19:34:00 +08:00
										 |  |  | 			module = this.getModule(module); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			onModule(module); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-02-05 06:21:22 +08:00
										 |  |  | 			if(this.profile) { | 
					
						
							|  |  |  | 				var afterBuilding = +new Date(); | 
					
						
							|  |  |  | 				module.profile.building = afterBuilding - afterFactory; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-13 19:34:00 +08:00
										 |  |  | 			return callback(null, module); | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2013-05-08 19:28:54 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 		if(result instanceof Module) { | 
					
						
							| 
									
										
										
										
											2013-05-13 19:34:00 +08:00
										 |  |  | 			if(this.profile) { | 
					
						
							|  |  |  | 				result.profile = module.profile; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 			module = result; | 
					
						
							| 
									
										
										
										
											2015-05-11 00:43:47 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 			onModule(module); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			moduleReady.call(this); | 
					
						
							|  |  |  | 			return; | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-13 19:34:00 +08:00
										 |  |  | 		onModule(module); | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-03 19:13:01 +08:00
										 |  |  | 		this.buildModule(module, false, null, null, function(err) { | 
					
						
							| 
									
										
										
										
											2015-05-11 00:43:47 +08:00
										 |  |  | 			if(err) { | 
					
						
							|  |  |  | 				return errorAndCallback(err); | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-05-11 00:43:47 +08:00
										 |  |  | 			if(this.profile) { | 
					
						
							|  |  |  | 				var afterBuilding = +new Date(); | 
					
						
							|  |  |  | 				module.profile.building = afterBuilding - afterFactory; | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2013-05-13 19:34:00 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-05-11 00:43:47 +08:00
										 |  |  | 			moduleReady.call(this); | 
					
						
							|  |  |  | 		}.bind(this)); | 
					
						
							| 
									
										
										
										
											2013-05-08 19:28:54 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-13 19:34:00 +08:00
										 |  |  | 		function moduleReady() { | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 			this.processModuleDependencies(module, function(err) { | 
					
						
							| 
									
										
										
										
											2014-06-04 03:03:21 +08:00
										 |  |  | 				if(err) { | 
					
						
							|  |  |  | 					return callback(err); | 
					
						
							|  |  |  | 				} | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-13 19:34:00 +08:00
										 |  |  | 				return callback(null, module); | 
					
						
							| 
									
										
										
										
											2015-04-24 05:55:50 +08:00
										 |  |  | 			}); | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	}.bind(this)); | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-13 19:34:00 +08:00
										 |  |  | Compilation.prototype.addEntry = function process(context, entry, name, callback) { | 
					
						
							| 
									
										
										
										
											2016-09-14 18:04:42 +08:00
										 |  |  | 	var slot = { | 
					
						
							|  |  |  | 		name: name, | 
					
						
							|  |  |  | 		module: null | 
					
						
							|  |  |  | 	}; | 
					
						
							|  |  |  | 	this.preparedChunks.push(slot); | 
					
						
							| 
									
										
										
										
											2013-05-13 19:34:00 +08:00
										 |  |  | 	this._addModuleChain(context, entry, function(module) { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-05-27 05:53:13 +08:00
										 |  |  | 		entry.module = module; | 
					
						
							| 
									
										
										
										
											2013-05-13 19:34:00 +08:00
										 |  |  | 		this.entries.push(module); | 
					
						
							| 
									
										
										
										
											2015-02-05 06:21:04 +08:00
										 |  |  | 		module.issuer = null; | 
					
						
							| 
									
										
										
										
											2013-05-13 19:34:00 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	}.bind(this), function(err, module) { | 
					
						
							| 
									
										
										
										
											2014-06-04 03:03:21 +08:00
										 |  |  | 		if(err) { | 
					
						
							|  |  |  | 			return callback(err); | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2013-05-13 19:34:00 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		if(module) { | 
					
						
							| 
									
										
										
										
											2016-09-14 18:04:42 +08:00
										 |  |  | 			slot.module = module; | 
					
						
							|  |  |  | 		} else { | 
					
						
							|  |  |  | 			var idx = this.preparedChunks.indexOf(slot); | 
					
						
							|  |  |  | 			this.preparedChunks.splice(idx, 1); | 
					
						
							| 
									
										
										
										
											2013-05-13 19:34:00 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		return callback(); | 
					
						
							|  |  |  | 	}.bind(this)); | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Compilation.prototype.prefetch = function process(context, dependency, callback) { | 
					
						
							|  |  |  | 	this._addModuleChain(context, dependency, function(module) { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		module.prefetched = true; | 
					
						
							| 
									
										
										
										
											2015-02-05 06:21:04 +08:00
										 |  |  | 		module.issuer = null; | 
					
						
							| 
									
										
										
										
											2013-05-13 19:34:00 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	}, callback); | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-07-29 06:13:25 +08:00
										 |  |  | Compilation.prototype.rebuildModule = function(module, thisCallback) { | 
					
						
							| 
									
										
										
										
											2014-07-19 20:32:48 +08:00
										 |  |  | 	if(module.variables.length || module.blocks.length) | 
					
						
							|  |  |  | 		throw new Error("Cannot rebuild a complex module with variables or blocks"); | 
					
						
							| 
									
										
										
										
											2014-07-29 06:13:25 +08:00
										 |  |  | 	if(module.rebuilding) { | 
					
						
							|  |  |  | 		return module.rebuilding.push(thisCallback); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	var rebuilding = module.rebuilding = [thisCallback]; | 
					
						
							| 
									
										
										
										
											2015-07-08 20:15:21 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-07-29 06:13:25 +08:00
										 |  |  | 	function callback(err) { | 
					
						
							|  |  |  | 		module.rebuilding = undefined; | 
					
						
							|  |  |  | 		rebuilding.forEach(function(cb) { | 
					
						
							|  |  |  | 			cb(err); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2014-07-19 20:32:48 +08:00
										 |  |  | 	var deps = module.dependencies.slice(); | 
					
						
							| 
									
										
										
										
											2016-07-03 19:13:01 +08:00
										 |  |  | 	this.buildModule(module, false, module, null, function(err) { | 
					
						
							| 
									
										
										
										
											2014-07-19 20:32:48 +08:00
										 |  |  | 		if(err) return callback(err); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		this.processModuleDependencies(module, function(err) { | 
					
						
							|  |  |  | 			if(err) return callback(err); | 
					
						
							|  |  |  | 			deps.forEach(function(d) { | 
					
						
							|  |  |  | 				if(d.module && d.module.removeReason(module, d)) { | 
					
						
							|  |  |  | 					module.chunks.forEach(function(chunk) { | 
					
						
							|  |  |  | 						if(!d.module.hasReasonForChunk(chunk)) { | 
					
						
							|  |  |  | 							if(d.module.removeChunk(chunk)) { | 
					
						
							|  |  |  | 								this.removeChunkFromDependencies(d.module, chunk); | 
					
						
							|  |  |  | 							} | 
					
						
							|  |  |  | 						} | 
					
						
							|  |  |  | 					}, this); | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			}, this); | 
					
						
							|  |  |  | 			callback(); | 
					
						
							|  |  |  | 		}.bind(this)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	}.bind(this)); | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-13 17:03:14 +08:00
										 |  |  | Compilation.prototype.finish = function finish() { | 
					
						
							| 
									
										
										
										
											2016-12-05 06:47:19 +08:00
										 |  |  | 	this.applyPlugins1("finish-modules", this.modules); | 
					
						
							| 
									
										
										
										
											2016-06-24 07:51:52 +08:00
										 |  |  | 	this.modules.forEach(function(m) { | 
					
						
							|  |  |  | 		this.reportDependencyWarnings(m, [m]); | 
					
						
							|  |  |  | 	}, this); | 
					
						
							| 
									
										
										
										
											2016-07-13 17:03:14 +08:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Compilation.prototype.unseal = function unseal() { | 
					
						
							| 
									
										
										
										
											2016-12-05 06:47:19 +08:00
										 |  |  | 	this.applyPlugins0("unseal"); | 
					
						
							| 
									
										
										
										
											2016-07-13 17:03:14 +08:00
										 |  |  | 	this.chunks.length = 0; | 
					
						
							|  |  |  | 	this.namedChunks = {}; | 
					
						
							|  |  |  | 	this.additionalChunkAssets.length = 0; | 
					
						
							|  |  |  | 	this.assets = {}; | 
					
						
							|  |  |  | 	this.modules.forEach(function(module) { | 
					
						
							|  |  |  | 		module.unseal(); | 
					
						
							|  |  |  | 	}); | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Compilation.prototype.seal = function seal(callback) { | 
					
						
							| 
									
										
										
										
											2016-10-18 02:26:22 +08:00
										 |  |  | 	var self = this; | 
					
						
							| 
									
										
										
										
											2016-12-05 06:47:19 +08:00
										 |  |  | 	self.applyPlugins0("seal"); | 
					
						
							| 
									
										
										
										
											2016-10-18 02:26:22 +08:00
										 |  |  | 	self.nextFreeModuleIndex = 0; | 
					
						
							|  |  |  | 	self.nextFreeModuleIndex2 = 0; | 
					
						
							|  |  |  | 	self.preparedChunks.forEach(function(preparedChunk) { | 
					
						
							| 
									
										
										
										
											2013-05-22 16:12:53 +08:00
										 |  |  | 		var module = preparedChunk.module; | 
					
						
							| 
									
										
										
										
											2016-10-18 02:26:22 +08:00
										 |  |  | 		var chunk = self.addChunk(preparedChunk.name, module); | 
					
						
							| 
									
										
										
										
											2016-12-01 12:37:14 +08:00
										 |  |  | 		var entrypoint = self.entrypoints[chunk.name] = new Entrypoint(chunk.name); | 
					
						
							| 
									
										
										
										
											2016-07-13 17:03:14 +08:00
										 |  |  | 		entrypoint.unshiftChunk(chunk); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-22 16:12:53 +08:00
										 |  |  | 		chunk.addModule(module); | 
					
						
							|  |  |  | 		module.addChunk(chunk); | 
					
						
							| 
									
										
										
										
											2015-06-13 17:45:28 +08:00
										 |  |  | 		chunk.entryModule = module; | 
					
						
							| 
									
										
										
										
											2016-12-05 06:47:19 +08:00
										 |  |  | 		self.assignIndex(module); | 
					
						
							| 
									
										
										
										
											2016-12-14 19:03:24 +08:00
										 |  |  | 		self.assignDepth(module); | 
					
						
							| 
									
										
										
										
											2016-10-18 02:26:22 +08:00
										 |  |  | 		self.processDependenciesBlockForChunk(module, chunk); | 
					
						
							|  |  |  | 	}, self); | 
					
						
							|  |  |  | 	self.sortModules(self.modules); | 
					
						
							| 
									
										
										
										
											2016-12-05 06:47:19 +08:00
										 |  |  | 	self.applyPlugins0("optimize"); | 
					
						
							| 
									
										
										
										
											2013-05-31 18:22:40 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-12-05 06:47:19 +08:00
										 |  |  | 	while(self.applyPluginsBailResult1("optimize-modules-basic", self.modules) || | 
					
						
							|  |  |  | 		self.applyPluginsBailResult1("optimize-modules", self.modules) || | 
					
						
							|  |  |  | 		self.applyPluginsBailResult1("optimize-modules-advanced", self.modules)); // eslint-disable-line no-extra-semi
 | 
					
						
							|  |  |  | 	self.applyPlugins1("after-optimize-modules", self.modules); | 
					
						
							| 
									
										
										
										
											2013-05-31 18:22:40 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-12-05 06:47:19 +08:00
										 |  |  | 	while(self.applyPluginsBailResult1("optimize-chunks-basic", self.chunks) || | 
					
						
							|  |  |  | 		self.applyPluginsBailResult1("optimize-chunks", self.chunks) || | 
					
						
							|  |  |  | 		self.applyPluginsBailResult1("optimize-chunks-advanced", self.chunks)); // eslint-disable-line no-extra-semi
 | 
					
						
							|  |  |  | 	self.applyPlugins1("after-optimize-chunks", self.chunks); | 
					
						
							| 
									
										
										
										
											2013-05-31 18:22:40 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-12-05 06:47:19 +08:00
										 |  |  | 	self.applyPluginsAsyncSeries("optimize-tree", self.chunks, self.modules, function sealPart2(err) { | 
					
						
							| 
									
										
										
										
											2014-06-04 03:03:21 +08:00
										 |  |  | 		if(err) { | 
					
						
							|  |  |  | 			return callback(err); | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2014-01-29 17:13:28 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-12-05 06:47:19 +08:00
										 |  |  | 		self.applyPlugins2("after-optimize-tree", self.chunks, self.modules); | 
					
						
							| 
									
										
										
										
											2015-04-21 01:39:02 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-18 02:26:22 +08:00
										 |  |  | 		var shouldRecord = self.applyPluginsBailResult("should-record") !== false; | 
					
						
							| 
									
										
										
										
											2014-09-03 20:16:17 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-18 02:26:22 +08:00
										 |  |  | 		self.sortItemsBeforeIds(); | 
					
						
							| 
									
										
										
										
											2016-07-13 17:03:14 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-12-05 06:47:19 +08:00
										 |  |  | 		self.applyPlugins2("revive-modules", self.modules, self.records); | 
					
						
							|  |  |  | 		self.applyPlugins1("optimize-module-order", self.modules); | 
					
						
							|  |  |  | 		self.applyPlugins1("advanced-optimize-module-order", self.modules); | 
					
						
							|  |  |  | 		self.applyPlugins1("before-module-ids", self.modules); | 
					
						
							|  |  |  | 		self.applyPlugins1("module-ids", self.modules); | 
					
						
							| 
									
										
										
										
											2016-10-18 02:26:22 +08:00
										 |  |  | 		self.applyModuleIds(); | 
					
						
							| 
									
										
										
										
											2016-12-05 06:47:19 +08:00
										 |  |  | 		self.applyPlugins1("optimize-module-ids", self.modules); | 
					
						
							|  |  |  | 		self.applyPlugins1("after-optimize-module-ids", self.modules); | 
					
						
							| 
									
										
										
										
											2016-07-13 17:03:14 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-18 02:26:22 +08:00
										 |  |  | 		self.sortItemsWithModuleIds(); | 
					
						
							| 
									
										
										
										
											2014-01-29 17:13:28 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-12-05 06:47:19 +08:00
										 |  |  | 		self.applyPlugins2("revive-chunks", self.chunks, self.records); | 
					
						
							|  |  |  | 		self.applyPlugins1("optimize-chunk-order", self.chunks); | 
					
						
							|  |  |  | 		self.applyPlugins1("before-chunk-ids", self.chunks); | 
					
						
							| 
									
										
										
										
											2016-10-18 02:26:22 +08:00
										 |  |  | 		self.applyChunkIds(); | 
					
						
							| 
									
										
										
										
											2016-12-05 06:47:19 +08:00
										 |  |  | 		self.applyPlugins1("optimize-chunk-ids", self.chunks); | 
					
						
							|  |  |  | 		self.applyPlugins1("after-optimize-chunk-ids", self.chunks); | 
					
						
							| 
									
										
										
										
											2016-07-13 17:03:14 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-12-05 06:47:19 +08:00
										 |  |  | 		self.sortItemsWithChunkIds(); | 
					
						
							| 
									
										
										
										
											2016-07-13 17:03:14 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		if(shouldRecord) | 
					
						
							| 
									
										
										
										
											2016-12-05 06:47:19 +08:00
										 |  |  | 			self.applyPlugins2("record-modules", self.modules, self.records); | 
					
						
							| 
									
										
										
										
											2014-09-03 20:16:17 +08:00
										 |  |  | 		if(shouldRecord) | 
					
						
							| 
									
										
										
										
											2016-12-05 06:47:19 +08:00
										 |  |  | 			self.applyPlugins2("record-chunks", self.chunks, self.records); | 
					
						
							| 
									
										
										
										
											2014-01-29 17:13:28 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-12-05 06:47:19 +08:00
										 |  |  | 		self.applyPlugins0("before-hash"); | 
					
						
							| 
									
										
										
										
											2016-10-18 02:26:22 +08:00
										 |  |  | 		self.createHash(); | 
					
						
							| 
									
										
										
										
											2016-12-05 06:47:19 +08:00
										 |  |  | 		self.applyPlugins0("after-hash"); | 
					
						
							| 
									
										
										
										
											2016-07-13 17:03:14 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		if(shouldRecord) | 
					
						
							| 
									
										
										
										
											2016-12-05 06:47:19 +08:00
										 |  |  | 			self.applyPlugins1("record-hash", self.records); | 
					
						
							| 
									
										
										
										
											2016-07-13 17:03:14 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-12-05 06:47:19 +08:00
										 |  |  | 		self.applyPlugins0("before-module-assets"); | 
					
						
							| 
									
										
										
										
											2016-10-18 02:26:22 +08:00
										 |  |  | 		self.createModuleAssets(); | 
					
						
							|  |  |  | 		if(self.applyPluginsBailResult("should-generate-chunk-assets") !== false) { | 
					
						
							| 
									
										
										
										
											2016-12-05 06:47:19 +08:00
										 |  |  | 			self.applyPlugins0("before-chunk-assets"); | 
					
						
							| 
									
										
										
										
											2016-10-18 02:26:22 +08:00
										 |  |  | 			self.createChunkAssets(); | 
					
						
							| 
									
										
										
										
											2015-01-30 07:46:52 +08:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2016-12-05 06:47:19 +08:00
										 |  |  | 		self.applyPlugins1("additional-chunk-assets", self.chunks); | 
					
						
							| 
									
										
										
										
											2016-10-18 02:26:22 +08:00
										 |  |  | 		self.summarizeDependencies(); | 
					
						
							| 
									
										
										
										
											2014-09-03 20:16:17 +08:00
										 |  |  | 		if(shouldRecord) | 
					
						
							| 
									
										
										
										
											2016-12-05 06:47:19 +08:00
										 |  |  | 			self.applyPlugins2("record", self, self.records); | 
					
						
							| 
									
										
										
										
											2014-01-29 17:13:28 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-18 02:26:22 +08:00
										 |  |  | 		self.applyPluginsAsync("additional-assets", function(err) { | 
					
						
							| 
									
										
										
										
											2014-06-04 03:03:21 +08:00
										 |  |  | 			if(err) { | 
					
						
							|  |  |  | 				return callback(err); | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2016-10-18 02:26:22 +08:00
										 |  |  | 			self.applyPluginsAsync("optimize-chunk-assets", self.chunks, function(err) { | 
					
						
							| 
									
										
										
										
											2014-06-04 03:03:21 +08:00
										 |  |  | 				if(err) { | 
					
						
							|  |  |  | 					return callback(err); | 
					
						
							|  |  |  | 				} | 
					
						
							| 
									
										
										
										
											2016-12-05 06:47:19 +08:00
										 |  |  | 				self.applyPlugins1("after-optimize-chunk-assets", self.chunks); | 
					
						
							| 
									
										
										
										
											2016-10-18 02:26:22 +08:00
										 |  |  | 				self.applyPluginsAsync("optimize-assets", self.assets, function(err) { | 
					
						
							| 
									
										
										
										
											2014-06-04 03:03:21 +08:00
										 |  |  | 					if(err) { | 
					
						
							|  |  |  | 						return callback(err); | 
					
						
							|  |  |  | 					} | 
					
						
							| 
									
										
										
										
											2016-12-05 06:47:19 +08:00
										 |  |  | 					self.applyPlugins1("after-optimize-assets", self.assets); | 
					
						
							| 
									
										
										
										
											2016-10-18 02:26:22 +08:00
										 |  |  | 					if(self.applyPluginsBailResult("need-additional-seal")) { | 
					
						
							|  |  |  | 						self.unseal(); | 
					
						
							|  |  |  | 						return self.seal(callback); | 
					
						
							| 
									
										
										
										
											2016-07-13 17:03:14 +08:00
										 |  |  | 					} | 
					
						
							| 
									
										
										
										
											2016-10-18 02:26:22 +08:00
										 |  |  | 					return self.applyPluginsAsync("after-seal", callback); | 
					
						
							|  |  |  | 				}); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 	}); | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-05-11 00:43:47 +08:00
										 |  |  | Compilation.prototype.sortModules = function sortModules(modules) { | 
					
						
							|  |  |  | 	modules.sort(function(a, b) { | 
					
						
							|  |  |  | 		if(a.index < b.index) return -1; | 
					
						
							|  |  |  | 		if(a.index > b.index) return 1; | 
					
						
							|  |  |  | 		return 0; | 
					
						
							|  |  |  | 	}); | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-24 07:51:52 +08:00
										 |  |  | Compilation.prototype.reportDependencyWarnings = function reportDependencyWarnings(module, blocks) { | 
					
						
							|  |  |  | 	var _this = this; | 
					
						
							|  |  |  | 	blocks.forEach(function(block) { | 
					
						
							|  |  |  | 		block.dependencies.forEach(function(d) { | 
					
						
							|  |  |  | 			var warnings = d.getWarnings(); | 
					
						
							|  |  |  | 			if(warnings) { | 
					
						
							|  |  |  | 				warnings.forEach(function(w) { | 
					
						
							|  |  |  | 					var warning = new ModuleDependencyWarning(module, w, d.loc); | 
					
						
							|  |  |  | 					_this.warnings.push(warning); | 
					
						
							|  |  |  | 				}); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 		_this.reportDependencyWarnings(module, block.blocks); | 
					
						
							|  |  |  | 	}); | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-01-23 22:31:40 +08:00
										 |  |  | Compilation.prototype.addChunk = function addChunk(name, module, loc) { | 
					
						
							| 
									
										
										
										
											2014-06-04 03:03:21 +08:00
										 |  |  | 	var chunk; | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 	if(name) { | 
					
						
							| 
									
										
										
										
											2014-01-24 20:32:58 +08:00
										 |  |  | 		if(Object.prototype.hasOwnProperty.call(this.namedChunks, name)) { | 
					
						
							| 
									
										
										
										
											2014-06-04 03:03:21 +08:00
										 |  |  | 			chunk = this.namedChunks[name]; | 
					
						
							|  |  |  | 			if(module) { | 
					
						
							|  |  |  | 				chunk.addOrigin(module, loc); | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2014-01-24 20:32:58 +08:00
										 |  |  | 			return chunk; | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2014-06-04 03:03:21 +08:00
										 |  |  | 	chunk = new Chunk(name, module, loc); | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 	this.chunks.push(chunk); | 
					
						
							|  |  |  | 	if(name) { | 
					
						
							|  |  |  | 		this.namedChunks[name] = chunk; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return chunk; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-12-05 06:47:19 +08:00
										 |  |  | Compilation.prototype.assignIndex = function assignIndex(module) { | 
					
						
							|  |  |  | 	var _this = this; | 
					
						
							| 
									
										
										
										
											2016-12-05 06:47:19 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-12-05 06:47:19 +08:00
										 |  |  | 	function assignIndexToModule(module) { | 
					
						
							|  |  |  | 		// enter module
 | 
					
						
							|  |  |  | 		if(typeof module.index !== "number") { | 
					
						
							|  |  |  | 			module.index = _this.nextFreeModuleIndex++; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			queue.push(function() { | 
					
						
							|  |  |  | 				// leave module
 | 
					
						
							|  |  |  | 				module.index2 = _this.nextFreeModuleIndex2++; | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			// enter it as block
 | 
					
						
							|  |  |  | 			assignIndexToDependencyBlock(module); | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2015-05-11 00:43:47 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2016-12-05 06:47:19 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-12-05 06:47:19 +08:00
										 |  |  | 	function assignIndexToDependency(dependency) { | 
					
						
							|  |  |  | 		if(dependency.module) { | 
					
						
							|  |  |  | 			queue.push(function() { | 
					
						
							|  |  |  | 				assignIndexToModule(dependency.module); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2015-05-11 00:43:47 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2016-12-05 06:47:19 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-12-05 06:47:19 +08:00
										 |  |  | 	function assignIndexToDependencyBlock(block) { | 
					
						
							|  |  |  | 		var allDependencies = []; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		function iteratorDependency(d) { | 
					
						
							|  |  |  | 			allDependencies.push(d); | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2016-12-05 06:47:19 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-12-05 06:47:19 +08:00
										 |  |  | 		function iteratorBlock(b) { | 
					
						
							|  |  |  | 			queue.push(function() { | 
					
						
							|  |  |  | 				assignIndexToDependencyBlock(b); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if(block.variables) { | 
					
						
							|  |  |  | 			block.variables.forEach(function(v) { | 
					
						
							|  |  |  | 				v.dependencies.forEach(iteratorDependency); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		if(block.dependencies) { | 
					
						
							|  |  |  | 			block.dependencies.forEach(iteratorDependency); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		if(block.blocks) { | 
					
						
							|  |  |  | 			block.blocks.slice().reverse().forEach(iteratorBlock, this); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		allDependencies.reverse(); | 
					
						
							|  |  |  | 		allDependencies.forEach(function(d) { | 
					
						
							|  |  |  | 			queue.push(function() { | 
					
						
							|  |  |  | 				assignIndexToDependency(d); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	var queue = [function() { | 
					
						
							|  |  |  | 		assignIndexToModule(module); | 
					
						
							|  |  |  | 	}]; | 
					
						
							|  |  |  | 	while(queue.length) { | 
					
						
							|  |  |  | 		queue.pop()(); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-12-14 19:03:24 +08:00
										 |  |  | Compilation.prototype.assignDepth = function assignDepth(module) { | 
					
						
							|  |  |  | 	function assignDepthToModule(module, depth) { | 
					
						
							|  |  |  | 		// enter module
 | 
					
						
							|  |  |  | 		if(typeof module.depth === "number" && module.depth <= depth) return; | 
					
						
							|  |  |  | 		module.depth = depth; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		// enter it as block
 | 
					
						
							|  |  |  | 		assignDepthToDependencyBlock(module, depth + 1); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	function assignDepthToDependency(dependency, depth) { | 
					
						
							|  |  |  | 		if(dependency.module) { | 
					
						
							|  |  |  | 			queue.push(function() { | 
					
						
							|  |  |  | 				assignDepthToModule(dependency.module, depth); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	function assignDepthToDependencyBlock(block, depth) { | 
					
						
							|  |  |  | 		function iteratorDependency(d) { | 
					
						
							|  |  |  | 			assignDepthToDependency(d, depth); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		function iteratorBlock(b) { | 
					
						
							|  |  |  | 			assignDepthToDependencyBlock(b, depth); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if(block.variables) { | 
					
						
							|  |  |  | 			block.variables.forEach(function(v) { | 
					
						
							|  |  |  | 				v.dependencies.forEach(iteratorDependency); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		if(block.dependencies) { | 
					
						
							|  |  |  | 			block.dependencies.forEach(iteratorDependency); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		if(block.blocks) { | 
					
						
							|  |  |  | 			block.blocks.forEach(iteratorBlock, this); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	var queue = [function() { | 
					
						
							|  |  |  | 		assignDepthToModule(module, 0); | 
					
						
							|  |  |  | 	}]; | 
					
						
							|  |  |  | 	while(queue.length) { | 
					
						
							|  |  |  | 		queue.pop()(); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-12-05 06:47:19 +08:00
										 |  |  | Compilation.prototype.processDependenciesBlockForChunk = function processDependenciesBlockForChunk(block, chunk) { | 
					
						
							| 
									
										
										
										
											2016-12-05 06:47:19 +08:00
										 |  |  | 	var queue = [ | 
					
						
							|  |  |  | 		[block, chunk] | 
					
						
							|  |  |  | 	]; | 
					
						
							| 
									
										
										
										
											2016-12-05 06:47:19 +08:00
										 |  |  | 	while(queue.length) { | 
					
						
							|  |  |  | 		var queueItem = queue.pop(); | 
					
						
							|  |  |  | 		block = queueItem[0]; | 
					
						
							|  |  |  | 		chunk = queueItem[1]; | 
					
						
							|  |  |  | 		if(block.variables) { | 
					
						
							|  |  |  | 			block.variables.forEach(function(v) { | 
					
						
							|  |  |  | 				v.dependencies.forEach(iteratorDependency, this); | 
					
						
							|  |  |  | 			}, this); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		if(block.dependencies) { | 
					
						
							|  |  |  | 			block.dependencies.forEach(iteratorDependency, this); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		if(block.blocks) { | 
					
						
							|  |  |  | 			block.blocks.forEach(iteratorBlock, this); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	function iteratorBlock(b) { | 
					
						
							|  |  |  | 		var c; | 
					
						
							|  |  |  | 		if(!b.chunks) { | 
					
						
							|  |  |  | 			c = this.addChunk(b.chunkName, b.module, b.loc); | 
					
						
							|  |  |  | 			b.chunks = [c]; | 
					
						
							|  |  |  | 			c.addBlock(b); | 
					
						
							|  |  |  | 		} else { | 
					
						
							|  |  |  | 			c = b.chunks[0]; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		chunk.addChunk(c); | 
					
						
							|  |  |  | 		c.addParent(chunk); | 
					
						
							|  |  |  | 		queue.push([b, c]); | 
					
						
							| 
									
										
										
										
											2014-11-02 19:17:05 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2015-07-08 20:15:21 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 	function iteratorDependency(d) { | 
					
						
							| 
									
										
										
										
											2015-05-11 00:43:47 +08:00
										 |  |  | 		if(!d.module) { | 
					
						
							|  |  |  | 			return; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		if(d.weak) { | 
					
						
							| 
									
										
										
										
											2014-06-04 03:03:21 +08:00
										 |  |  | 			return; | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 		if(chunk.addModule(d.module)) { | 
					
						
							|  |  |  | 			d.module.addChunk(chunk); | 
					
						
							| 
									
										
										
										
											2016-12-05 06:47:19 +08:00
										 |  |  | 			queue.push([d.module, chunk]); | 
					
						
							| 
									
										
										
										
											2015-05-11 00:43:47 +08:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-07-19 20:32:48 +08:00
										 |  |  | Compilation.prototype.removeChunkFromDependencies = function removeChunkFromDependencies(block, chunk) { | 
					
						
							|  |  |  | 	block.blocks.forEach(function(b) { | 
					
						
							| 
									
										
										
										
											2015-01-02 04:58:27 +08:00
										 |  |  | 		b.chunks.forEach(function(c) { | 
					
						
							|  |  |  | 			chunk.removeChunk(c); | 
					
						
							|  |  |  | 			c.removeParent(chunk); | 
					
						
							|  |  |  | 			this.removeChunkFromDependencies(b, c); | 
					
						
							|  |  |  | 		}, this); | 
					
						
							| 
									
										
										
										
											2014-07-19 20:32:48 +08:00
										 |  |  | 	}, this); | 
					
						
							| 
									
										
										
										
											2015-07-08 20:15:21 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-07-19 20:32:48 +08:00
										 |  |  | 	function iteratorDependency(d) { | 
					
						
							|  |  |  | 		if(!d.module) { | 
					
						
							|  |  |  | 			return; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		if(!d.module.hasReasonForChunk(chunk)) { | 
					
						
							|  |  |  | 			if(d.module.removeChunk(chunk)) { | 
					
						
							|  |  |  | 				this.removeChunkFromDependencies(d.module, chunk); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	block.dependencies.forEach(iteratorDependency, this); | 
					
						
							|  |  |  | 	block.variables.forEach(function(v) { | 
					
						
							|  |  |  | 		v.dependencies.forEach(iteratorDependency, this); | 
					
						
							|  |  |  | 	}, this); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | Compilation.prototype.applyModuleIds = function applyModuleIds() { | 
					
						
							| 
									
										
										
										
											2016-07-18 06:41:26 +08:00
										 |  |  | 	var unusedIds = []; | 
					
						
							|  |  |  | 	var nextFreeModuleId = 0; | 
					
						
							| 
									
										
										
										
											2016-09-14 18:04:42 +08:00
										 |  |  | 	var usedIds = []; | 
					
						
							|  |  |  | 	var usedIdMap = {}; | 
					
						
							| 
									
										
										
										
											2016-07-18 06:41:26 +08:00
										 |  |  | 	if(this.usedModuleIds) { | 
					
						
							| 
									
										
										
										
											2016-09-14 18:04:42 +08:00
										 |  |  | 		Object.keys(this.usedModuleIds).forEach(function(key) { | 
					
						
							|  |  |  | 			var id = this.usedModuleIds[key]; | 
					
						
							|  |  |  | 			if(typeof usedIdMap[id] === "undefined") { | 
					
						
							|  |  |  | 				usedIds.push(id); | 
					
						
							|  |  |  | 				usedIdMap[id] = id; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		}, this); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	this.modules.forEach(function(module) { | 
					
						
							|  |  |  | 		if(module.id !== null && typeof usedIdMap[module.id] === "undefined") { | 
					
						
							|  |  |  | 			usedIds.push(module.id); | 
					
						
							|  |  |  | 			usedIdMap[module.id] = module.id; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	}); | 
					
						
							|  |  |  | 	if(usedIds.length > 0) { | 
					
						
							| 
									
										
										
										
											2016-07-18 06:41:26 +08:00
										 |  |  | 		var usedNumberIds = usedIds.filter(function(id) { | 
					
						
							|  |  |  | 			return typeof id === "number"; | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 		nextFreeModuleId = usedNumberIds.reduce(function(a, b) { | 
					
						
							|  |  |  | 			return Math.max(a, b); | 
					
						
							|  |  |  | 		}, -1) + 1; | 
					
						
							|  |  |  | 		for(var i = 0; i < nextFreeModuleId; i++) { | 
					
						
							| 
									
										
										
										
											2016-09-14 18:04:42 +08:00
										 |  |  | 			if(usedIdMap[i] !== i) | 
					
						
							| 
									
										
										
										
											2016-07-18 06:41:26 +08:00
										 |  |  | 				unusedIds.push(i); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		unusedIds.reverse(); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 	this.modules.forEach(function(module) { | 
					
						
							| 
									
										
										
										
											2013-05-08 19:28:54 +08:00
										 |  |  | 		if(module.id === null) { | 
					
						
							| 
									
										
										
										
											2016-07-18 06:41:26 +08:00
										 |  |  | 			if(unusedIds.length > 0) | 
					
						
							|  |  |  | 				module.id = unusedIds.pop(); | 
					
						
							|  |  |  | 			else | 
					
						
							|  |  |  | 				module.id = nextFreeModuleId++; | 
					
						
							| 
									
										
										
										
											2013-05-08 19:28:54 +08:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2013-05-31 18:22:40 +08:00
										 |  |  | 	}, this); | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Compilation.prototype.applyChunkIds = function applyChunkIds() { | 
					
						
							| 
									
										
										
										
											2016-07-18 06:41:26 +08:00
										 |  |  | 	var unusedIds = []; | 
					
						
							|  |  |  | 	var nextFreeChunkId = 0; | 
					
						
							|  |  |  | 	if(this.usedChunkIds) { | 
					
						
							|  |  |  | 		var usedIds = Object.keys(this.usedChunkIds).map(function(key) { | 
					
						
							|  |  |  | 			return this.usedChunkIds[key]; | 
					
						
							|  |  |  | 		}, this).sort(); | 
					
						
							|  |  |  | 		var usedNumberIds = usedIds.filter(function(id) { | 
					
						
							|  |  |  | 			return typeof id === "number"; | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 		nextFreeChunkId = usedNumberIds.reduce(function(a, b) { | 
					
						
							|  |  |  | 			return Math.max(a, b); | 
					
						
							|  |  |  | 		}, -1) + 1; | 
					
						
							|  |  |  | 		for(var i = 0; i < nextFreeChunkId; i++) { | 
					
						
							|  |  |  | 			if(this.usedChunkIds[i] !== i) | 
					
						
							|  |  |  | 				unusedIds.push(i); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		unusedIds.reverse(); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 	this.chunks.forEach(function(chunk) { | 
					
						
							| 
									
										
										
										
											2013-05-09 05:01:25 +08:00
										 |  |  | 		if(chunk.id === null) { | 
					
						
							| 
									
										
										
										
											2016-07-18 06:41:26 +08:00
										 |  |  | 			if(unusedIds.length > 0) | 
					
						
							|  |  |  | 				chunk.id = unusedIds.pop(); | 
					
						
							|  |  |  | 			else | 
					
						
							|  |  |  | 				chunk.id = nextFreeChunkId++; | 
					
						
							| 
									
										
										
										
											2013-05-09 05:01:25 +08:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2014-06-04 03:03:21 +08:00
										 |  |  | 		if(!chunk.ids) { | 
					
						
							| 
									
										
										
										
											2013-02-24 09:05:55 +08:00
										 |  |  | 			chunk.ids = [chunk.id]; | 
					
						
							| 
									
										
										
										
											2014-06-04 03:03:21 +08:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2013-05-09 05:01:25 +08:00
										 |  |  | 	}, this); | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-13 17:03:14 +08:00
										 |  |  | function byId(a, b) { | 
					
						
							| 
									
										
										
										
											2016-09-14 18:04:42 +08:00
										 |  |  | 	if(a.id < b.id) return -1; | 
					
						
							|  |  |  | 	if(a.id > b.id) return 1; | 
					
						
							|  |  |  | 	return 0; | 
					
						
							| 
									
										
										
										
											2016-07-13 17:03:14 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Compilation.prototype.sortItemsBeforeIds = function sortItemsBeforeIds() { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Compilation.prototype.sortItemsWithModuleIds = function sortItemsWithModuleIds() { | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 	this.modules.sort(byId); | 
					
						
							|  |  |  | 	this.modules.forEach(function(module) { | 
					
						
							| 
									
										
										
										
											2016-07-13 17:03:14 +08:00
										 |  |  | 		module.sortItems(); | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 	}); | 
					
						
							|  |  |  | 	this.chunks.forEach(function(chunk) { | 
					
						
							| 
									
										
										
										
											2016-07-13 17:03:14 +08:00
										 |  |  | 		chunk.sortItems(); | 
					
						
							|  |  |  | 	}); | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-12-05 06:47:19 +08:00
										 |  |  | Compilation.prototype.sortItemsWithChunkIds = function sortItemsWithChunkIds() { | 
					
						
							| 
									
										
										
										
											2016-07-13 17:03:14 +08:00
										 |  |  | 	this.chunks.sort(byId); | 
					
						
							|  |  |  | 	this.modules.forEach(function(module) { | 
					
						
							|  |  |  | 		module.sortItems(); | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 	}); | 
					
						
							| 
									
										
										
										
											2016-12-05 06:47:19 +08:00
										 |  |  | 	this.chunks.forEach(function(chunk) { | 
					
						
							|  |  |  | 		chunk.sortItems(); | 
					
						
							|  |  |  | 	}); | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Compilation.prototype.summarizeDependencies = function summarizeDependencies() { | 
					
						
							|  |  |  | 	function filterDups(array) { | 
					
						
							|  |  |  | 		var newArray = []; | 
					
						
							|  |  |  | 		for(var i = 0; i < array.length; i++) { | 
					
						
							| 
									
										
										
										
											2015-04-24 05:55:50 +08:00
										 |  |  | 			if(i === 0 || array[i - 1] !== array[i]) | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 				newArray.push(array[i]); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		return newArray; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2016-09-14 18:04:42 +08:00
										 |  |  | 	this.fileDependencies = (this.compilationDependencies || []).slice(); | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 	this.contextDependencies = []; | 
					
						
							| 
									
										
										
										
											2015-01-18 04:55:44 +08:00
										 |  |  | 	this.missingDependencies = []; | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 	this.children.forEach(function(child) { | 
					
						
							|  |  |  | 		this.fileDependencies = this.fileDependencies.concat(child.fileDependencies); | 
					
						
							|  |  |  | 		this.contextDependencies = this.contextDependencies.concat(child.contextDependencies); | 
					
						
							| 
									
										
										
										
											2015-01-18 04:55:44 +08:00
										 |  |  | 		this.missingDependencies = this.missingDependencies.concat(child.missingDependencies); | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 	}.bind(this)); | 
					
						
							|  |  |  | 	this.modules.forEach(function(module) { | 
					
						
							|  |  |  | 		if(module.fileDependencies) { | 
					
						
							|  |  |  | 			module.fileDependencies.forEach(function(item) { | 
					
						
							|  |  |  | 				this.fileDependencies.push(item); | 
					
						
							|  |  |  | 			}, this); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		if(module.contextDependencies) { | 
					
						
							|  |  |  | 			module.contextDependencies.forEach(function(item) { | 
					
						
							|  |  |  | 				this.contextDependencies.push(item); | 
					
						
							|  |  |  | 			}, this); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	}, this); | 
					
						
							| 
									
										
										
										
											2015-01-18 04:55:44 +08:00
										 |  |  | 	this.errors.forEach(function(error) { | 
					
						
							|  |  |  | 		if(Array.isArray(error.missing)) { | 
					
						
							|  |  |  | 			error.missing.forEach(function(item) { | 
					
						
							|  |  |  | 				this.missingDependencies.push(item); | 
					
						
							| 
									
										
										
										
											2015-04-24 05:55:50 +08:00
										 |  |  | 			}, this); | 
					
						
							| 
									
										
										
										
											2015-01-18 04:55:44 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	}, this); | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 	this.fileDependencies.sort(); | 
					
						
							|  |  |  | 	this.fileDependencies = filterDups(this.fileDependencies); | 
					
						
							|  |  |  | 	this.contextDependencies.sort(); | 
					
						
							|  |  |  | 	this.contextDependencies = filterDups(this.contextDependencies); | 
					
						
							| 
									
										
										
										
											2015-01-18 04:55:44 +08:00
										 |  |  | 	this.missingDependencies.sort(); | 
					
						
							|  |  |  | 	this.missingDependencies = filterDups(this.missingDependencies); | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-07-01 19:59:02 +08:00
										 |  |  | Compilation.prototype.createHash = function createHash() { | 
					
						
							|  |  |  | 	var outputOptions = this.outputOptions; | 
					
						
							| 
									
										
										
										
											2013-05-21 17:08:08 +08:00
										 |  |  | 	var hashFunction = outputOptions.hashFunction; | 
					
						
							|  |  |  | 	var hashDigest = outputOptions.hashDigest; | 
					
						
							|  |  |  | 	var hashDigestLength = outputOptions.hashDigestLength; | 
					
						
							| 
									
										
										
										
											2013-07-11 05:20:07 +08:00
										 |  |  | 	var hash = require("crypto").createHash(hashFunction); | 
					
						
							| 
									
										
										
										
											2016-06-05 02:03:42 +08:00
										 |  |  | 	if(outputOptions.hashSalt) | 
					
						
							|  |  |  | 		hash.update(outputOptions.hashSalt); | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 	this.mainTemplate.updateHash(hash); | 
					
						
							|  |  |  | 	this.chunkTemplate.updateHash(hash); | 
					
						
							|  |  |  | 	this.moduleTemplate.updateHash(hash); | 
					
						
							|  |  |  | 	var i, chunk; | 
					
						
							| 
									
										
										
										
											2015-07-23 04:34:25 +08:00
										 |  |  | 	var chunks = this.chunks.slice(); | 
					
						
							|  |  |  | 	chunks.sort(function(a, b) { | 
					
						
							| 
									
										
										
										
											2016-07-13 17:03:14 +08:00
										 |  |  | 		var aEntry = a.hasRuntime(); | 
					
						
							|  |  |  | 		var bEntry = b.hasRuntime(); | 
					
						
							|  |  |  | 		if(aEntry && !bEntry) return 1; | 
					
						
							|  |  |  | 		if(!aEntry && bEntry) return -1; | 
					
						
							| 
									
										
										
										
											2015-07-23 04:34:25 +08:00
										 |  |  | 		return 0; | 
					
						
							|  |  |  | 	}); | 
					
						
							|  |  |  | 	for(i = 0; i < chunks.length; i++) { | 
					
						
							|  |  |  | 		chunk = chunks[i]; | 
					
						
							| 
									
										
										
										
											2013-07-11 05:20:07 +08:00
										 |  |  | 		var chunkHash = require("crypto").createHash(hashFunction); | 
					
						
							| 
									
										
										
										
											2016-06-05 02:03:42 +08:00
										 |  |  | 		if(outputOptions.hashSalt) | 
					
						
							|  |  |  | 			hash.update(outputOptions.hashSalt); | 
					
						
							| 
									
										
										
										
											2013-05-21 07:46:14 +08:00
										 |  |  | 		chunk.updateHash(chunkHash); | 
					
						
							| 
									
										
										
										
											2016-07-13 17:03:14 +08:00
										 |  |  | 		if(chunk.hasRuntime()) { | 
					
						
							| 
									
										
										
										
											2015-06-25 05:17:12 +08:00
										 |  |  | 			this.mainTemplate.updateHashForChunk(chunkHash, chunk); | 
					
						
							|  |  |  | 		} else { | 
					
						
							|  |  |  | 			this.chunkTemplate.updateHashForChunk(chunkHash); | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2016-12-05 06:47:19 +08:00
										 |  |  | 		this.applyPlugins2("chunk-hash", chunk, chunkHash); | 
					
						
							| 
									
										
										
										
											2013-05-21 17:08:08 +08:00
										 |  |  | 		chunk.hash = chunkHash.digest(hashDigest); | 
					
						
							| 
									
										
										
										
											2013-05-21 07:46:14 +08:00
										 |  |  | 		hash.update(chunk.hash); | 
					
						
							| 
									
										
										
										
											2013-05-21 17:08:08 +08:00
										 |  |  | 		chunk.renderedHash = chunk.hash.substr(0, hashDigestLength); | 
					
						
							| 
									
										
										
										
											2013-02-13 20:00:01 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2013-07-01 19:59:02 +08:00
										 |  |  | 	this.fullHash = hash.digest(hashDigest); | 
					
						
							|  |  |  | 	this.hash = this.fullHash.substr(0, hashDigestLength); | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Compilation.prototype.modifyHash = function modifyHash(update) { | 
					
						
							|  |  |  | 	var outputOptions = this.outputOptions; | 
					
						
							|  |  |  | 	var hashFunction = outputOptions.hashFunction; | 
					
						
							|  |  |  | 	var hashDigest = outputOptions.hashDigest; | 
					
						
							|  |  |  | 	var hashDigestLength = outputOptions.hashDigestLength; | 
					
						
							| 
									
										
										
										
											2013-07-11 05:20:07 +08:00
										 |  |  | 	var hash = require("crypto").createHash(hashFunction); | 
					
						
							| 
									
										
										
										
											2013-07-01 19:59:02 +08:00
										 |  |  | 	hash.update(this.fullHash); | 
					
						
							|  |  |  | 	hash.update(update); | 
					
						
							|  |  |  | 	this.fullHash = hash.digest(hashDigest); | 
					
						
							|  |  |  | 	this.hash = this.fullHash.substr(0, hashDigestLength); | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-03-06 05:30:24 +08:00
										 |  |  | Compilation.prototype.createModuleAssets = function createModuleAssets() { | 
					
						
							| 
									
										
										
										
											2016-10-29 17:11:44 +08:00
										 |  |  | 	var cacheAssetsAndApplyPlugins = function cacheAssetsAndApplyPlugins(name) { | 
					
						
							|  |  |  | 		var file = this.getPath(name); | 
					
						
							|  |  |  | 		this.assets[file] = module.assets[name]; | 
					
						
							| 
									
										
										
										
											2016-12-05 06:47:19 +08:00
										 |  |  | 		this.applyPlugins2("module-asset", module, file); | 
					
						
							| 
									
										
										
										
											2016-10-29 17:11:44 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-07-04 18:11:17 +08:00
										 |  |  | 	for(var i = 0; i < this.modules.length; i++) { | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 		var module = this.modules[i]; | 
					
						
							|  |  |  | 		if(module.assets) { | 
					
						
							| 
									
										
										
										
											2016-10-29 17:11:44 +08:00
										 |  |  | 			Object.keys(module.assets).forEach(cacheAssetsAndApplyPlugins, this); | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2015-01-31 23:19:36 +08:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Compilation.prototype.createChunkAssets = function createChunkAssets() { | 
					
						
							|  |  |  | 	var outputOptions = this.outputOptions; | 
					
						
							| 
									
										
										
										
											2016-01-07 06:02:25 +08:00
										 |  |  | 	var filename = outputOptions.filename; | 
					
						
							|  |  |  | 	var chunkFilename = outputOptions.chunkFilename; | 
					
						
							| 
									
										
										
										
											2013-07-04 18:11:17 +08:00
										 |  |  | 	for(var i = 0; i < this.chunks.length; i++) { | 
					
						
							|  |  |  | 		var chunk = this.chunks[i]; | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 		chunk.files = []; | 
					
						
							| 
									
										
										
										
											2013-05-21 07:46:14 +08:00
										 |  |  | 		var chunkHash = chunk.hash; | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 		var source; | 
					
						
							|  |  |  | 		var file; | 
					
						
							| 
									
										
										
										
											2015-07-08 20:15:21 +08:00
										 |  |  | 		var filenameTemplate = chunk.filenameTemplate ? chunk.filenameTemplate : | 
					
						
							| 
									
										
										
										
											2016-07-13 17:03:14 +08:00
										 |  |  | 			chunk.isInitial() ? filename : | 
					
						
							| 
									
										
										
										
											2013-12-03 18:19:30 +08:00
										 |  |  | 			chunkFilename; | 
					
						
							| 
									
										
										
										
											2015-06-27 17:34:17 +08:00
										 |  |  | 		try { | 
					
						
							| 
									
										
										
										
											2016-07-13 17:03:14 +08:00
										 |  |  | 			var useChunkHash = !chunk.hasRuntime() || (this.mainTemplate.useChunkHash && this.mainTemplate.useChunkHash(chunk)); | 
					
						
							| 
									
										
										
										
											2015-06-27 17:34:17 +08:00
										 |  |  | 			var usedHash = useChunkHash ? chunkHash : this.fullHash; | 
					
						
							|  |  |  | 			if(this.cache && this.cache["c" + chunk.id] && this.cache["c" + chunk.id].hash === usedHash) { | 
					
						
							|  |  |  | 				source = this.cache["c" + chunk.id].source; | 
					
						
							| 
									
										
										
										
											2013-05-08 19:28:54 +08:00
										 |  |  | 			} else { | 
					
						
							| 
									
										
										
										
											2016-07-13 17:03:14 +08:00
										 |  |  | 				if(chunk.hasRuntime()) { | 
					
						
							| 
									
										
										
										
											2015-06-27 17:34:17 +08:00
										 |  |  | 					source = this.mainTemplate.render(this.hash, chunk, this.moduleTemplate, this.dependencyTemplates); | 
					
						
							|  |  |  | 				} else { | 
					
						
							|  |  |  | 					source = this.chunkTemplate.render(chunk, this.moduleTemplate, this.dependencyTemplates); | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 				if(this.cache) { | 
					
						
							|  |  |  | 					this.cache["c" + chunk.id] = { | 
					
						
							|  |  |  | 						hash: usedHash, | 
					
						
							|  |  |  | 						source: source = (source instanceof CachedSource ? source : new CachedSource(source)) | 
					
						
							|  |  |  | 					}; | 
					
						
							|  |  |  | 				} | 
					
						
							| 
									
										
										
										
											2013-05-08 19:28:54 +08:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2015-07-01 06:44:17 +08:00
										 |  |  | 			file = this.getPath(filenameTemplate, { | 
					
						
							|  |  |  | 				noChunkHash: !useChunkHash, | 
					
						
							|  |  |  | 				chunk: chunk | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 			if(this.assets[file]) | 
					
						
							|  |  |  | 				throw new Error("Conflict: Multiple assets emit to the same filename '" + file + "'"); | 
					
						
							|  |  |  | 			this.assets[file] = source; | 
					
						
							| 
									
										
										
										
											2013-12-03 18:19:30 +08:00
										 |  |  | 			chunk.files.push(file); | 
					
						
							| 
									
										
										
										
											2016-12-05 06:47:19 +08:00
										 |  |  | 			this.applyPlugins2("chunk-asset", chunk, file); | 
					
						
							| 
									
										
										
										
											2015-06-27 17:34:17 +08:00
										 |  |  | 		} catch(err) { | 
					
						
							|  |  |  | 			this.errors.push(new ChunkRenderError(chunk, file || filenameTemplate, err)); | 
					
						
							| 
									
										
										
										
											2013-12-03 18:19:30 +08:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-08 20:15:21 +08:00
										 |  |  | Compilation.prototype.getPath = function(filename, data) { | 
					
						
							| 
									
										
										
										
											2014-08-22 19:51:24 +08:00
										 |  |  | 	data = data || {}; | 
					
						
							|  |  |  | 	data.hash = data.hash || this.hash; | 
					
						
							|  |  |  | 	return this.mainTemplate.applyPluginsWaterfall("asset-path", filename, data); | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | Compilation.prototype.getStats = function() { | 
					
						
							|  |  |  | 	return new Stats(this); | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Compilation.prototype.createChildCompiler = function(name, outputOptions) { | 
					
						
							|  |  |  | 	return this.compiler.createChildCompiler(this, name, outputOptions); | 
					
						
							|  |  |  | }; | 
					
						
							| 
									
										
										
										
											2016-07-16 03:59:24 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | Compilation.prototype.checkConstraints = function() { | 
					
						
							| 
									
										
										
										
											2016-07-18 06:41:26 +08:00
										 |  |  | 	var usedIds = {}; | 
					
						
							|  |  |  | 	this.modules.forEach(function(module) { | 
					
						
							|  |  |  | 		if(usedIds[module.id]) | 
					
						
							|  |  |  | 			throw new Error("checkConstraints: duplicate module id " + module.id); | 
					
						
							|  |  |  | 	}); | 
					
						
							| 
									
										
										
										
											2016-07-16 03:59:24 +08:00
										 |  |  | 	this.chunks.forEach(function(chunk, idx) { | 
					
						
							|  |  |  | 		if(this.chunks.indexOf(chunk) !== idx) | 
					
						
							| 
									
										
										
										
											2016-07-18 06:41:26 +08:00
										 |  |  | 			throw new Error("checkConstraints: duplicate chunk in compilation " + chunk.debugId); | 
					
						
							| 
									
										
										
										
											2016-07-16 03:59:24 +08:00
										 |  |  | 		chunk.checkConstraints(); | 
					
						
							|  |  |  | 	}.bind(this)); | 
					
						
							| 
									
										
										
										
											2016-11-24 06:14:09 +08:00
										 |  |  | }; |