| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | /* | 
					
						
							|  |  |  | 	MIT License http://www.opensource.org/licenses/mit-license.php
 | 
					
						
							|  |  |  | 	Author Tobias Koppers @sokra | 
					
						
							|  |  |  | */ | 
					
						
							| 
									
										
										
										
											2018-07-30 23:08:51 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-21 10:44:55 +08:00
										 |  |  | "use strict"; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-19 17:09:30 +08:00
										 |  |  | const parseJson = require("json-parse-better-errors"); | 
					
						
							| 
									
										
										
										
											2018-02-11 12:27:09 +08:00
										 |  |  | const asyncLib = require("neo-async"); | 
					
						
							| 
									
										
										
										
											2018-03-22 19:05:58 +08:00
										 |  |  | const { | 
					
						
							|  |  |  | 	SyncHook, | 
					
						
							|  |  |  | 	SyncBailHook, | 
					
						
							|  |  |  | 	AsyncParallelHook, | 
					
						
							|  |  |  | 	AsyncSeriesHook | 
					
						
							|  |  |  | } = require("tapable"); | 
					
						
							| 
									
										
										
										
											2019-01-19 03:38:34 +08:00
										 |  |  | const { SizeOnlySource } = require("webpack-sources"); | 
					
						
							| 
									
										
										
										
											2017-06-21 10:44:55 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-27 13:22:19 +08:00
										 |  |  | const Cache = require("./Cache"); | 
					
						
							| 
									
										
										
										
											2017-06-21 10:44:55 +08:00
										 |  |  | const Compilation = require("./Compilation"); | 
					
						
							| 
									
										
										
										
											2018-09-27 13:22:19 +08:00
										 |  |  | const ConcurrentCompilationError = require("./ConcurrentCompilationError"); | 
					
						
							| 
									
										
										
										
											2017-06-21 10:44:55 +08:00
										 |  |  | const ContextModuleFactory = require("./ContextModuleFactory"); | 
					
						
							| 
									
										
										
										
											2018-07-30 23:08:51 +08:00
										 |  |  | const NormalModuleFactory = require("./NormalModuleFactory"); | 
					
						
							| 
									
										
										
										
											2018-09-27 13:22:19 +08:00
										 |  |  | const RequestShortener = require("./RequestShortener"); | 
					
						
							| 
									
										
										
										
											2017-11-17 21:26:23 +08:00
										 |  |  | const ResolverFactory = require("./ResolverFactory"); | 
					
						
							| 
									
										
										
										
											2018-07-30 23:08:51 +08:00
										 |  |  | const Stats = require("./Stats"); | 
					
						
							|  |  |  | const Watching = require("./Watching"); | 
					
						
							| 
									
										
										
										
											2019-07-22 04:28:46 +08:00
										 |  |  | const { Logger } = require("./logging/Logger"); | 
					
						
							| 
									
										
										
										
											2019-06-11 19:09:42 +08:00
										 |  |  | const { join, dirname, mkdirp } = require("./util/fs"); | 
					
						
							| 
									
										
										
										
											2018-03-22 19:05:58 +08:00
										 |  |  | const { makePathsRelative } = require("./util/identifier"); | 
					
						
							| 
									
										
										
										
											2017-06-21 10:44:55 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-19 03:38:34 +08:00
										 |  |  | /** @typedef {import("webpack-sources").Source} Source */ | 
					
						
							| 
									
										
										
										
											2018-09-19 19:05:22 +08:00
										 |  |  | /** @typedef {import("../declarations/WebpackOptions").Entry} Entry */ | 
					
						
							| 
									
										
										
										
											2018-12-10 18:34:59 +08:00
										 |  |  | /** @typedef {import("../declarations/WebpackOptions").OutputOptions} OutputOptions */ | 
					
						
							|  |  |  | /** @typedef {import("../declarations/WebpackOptions").WatchOptions} WatchOptions */ | 
					
						
							| 
									
										
										
										
											2018-09-19 19:05:22 +08:00
										 |  |  | /** @typedef {import("../declarations/WebpackOptions").WebpackOptions} WebpackOptions */ | 
					
						
							| 
									
										
										
										
											2018-12-10 18:34:59 +08:00
										 |  |  | /** @typedef {import("../declarations/WebpackOptions").WebpackPluginInstance} WebpackPluginInstance */ | 
					
						
							|  |  |  | /** @typedef {import("./Chunk")} Chunk */ | 
					
						
							| 
									
										
										
										
											2018-09-28 03:28:07 +08:00
										 |  |  | /** @typedef {import("./FileSystemInfo").FileSystemInfoEntry} FileSystemInfoEntry */ | 
					
						
							| 
									
										
										
										
											2018-12-09 19:54:17 +08:00
										 |  |  | /** @typedef {import("./Module")} Module */ | 
					
						
							| 
									
										
										
										
											2019-06-11 19:09:42 +08:00
										 |  |  | /** @typedef {import("./util/fs").InputFileSystem} InputFileSystem */ | 
					
						
							|  |  |  | /** @typedef {import("./util/fs").IntermediateFileSystem} IntermediateFileSystem */ | 
					
						
							|  |  |  | /** @typedef {import("./util/fs").OutputFileSystem} OutputFileSystem */ | 
					
						
							| 
									
										
										
										
											2018-09-19 19:05:22 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-04 00:57:02 +08:00
										 |  |  | /** | 
					
						
							|  |  |  |  * @typedef {Object} CompilationParams | 
					
						
							|  |  |  |  * @property {NormalModuleFactory} normalModuleFactory | 
					
						
							|  |  |  |  * @property {ContextModuleFactory} contextModuleFactory | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-10 18:34:59 +08:00
										 |  |  | /** | 
					
						
							|  |  |  |  * @template T | 
					
						
							|  |  |  |  * @callback Callback | 
					
						
							|  |  |  |  * @param {Error=} err | 
					
						
							|  |  |  |  * @param {T=} result | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							|  |  |  |  * @callback RunAsChildCallback | 
					
						
							|  |  |  |  * @param {Error=} err | 
					
						
							|  |  |  |  * @param {Chunk[]=} entries | 
					
						
							|  |  |  |  * @param {Compilation=} compilation | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-09-05 20:10:16 +08:00
										 |  |  | /** | 
					
						
							|  |  |  |  * @typedef {Object} AssetEmittedInfo | 
					
						
							|  |  |  |  * @property {Buffer} content | 
					
						
							|  |  |  |  * @property {Source} source | 
					
						
							|  |  |  |  * @property {Compilation} compilation | 
					
						
							|  |  |  |  * @property {string} outputPath | 
					
						
							|  |  |  |  * @property {string} targetPath | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-27 18:47:31 +08:00
										 |  |  | /** | 
					
						
							|  |  |  |  * @param {string[]} array an array | 
					
						
							|  |  |  |  * @returns {boolean} true, if the array is sorted | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | const isSorted = array => { | 
					
						
							|  |  |  | 	for (let i = 1; i < array.length; i++) { | 
					
						
							|  |  |  | 		if (array[i - 1] > array[i]) return false; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return true; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							|  |  |  |  * @param {Object} obj an object | 
					
						
							|  |  |  |  * @param {string[]} keys the keys of the object | 
					
						
							|  |  |  |  * @returns {Object} the object with properties sorted by property name | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | const sortObject = (obj, keys) => { | 
					
						
							|  |  |  | 	return keys.sort().reduce((o, k) => { | 
					
						
							|  |  |  | 		o[k] = obj[k]; | 
					
						
							|  |  |  | 		return o; | 
					
						
							|  |  |  | 	}, {}); | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-26 14:27:44 +08:00
										 |  |  | class Compiler { | 
					
						
							| 
									
										
										
										
											2018-12-10 18:34:59 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {string} context the compilation path | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2017-12-01 17:44:22 +08:00
										 |  |  | 	constructor(context) { | 
					
						
							| 
									
										
										
										
											2018-07-30 20:25:40 +08:00
										 |  |  | 		this.hooks = Object.freeze({ | 
					
						
							| 
									
										
										
										
											2018-12-09 19:54:17 +08:00
										 |  |  | 			/** @type {SyncBailHook<[Compilation], boolean>} */ | 
					
						
							| 
									
										
										
										
											2017-11-27 22:27:37 +08:00
										 |  |  | 			shouldEmit: new SyncBailHook(["compilation"]), | 
					
						
							| 
									
										
										
										
											2018-12-09 19:54:17 +08:00
										 |  |  | 			/** @type {AsyncSeriesHook<[Stats]>} */ | 
					
						
							| 
									
										
										
										
											2018-01-25 20:56:50 +08:00
										 |  |  | 			done: new AsyncSeriesHook(["stats"]), | 
					
						
							| 
									
										
										
										
											2019-07-10 03:14:40 +08:00
										 |  |  | 			/** @type {SyncHook<[Stats]>} */ | 
					
						
							| 
									
										
										
										
											2018-12-25 15:08:12 +08:00
										 |  |  | 			afterDone: new SyncHook(["stats"]), | 
					
						
							| 
									
										
										
										
											2018-12-09 19:54:17 +08:00
										 |  |  | 			/** @type {AsyncSeriesHook<[]>} */ | 
					
						
							| 
									
										
										
										
											2017-11-27 22:27:37 +08:00
										 |  |  | 			additionalPass: new AsyncSeriesHook([]), | 
					
						
							| 
									
										
										
										
											2018-12-09 19:54:17 +08:00
										 |  |  | 			/** @type {AsyncSeriesHook<[Compiler]>} */ | 
					
						
							| 
									
										
										
										
											2018-05-04 00:57:02 +08:00
										 |  |  | 			beforeRun: new AsyncSeriesHook(["compiler"]), | 
					
						
							| 
									
										
										
										
											2018-12-09 19:54:17 +08:00
										 |  |  | 			/** @type {AsyncSeriesHook<[Compiler]>} */ | 
					
						
							| 
									
										
										
										
											2018-05-04 00:57:02 +08:00
										 |  |  | 			run: new AsyncSeriesHook(["compiler"]), | 
					
						
							| 
									
										
										
										
											2018-12-09 19:54:17 +08:00
										 |  |  | 			/** @type {AsyncSeriesHook<[Compilation]>} */ | 
					
						
							| 
									
										
										
										
											2017-11-27 22:27:37 +08:00
										 |  |  | 			emit: new AsyncSeriesHook(["compilation"]), | 
					
						
							| 
									
										
										
										
											2019-09-05 20:10:16 +08:00
										 |  |  | 			/** @type {AsyncSeriesHook<[string, AssetEmittedInfo]>} */ | 
					
						
							|  |  |  | 			assetEmitted: new AsyncSeriesHook(["file", "info"]), | 
					
						
							| 
									
										
										
										
											2018-12-09 19:54:17 +08:00
										 |  |  | 			/** @type {AsyncSeriesHook<[Compilation]>} */ | 
					
						
							| 
									
										
										
										
											2017-11-27 22:27:37 +08:00
										 |  |  | 			afterEmit: new AsyncSeriesHook(["compilation"]), | 
					
						
							| 
									
										
										
										
											2018-05-04 00:57:02 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-09 19:54:17 +08:00
										 |  |  | 			/** @type {SyncHook<[Compilation, CompilationParams]>} */ | 
					
						
							| 
									
										
										
										
											2017-11-27 22:27:37 +08:00
										 |  |  | 			thisCompilation: new SyncHook(["compilation", "params"]), | 
					
						
							| 
									
										
										
										
											2018-12-09 19:54:17 +08:00
										 |  |  | 			/** @type {SyncHook<[Compilation, CompilationParams]>} */ | 
					
						
							| 
									
										
										
										
											2017-11-27 22:27:37 +08:00
										 |  |  | 			compilation: new SyncHook(["compilation", "params"]), | 
					
						
							| 
									
										
										
										
											2018-12-09 19:54:17 +08:00
										 |  |  | 			/** @type {SyncHook<[NormalModuleFactory]>} */ | 
					
						
							| 
									
										
										
										
											2017-11-27 22:27:37 +08:00
										 |  |  | 			normalModuleFactory: new SyncHook(["normalModuleFactory"]), | 
					
						
							| 
									
										
										
										
											2018-12-09 19:54:17 +08:00
										 |  |  | 			/** @type {SyncHook<[ContextModuleFactory]>}  */ | 
					
						
							| 
									
										
										
										
											2017-11-27 22:27:37 +08:00
										 |  |  | 			contextModuleFactory: new SyncHook(["contextModulefactory"]), | 
					
						
							| 
									
										
										
										
											2018-05-04 00:57:02 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-09 19:54:17 +08:00
										 |  |  | 			/** @type {AsyncSeriesHook<[CompilationParams]>} */ | 
					
						
							| 
									
										
										
										
											2017-11-27 22:27:37 +08:00
										 |  |  | 			beforeCompile: new AsyncSeriesHook(["params"]), | 
					
						
							| 
									
										
										
										
											2018-12-09 19:54:17 +08:00
										 |  |  | 			/** @type {SyncHook<[CompilationParams]>} */ | 
					
						
							| 
									
										
										
										
											2017-11-27 22:27:37 +08:00
										 |  |  | 			compile: new SyncHook(["params"]), | 
					
						
							| 
									
										
										
										
											2018-12-09 19:54:17 +08:00
										 |  |  | 			/** @type {AsyncParallelHook<[Compilation], Module>} */ | 
					
						
							| 
									
										
										
										
											2017-11-27 22:27:37 +08:00
										 |  |  | 			make: new AsyncParallelHook(["compilation"]), | 
					
						
							| 
									
										
										
										
											2018-12-09 19:54:17 +08:00
										 |  |  | 			/** @type {AsyncSeriesHook<[Compilation]>} */ | 
					
						
							| 
									
										
										
										
											2017-11-27 22:27:37 +08:00
										 |  |  | 			afterCompile: new AsyncSeriesHook(["compilation"]), | 
					
						
							| 
									
										
										
										
											2018-05-04 00:57:02 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-09 19:54:17 +08:00
										 |  |  | 			/** @type {AsyncSeriesHook<[Compiler]>} */ | 
					
						
							| 
									
										
										
										
											2017-11-27 22:27:37 +08:00
										 |  |  | 			watchRun: new AsyncSeriesHook(["compiler"]), | 
					
						
							| 
									
										
										
										
											2018-12-09 19:54:17 +08:00
										 |  |  | 			/** @type {SyncHook<[Error]>} */ | 
					
						
							| 
									
										
										
										
											2017-11-27 22:27:37 +08:00
										 |  |  | 			failed: new SyncHook(["error"]), | 
					
						
							| 
									
										
										
										
											2018-12-09 19:54:17 +08:00
										 |  |  | 			/** @type {SyncHook<[string, string]>} */ | 
					
						
							| 
									
										
										
										
											2017-11-27 22:27:37 +08:00
										 |  |  | 			invalid: new SyncHook(["filename", "changeTime"]), | 
					
						
							| 
									
										
										
										
											2018-12-09 19:54:17 +08:00
										 |  |  | 			/** @type {SyncHook<[]>} */ | 
					
						
							| 
									
										
										
										
											2017-11-27 22:27:37 +08:00
										 |  |  | 			watchClose: new SyncHook([]), | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-07-24 16:51:04 +08:00
										 |  |  | 			/** @type {SyncBailHook<[string, string, any[]], true>} */ | 
					
						
							| 
									
										
										
										
											2019-07-31 22:57:01 +08:00
										 |  |  | 			infrastructureLog: new SyncBailHook(["origin", "type", "args"]), | 
					
						
							| 
									
										
										
											
												add logging API
Plugins:
Compiler.getInfrastructureLogger(name)
Compilation.getLogger(name)
Loader:
this.getLogger([name])
API equal to console API with these methods:
error, warn, info, log, debug,
time, timeLog, timeEnd,
group, groupCollapsed, groupEnd,
profile, profileEnd,
clear
											
										 
											2019-07-18 23:13:40 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-27 22:27:37 +08:00
										 |  |  | 			// TODO the following hooks are weirdly located here
 | 
					
						
							|  |  |  | 			// TODO move them for webpack 5
 | 
					
						
							| 
									
										
										
										
											2018-12-09 19:54:17 +08:00
										 |  |  | 			/** @type {SyncHook<[]>} */ | 
					
						
							| 
									
										
										
										
											2017-11-27 22:27:37 +08:00
										 |  |  | 			environment: new SyncHook([]), | 
					
						
							| 
									
										
										
										
											2018-12-09 19:54:17 +08:00
										 |  |  | 			/** @type {SyncHook<[]>} */ | 
					
						
							| 
									
										
										
										
											2017-11-27 22:27:37 +08:00
										 |  |  | 			afterEnvironment: new SyncHook([]), | 
					
						
							| 
									
										
										
										
											2018-12-09 19:54:17 +08:00
										 |  |  | 			/** @type {SyncHook<[Compiler]>} */ | 
					
						
							| 
									
										
										
										
											2017-11-27 22:27:37 +08:00
										 |  |  | 			afterPlugins: new SyncHook(["compiler"]), | 
					
						
							| 
									
										
										
										
											2018-12-09 19:54:17 +08:00
										 |  |  | 			/** @type {SyncHook<[Compiler]>} */ | 
					
						
							| 
									
										
										
										
											2017-11-27 22:27:37 +08:00
										 |  |  | 			afterResolvers: new SyncHook(["compiler"]), | 
					
						
							| 
									
										
										
										
											2018-12-09 19:54:17 +08:00
										 |  |  | 			/** @type {SyncBailHook<[string, Entry], boolean>} */ | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 			entryOption: new SyncBailHook(["context", "entry"]) | 
					
						
							| 
									
										
										
										
											2018-07-30 20:25:40 +08:00
										 |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2017-11-27 22:27:37 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-04 00:57:02 +08:00
										 |  |  | 		/** @type {string=} */ | 
					
						
							| 
									
										
										
										
											2018-03-30 08:33:19 +08:00
										 |  |  | 		this.name = undefined; | 
					
						
							| 
									
										
										
										
											2018-05-04 00:57:02 +08:00
										 |  |  | 		/** @type {Compilation=} */ | 
					
						
							| 
									
										
										
										
											2018-03-30 08:33:19 +08:00
										 |  |  | 		this.parentCompilation = undefined; | 
					
						
							| 
									
										
										
										
											2018-09-27 13:22:19 +08:00
										 |  |  | 		/** @type {Compiler} */ | 
					
						
							|  |  |  | 		this.root = this; | 
					
						
							| 
									
										
										
										
											2018-05-04 00:57:02 +08:00
										 |  |  | 		/** @type {string} */ | 
					
						
							| 
									
										
										
										
											2017-06-21 10:44:55 +08:00
										 |  |  | 		this.outputPath = ""; | 
					
						
							| 
									
										
										
										
											2018-05-04 00:57:02 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-11 19:09:42 +08:00
										 |  |  | 		/** @type {OutputFileSystem} */ | 
					
						
							| 
									
										
										
										
											2017-06-21 10:44:55 +08:00
										 |  |  | 		this.outputFileSystem = null; | 
					
						
							| 
									
										
										
										
											2019-06-11 19:09:42 +08:00
										 |  |  | 		/** @type {IntermediateFileSystem} */ | 
					
						
							|  |  |  | 		this.intermediateFileSystem = null; | 
					
						
							|  |  |  | 		/** @type {InputFileSystem} */ | 
					
						
							| 
									
										
										
										
											2017-06-21 10:44:55 +08:00
										 |  |  | 		this.inputFileSystem = null; | 
					
						
							| 
									
										
										
										
											2018-09-27 13:22:19 +08:00
										 |  |  | 		this.watchFileSystem = null; | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-04 00:57:02 +08:00
										 |  |  | 		/** @type {string|null} */ | 
					
						
							| 
									
										
										
										
											2017-06-21 10:44:55 +08:00
										 |  |  | 		this.recordsInputPath = null; | 
					
						
							| 
									
										
										
										
											2018-05-04 00:57:02 +08:00
										 |  |  | 		/** @type {string|null} */ | 
					
						
							| 
									
										
										
										
											2017-06-21 10:44:55 +08:00
										 |  |  | 		this.recordsOutputPath = null; | 
					
						
							|  |  |  | 		this.records = {}; | 
					
						
							| 
									
										
										
										
											2018-10-25 02:10:30 +08:00
										 |  |  | 		/** @type {Set<string>} */ | 
					
						
							| 
									
										
										
										
											2019-08-13 04:59:09 +08:00
										 |  |  | 		this.managedPaths = new Set(); | 
					
						
							|  |  |  | 		/** @type {Set<string>} */ | 
					
						
							| 
									
										
										
										
											2019-08-16 17:55:10 +08:00
										 |  |  | 		this.immutablePaths = new Set(); | 
					
						
							|  |  |  | 		/** @type {Set<string>} */ | 
					
						
							| 
									
										
										
										
											2018-10-19 06:58:58 +08:00
										 |  |  | 		this.removedFiles = new Set(); | 
					
						
							| 
									
										
										
										
											2019-01-05 02:17:37 +08:00
										 |  |  | 		/** @type {Map<string, FileSystemInfoEntry | null>} */ | 
					
						
							| 
									
										
										
										
											2018-01-23 15:30:22 +08:00
										 |  |  | 		this.fileTimestamps = new Map(); | 
					
						
							| 
									
										
										
										
											2019-01-05 02:17:37 +08:00
										 |  |  | 		/** @type {Map<string, FileSystemInfoEntry | null>} */ | 
					
						
							| 
									
										
										
										
											2018-01-23 15:30:22 +08:00
										 |  |  | 		this.contextTimestamps = new Map(); | 
					
						
							| 
									
										
										
										
											2018-05-04 00:57:02 +08:00
										 |  |  | 		/** @type {ResolverFactory} */ | 
					
						
							| 
									
										
										
										
											2017-11-17 21:26:23 +08:00
										 |  |  | 		this.resolverFactory = new ResolverFactory(); | 
					
						
							| 
									
										
										
										
											2018-01-24 05:28:23 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-07-22 14:23:40 +08:00
										 |  |  | 		this.infrastructureLogger = undefined; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-19 19:05:22 +08:00
										 |  |  | 		/** @type {WebpackOptions} */ | 
					
						
							|  |  |  | 		this.options = /** @type {WebpackOptions} */ ({}); | 
					
						
							| 
									
										
										
										
											2017-12-01 17:44:22 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		this.context = context; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		this.requestShortener = new RequestShortener(context); | 
					
						
							| 
									
										
										
										
											2018-03-07 05:56:31 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-27 13:22:19 +08:00
										 |  |  | 		this.cache = new Cache(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-26 16:28:16 +08:00
										 |  |  | 		this.compilerPath = ""; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-04 00:57:02 +08:00
										 |  |  | 		/** @type {boolean} */ | 
					
						
							| 
									
										
										
										
											2018-03-07 05:56:31 +08:00
										 |  |  | 		this.running = false; | 
					
						
							| 
									
										
										
										
											2018-10-23 06:23:47 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		/** @type {boolean} */ | 
					
						
							|  |  |  | 		this.watchMode = false; | 
					
						
							| 
									
										
										
										
											2019-01-19 03:38:34 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		/** @private @type {WeakMap<Source, { sizeOnlySource: SizeOnlySource, writtenTo: Map<string, number> }>} */ | 
					
						
							|  |  |  | 		this._assetEmittingSourceCache = new WeakMap(); | 
					
						
							|  |  |  | 		/** @private @type {Map<string, number>} */ | 
					
						
							|  |  |  | 		this._assetEmittingWrittenFiles = new Map(); | 
					
						
							| 
									
										
										
										
											2017-06-21 10:44:55 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
											
												add logging API
Plugins:
Compiler.getInfrastructureLogger(name)
Compilation.getLogger(name)
Loader:
this.getLogger([name])
API equal to console API with these methods:
error, warn, info, log, debug,
time, timeLog, timeEnd,
group, groupCollapsed, groupEnd,
profile, profileEnd,
clear
											
										 
											2019-07-18 23:13:40 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {string | (function(): string)} name name of the logger, or function called once to get the logger name | 
					
						
							|  |  |  | 	 * @returns {Logger} a logger with that name | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	getInfrastructureLogger(name) { | 
					
						
							|  |  |  | 		if (!name) { | 
					
						
							|  |  |  | 			throw new TypeError( | 
					
						
							|  |  |  | 				"Compiler.getInfrastructureLogger(name) called without a name" | 
					
						
							|  |  |  | 			); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		return new Logger((type, args) => { | 
					
						
							|  |  |  | 			if (typeof name === "function") { | 
					
						
							|  |  |  | 				name = name(); | 
					
						
							|  |  |  | 				if (!name) { | 
					
						
							|  |  |  | 					throw new TypeError( | 
					
						
							|  |  |  | 						"Compiler.getInfrastructureLogger(name) called with a function not returning a name" | 
					
						
							|  |  |  | 					); | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2019-07-31 22:57:01 +08:00
										 |  |  | 			if (this.hooks.infrastructureLog.call(name, type, args) === undefined) { | 
					
						
							| 
									
										
										
										
											2019-07-22 14:23:40 +08:00
										 |  |  | 				if (this.infrastructureLogger !== undefined) { | 
					
						
							|  |  |  | 					this.infrastructureLogger(name, type, args); | 
					
						
							|  |  |  | 				} | 
					
						
							| 
									
										
										
											
												add logging API
Plugins:
Compiler.getInfrastructureLogger(name)
Compilation.getLogger(name)
Loader:
this.getLogger([name])
API equal to console API with these methods:
error, warn, info, log, debug,
time, timeLog, timeEnd,
group, groupCollapsed, groupEnd,
profile, profileEnd,
clear
											
										 
											2019-07-18 23:13:40 +08:00
										 |  |  | 			} | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-10 18:34:59 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {WatchOptions} watchOptions the watcher's options | 
					
						
							|  |  |  | 	 * @param {Callback<Stats>} handler signals when the call finishes | 
					
						
							|  |  |  | 	 * @returns {Watching} a compiler watcher | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2017-06-21 10:44:55 +08:00
										 |  |  | 	watch(watchOptions, handler) { | 
					
						
							| 
									
										
										
										
											2018-12-10 18:34:59 +08:00
										 |  |  | 		if (this.running) { | 
					
						
							|  |  |  | 			return handler(new ConcurrentCompilationError()); | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2018-03-07 05:56:31 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		this.running = true; | 
					
						
							| 
									
										
										
										
											2018-10-24 01:52:32 +08:00
										 |  |  | 		this.watchMode = true; | 
					
						
							| 
									
										
										
										
											2017-12-31 23:19:18 +08:00
										 |  |  | 		return new Watching(this, watchOptions, handler); | 
					
						
							| 
									
										
										
										
											2017-06-21 10:44:55 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2016-10-18 02:26:22 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-10 18:34:59 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {Callback<Stats>} callback signals when the call finishes | 
					
						
							|  |  |  | 	 * @returns {void} | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2017-06-21 10:44:55 +08:00
										 |  |  | 	run(callback) { | 
					
						
							| 
									
										
										
										
											2018-12-10 18:34:59 +08:00
										 |  |  | 		if (this.running) { | 
					
						
							|  |  |  | 			return callback(new ConcurrentCompilationError()); | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2018-03-07 05:56:31 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-07-26 17:09:14 +08:00
										 |  |  | 		let logger; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-07 17:14:51 +08:00
										 |  |  | 		const finalCallback = (err, stats) => { | 
					
						
							| 
									
										
										
										
											2019-07-26 17:09:14 +08:00
										 |  |  | 			if (logger) logger.time("beginIdle"); | 
					
						
							| 
									
										
										
										
											2018-09-27 13:22:19 +08:00
										 |  |  | 			this.cache.beginIdle(); | 
					
						
							| 
									
										
										
										
											2019-07-26 17:09:14 +08:00
										 |  |  | 			if (logger) logger.timeEnd("beginIdle"); | 
					
						
							| 
									
										
										
										
											2018-03-07 17:14:51 +08:00
										 |  |  | 			this.running = false; | 
					
						
							| 
									
										
										
										
											2018-11-22 00:03:18 +08:00
										 |  |  | 			if (err) { | 
					
						
							|  |  |  | 				this.hooks.failed.call(err); | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2018-12-25 18:43:34 +08:00
										 |  |  | 			if (callback !== undefined) callback(err, stats); | 
					
						
							| 
									
										
										
										
											2018-12-25 15:08:12 +08:00
										 |  |  | 			this.hooks.afterDone.call(stats); | 
					
						
							| 
									
										
										
										
											2018-03-07 17:14:51 +08:00
										 |  |  | 		}; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-21 10:44:55 +08:00
										 |  |  | 		const startTime = Date.now(); | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-07 05:56:31 +08:00
										 |  |  | 		this.running = true; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-07-01 23:47:36 +08:00
										 |  |  | 		const onCompiled = (err, compilation) => { | 
					
						
							| 
									
										
										
										
											2018-03-07 17:14:51 +08:00
										 |  |  | 			if (err) return finalCallback(err); | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 			if (this.hooks.shouldEmit.call(compilation) === false) { | 
					
						
							| 
									
										
										
										
											2017-07-01 23:47:36 +08:00
										 |  |  | 				const stats = new Stats(compilation); | 
					
						
							|  |  |  | 				stats.startTime = startTime; | 
					
						
							|  |  |  | 				stats.endTime = Date.now(); | 
					
						
							| 
									
										
										
										
											2018-01-25 20:56:50 +08:00
										 |  |  | 				this.hooks.done.callAsync(stats, err => { | 
					
						
							| 
									
										
										
										
											2018-03-07 17:14:51 +08:00
										 |  |  | 					if (err) return finalCallback(err); | 
					
						
							|  |  |  | 					return finalCallback(null, stats); | 
					
						
							| 
									
										
										
										
											2018-01-25 20:56:50 +08:00
										 |  |  | 				}); | 
					
						
							|  |  |  | 				return; | 
					
						
							| 
									
										
										
										
											2017-07-01 23:47:36 +08:00
										 |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-05 20:49:42 +08:00
										 |  |  | 			process.nextTick(() => { | 
					
						
							| 
									
										
										
										
											2019-07-26 17:09:14 +08:00
										 |  |  | 				logger = compilation.getLogger("webpack.Compiler"); | 
					
						
							|  |  |  | 				logger.time("emitAssets"); | 
					
						
							| 
									
										
										
										
											2019-01-05 20:49:42 +08:00
										 |  |  | 				this.emitAssets(compilation, err => { | 
					
						
							| 
									
										
										
										
											2019-07-26 17:09:14 +08:00
										 |  |  | 					logger.timeEnd("emitAssets"); | 
					
						
							| 
									
										
										
										
											2019-01-05 20:49:42 +08:00
										 |  |  | 					if (err) return finalCallback(err); | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-05 20:49:42 +08:00
										 |  |  | 					if (compilation.hooks.needAdditionalPass.call()) { | 
					
						
							|  |  |  | 						compilation.needAdditionalPass = true; | 
					
						
							| 
									
										
										
										
											2013-05-31 18:22:40 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-05 20:49:42 +08:00
										 |  |  | 						const stats = new Stats(compilation); | 
					
						
							|  |  |  | 						stats.startTime = startTime; | 
					
						
							|  |  |  | 						stats.endTime = Date.now(); | 
					
						
							| 
									
										
										
										
											2019-07-26 17:09:14 +08:00
										 |  |  | 						logger.time("done hook"); | 
					
						
							| 
									
										
										
										
											2019-01-05 20:49:42 +08:00
										 |  |  | 						this.hooks.done.callAsync(stats, err => { | 
					
						
							| 
									
										
										
										
											2019-07-26 17:09:14 +08:00
										 |  |  | 							logger.timeEnd("done hook"); | 
					
						
							| 
									
										
										
										
											2018-03-07 17:14:51 +08:00
										 |  |  | 							if (err) return finalCallback(err); | 
					
						
							| 
									
										
										
										
											2013-05-31 18:22:40 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-05 20:49:42 +08:00
										 |  |  | 							this.hooks.additionalPass.callAsync(err => { | 
					
						
							|  |  |  | 								if (err) return finalCallback(err); | 
					
						
							|  |  |  | 								this.compile(onCompiled); | 
					
						
							|  |  |  | 							}); | 
					
						
							|  |  |  | 						}); | 
					
						
							|  |  |  | 						return; | 
					
						
							|  |  |  | 					} | 
					
						
							| 
									
										
										
										
											2016-05-07 04:45:44 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-07-26 17:09:14 +08:00
										 |  |  | 					logger.time("emitRecords"); | 
					
						
							| 
									
										
										
										
											2019-01-05 20:49:42 +08:00
										 |  |  | 					this.emitRecords(err => { | 
					
						
							| 
									
										
										
										
											2019-07-26 17:09:14 +08:00
										 |  |  | 						logger.timeEnd("emitRecords"); | 
					
						
							| 
									
										
										
										
											2018-03-07 17:14:51 +08:00
										 |  |  | 						if (err) return finalCallback(err); | 
					
						
							| 
									
										
										
										
											2019-01-05 20:49:42 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 						const stats = new Stats(compilation); | 
					
						
							|  |  |  | 						stats.startTime = startTime; | 
					
						
							|  |  |  | 						stats.endTime = Date.now(); | 
					
						
							| 
									
										
										
										
											2019-07-26 17:09:14 +08:00
										 |  |  | 						logger.time("done hook"); | 
					
						
							| 
									
										
										
										
											2019-01-05 20:49:42 +08:00
										 |  |  | 						this.hooks.done.callAsync(stats, err => { | 
					
						
							| 
									
										
										
										
											2019-07-26 17:09:14 +08:00
										 |  |  | 							logger.timeEnd("done hook"); | 
					
						
							| 
									
										
										
										
											2019-01-05 20:49:42 +08:00
										 |  |  | 							if (err) return finalCallback(err); | 
					
						
							|  |  |  | 							return finalCallback(null, stats); | 
					
						
							|  |  |  | 						}); | 
					
						
							| 
									
										
										
										
											2018-01-25 20:56:50 +08:00
										 |  |  | 					}); | 
					
						
							| 
									
										
										
										
											2017-07-01 23:47:36 +08:00
										 |  |  | 				}); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}; | 
					
						
							| 
									
										
										
										
											2016-05-07 04:45:44 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-27 13:22:19 +08:00
										 |  |  | 		this.cache.endIdle(err => { | 
					
						
							| 
									
										
										
										
											2018-03-07 17:14:51 +08:00
										 |  |  | 			if (err) return finalCallback(err); | 
					
						
							| 
									
										
										
										
											2016-05-07 04:45:44 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-27 13:22:19 +08:00
										 |  |  | 			this.hooks.beforeRun.callAsync(this, err => { | 
					
						
							| 
									
										
										
										
											2018-03-07 17:14:51 +08:00
										 |  |  | 				if (err) return finalCallback(err); | 
					
						
							| 
									
										
										
										
											2016-05-07 04:45:44 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-27 13:22:19 +08:00
										 |  |  | 				this.hooks.run.callAsync(this, err => { | 
					
						
							| 
									
										
										
										
											2018-03-07 17:14:51 +08:00
										 |  |  | 					if (err) return finalCallback(err); | 
					
						
							| 
									
										
										
										
											2017-06-21 10:44:55 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-27 13:22:19 +08:00
										 |  |  | 					this.readRecords(err => { | 
					
						
							|  |  |  | 						if (err) return finalCallback(err); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 						this.compile(onCompiled); | 
					
						
							|  |  |  | 					}); | 
					
						
							| 
									
										
										
										
											2016-10-18 02:26:22 +08:00
										 |  |  | 				}); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2017-06-21 10:44:55 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-10 18:34:59 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {RunAsChildCallback} callback signals when the call finishes | 
					
						
							|  |  |  | 	 * @returns {void} | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2017-06-21 10:44:55 +08:00
										 |  |  | 	runAsChild(callback) { | 
					
						
							|  |  |  | 		this.compile((err, compilation) => { | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 			if (err) return callback(err); | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-21 10:44:55 +08:00
										 |  |  | 			this.parentCompilation.children.push(compilation); | 
					
						
							| 
									
										
										
										
											2019-09-11 17:13:46 +08:00
										 |  |  | 			for (const { name, source, info } of compilation.getAssets()) { | 
					
						
							|  |  |  | 				this.parentCompilation.emitAsset(name, source, info); | 
					
						
							| 
									
										
										
										
											2018-01-22 20:52:43 +08:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2015-01-05 21:30:18 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 			const entries = Array.from( | 
					
						
							|  |  |  | 				compilation.entrypoints.values(), | 
					
						
							|  |  |  | 				ep => ep.chunks | 
					
						
							|  |  |  | 			).reduce((array, chunks) => { | 
					
						
							| 
									
										
										
										
											2017-06-21 10:44:55 +08:00
										 |  |  | 				return array.concat(chunks); | 
					
						
							|  |  |  | 			}, []); | 
					
						
							| 
									
										
										
										
											2015-07-13 06:20:09 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-21 10:44:55 +08:00
										 |  |  | 			return callback(null, entries, compilation); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-21 10:44:55 +08:00
										 |  |  | 	purgeInputFileSystem() { | 
					
						
							| 
									
										
										
										
											2018-05-29 20:50:40 +08:00
										 |  |  | 		if (this.inputFileSystem && this.inputFileSystem.purge) { | 
					
						
							| 
									
										
										
										
											2017-06-21 10:44:55 +08:00
										 |  |  | 			this.inputFileSystem.purge(); | 
					
						
							| 
									
										
										
										
											2018-05-29 20:50:40 +08:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2017-06-21 10:44:55 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2014-06-12 04:52:02 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-10 18:34:59 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {Compilation} compilation the compilation | 
					
						
							|  |  |  | 	 * @param {Callback<void>} callback signals when the assets are emitted | 
					
						
							|  |  |  | 	 * @returns {void} | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2017-06-21 10:44:55 +08:00
										 |  |  | 	emitAssets(compilation, callback) { | 
					
						
							|  |  |  | 		let outputPath; | 
					
						
							| 
									
										
										
										
											2014-03-12 01:42:51 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		const emitFiles = err => { | 
					
						
							|  |  |  | 			if (err) return callback(err); | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-10 03:53:04 +08:00
										 |  |  | 			asyncLib.forEachLimit( | 
					
						
							| 
									
										
										
										
											2019-09-11 17:13:46 +08:00
										 |  |  | 				compilation.getAssets(), | 
					
						
							| 
									
										
										
										
											2019-01-10 03:25:44 +08:00
										 |  |  | 				15, | 
					
						
							| 
									
										
										
										
											2019-09-11 17:13:46 +08:00
										 |  |  | 				({ name: file, source }, callback) => { | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 					let targetFile = file; | 
					
						
							|  |  |  | 					const queryStringIdx = targetFile.indexOf("?"); | 
					
						
							|  |  |  | 					if (queryStringIdx >= 0) { | 
					
						
							|  |  |  | 						targetFile = targetFile.substr(0, queryStringIdx); | 
					
						
							| 
									
										
										
										
											2017-06-21 10:44:55 +08:00
										 |  |  | 					} | 
					
						
							| 
									
										
										
										
											2017-01-17 13:57:27 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 					const writeOut = err => { | 
					
						
							|  |  |  | 						if (err) return callback(err); | 
					
						
							| 
									
										
										
										
											2019-06-11 19:09:42 +08:00
										 |  |  | 						const targetPath = join( | 
					
						
							|  |  |  | 							this.outputFileSystem, | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 							outputPath, | 
					
						
							|  |  |  | 							targetFile | 
					
						
							|  |  |  | 						); | 
					
						
							| 
									
										
										
										
											2019-01-19 03:38:34 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 						// check if the target file has already been written by this Compiler
 | 
					
						
							|  |  |  | 						const targetFileGeneration = this._assetEmittingWrittenFiles.get( | 
					
						
							|  |  |  | 							targetPath | 
					
						
							|  |  |  | 						); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 						// create an cache entry for this Source if not already existing
 | 
					
						
							|  |  |  | 						let cacheEntry = this._assetEmittingSourceCache.get(source); | 
					
						
							|  |  |  | 						if (cacheEntry === undefined) { | 
					
						
							|  |  |  | 							cacheEntry = { | 
					
						
							|  |  |  | 								sizeOnlySource: undefined, | 
					
						
							|  |  |  | 								writtenTo: new Map() | 
					
						
							|  |  |  | 							}; | 
					
						
							|  |  |  | 							this._assetEmittingSourceCache.set(source, cacheEntry); | 
					
						
							|  |  |  | 						} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 						// if the target file has already been written
 | 
					
						
							|  |  |  | 						if (targetFileGeneration !== undefined) { | 
					
						
							|  |  |  | 							// check if the Source has been written to this target file
 | 
					
						
							|  |  |  | 							const writtenGeneration = cacheEntry.writtenTo.get(targetPath); | 
					
						
							|  |  |  | 							if (writtenGeneration === targetFileGeneration) { | 
					
						
							|  |  |  | 								// if yes, we skip writing the file
 | 
					
						
							|  |  |  | 								// as it's already there
 | 
					
						
							|  |  |  | 								// (we assume one doesn't remove files while the Compiler is running)
 | 
					
						
							| 
									
										
										
										
											2019-09-11 17:13:46 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-09-13 17:12:26 +08:00
										 |  |  | 								compilation.updateAsset(file, cacheEntry.sizeOnlySource, { | 
					
						
							|  |  |  | 									size: cacheEntry.sizeOnlySource.size() | 
					
						
							|  |  |  | 								}); | 
					
						
							| 
									
										
										
										
											2019-01-17 20:07:17 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-19 03:38:34 +08:00
										 |  |  | 								return callback(); | 
					
						
							|  |  |  | 							} | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 						} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-09-13 17:12:26 +08:00
										 |  |  | 						// TODO webpack 5: if info.immutable check if file already exists in output
 | 
					
						
							|  |  |  | 						// skip emitting if it's already there
 | 
					
						
							| 
									
										
										
										
											2019-01-17 20:07:17 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-19 03:38:34 +08:00
										 |  |  | 						// get the binary (Buffer) content from the Source
 | 
					
						
							|  |  |  | 						/** @type {Buffer} */ | 
					
						
							| 
									
										
										
										
											2019-01-18 23:26:16 +08:00
										 |  |  | 						let content; | 
					
						
							|  |  |  | 						if (typeof source.buffer === "function") { | 
					
						
							|  |  |  | 							content = source.buffer(); | 
					
						
							|  |  |  | 						} else { | 
					
						
							| 
									
										
										
										
											2019-01-19 03:38:34 +08:00
										 |  |  | 							const bufferOrString = source.source(); | 
					
						
							|  |  |  | 							if (Buffer.isBuffer(bufferOrString)) { | 
					
						
							|  |  |  | 								content = bufferOrString; | 
					
						
							|  |  |  | 							} else { | 
					
						
							|  |  |  | 								content = Buffer.from(bufferOrString, "utf8"); | 
					
						
							| 
									
										
										
										
											2019-01-18 23:26:16 +08:00
										 |  |  | 							} | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 						} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-19 03:38:34 +08:00
										 |  |  | 						// Create a replacement resource which only allows to ask for size
 | 
					
						
							|  |  |  | 						// This allows to GC all memory allocated by the Source
 | 
					
						
							|  |  |  | 						// (expect when the Source is stored in any other cache)
 | 
					
						
							|  |  |  | 						cacheEntry.sizeOnlySource = new SizeOnlySource(content.length); | 
					
						
							| 
									
										
										
										
											2019-09-13 17:12:26 +08:00
										 |  |  | 						compilation.updateAsset(file, cacheEntry.sizeOnlySource, { | 
					
						
							|  |  |  | 							size: content.length | 
					
						
							|  |  |  | 						}); | 
					
						
							| 
									
										
										
										
											2019-01-19 03:38:34 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 						// Write the file to output file system
 | 
					
						
							|  |  |  | 						this.outputFileSystem.writeFile(targetPath, content, err => { | 
					
						
							|  |  |  | 							if (err) return callback(err); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 							// information marker that the asset has been emitted
 | 
					
						
							|  |  |  | 							compilation.emittedAssets.add(file); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 							// cache the information that the Source has been written to that location
 | 
					
						
							|  |  |  | 							const newGeneration = | 
					
						
							|  |  |  | 								targetFileGeneration === undefined | 
					
						
							|  |  |  | 									? 1 | 
					
						
							|  |  |  | 									: targetFileGeneration + 1; | 
					
						
							|  |  |  | 							cacheEntry.writtenTo.set(targetPath, newGeneration); | 
					
						
							|  |  |  | 							this._assetEmittingWrittenFiles.set(targetPath, newGeneration); | 
					
						
							| 
									
										
										
										
											2019-09-05 20:10:16 +08:00
										 |  |  | 							this.hooks.assetEmitted.callAsync( | 
					
						
							|  |  |  | 								file, | 
					
						
							|  |  |  | 								{ | 
					
						
							|  |  |  | 									content, | 
					
						
							|  |  |  | 									source, | 
					
						
							|  |  |  | 									outputPath, | 
					
						
							|  |  |  | 									compilation, | 
					
						
							|  |  |  | 									targetPath | 
					
						
							|  |  |  | 								}, | 
					
						
							|  |  |  | 								callback | 
					
						
							|  |  |  | 							); | 
					
						
							| 
									
										
										
										
											2019-01-19 03:38:34 +08:00
										 |  |  | 						}); | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 					}; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 					if (targetFile.match(/\/|\\/)) { | 
					
						
							| 
									
										
										
										
											2019-06-11 19:09:42 +08:00
										 |  |  | 						const fs = this.outputFileSystem; | 
					
						
							|  |  |  | 						const dir = dirname(fs, join(fs, outputPath, targetFile)); | 
					
						
							|  |  |  | 						mkdirp(fs, dir, writeOut); | 
					
						
							| 
									
										
										
										
											2018-05-29 20:50:40 +08:00
										 |  |  | 					} else { | 
					
						
							|  |  |  | 						writeOut(); | 
					
						
							|  |  |  | 					} | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 				}, | 
					
						
							|  |  |  | 				err => { | 
					
						
							|  |  |  | 					if (err) return callback(err); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 					this.hooks.afterEmit.callAsync(compilation, err => { | 
					
						
							|  |  |  | 						if (err) return callback(err); | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 						return callback(); | 
					
						
							|  |  |  | 					}); | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			); | 
					
						
							| 
									
										
										
										
											2017-08-11 13:52:25 +08:00
										 |  |  | 		}; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-27 22:27:37 +08:00
										 |  |  | 		this.hooks.emit.callAsync(compilation, err => { | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 			if (err) return callback(err); | 
					
						
							| 
									
										
										
										
											2018-08-23 01:23:48 +08:00
										 |  |  | 			outputPath = compilation.getPath(this.outputPath, {}); | 
					
						
							| 
									
										
										
										
											2019-06-11 19:09:42 +08:00
										 |  |  | 			mkdirp(this.outputFileSystem, outputPath, emitFiles); | 
					
						
							| 
									
										
										
										
											2017-08-11 13:52:25 +08:00
										 |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-10 18:34:59 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {Callback<void>} callback signals when the call finishes | 
					
						
							|  |  |  | 	 * @returns {void} | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2017-06-21 10:44:55 +08:00
										 |  |  | 	emitRecords(callback) { | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		if (!this.recordsOutputPath) return callback(); | 
					
						
							| 
									
										
										
										
											2017-11-08 18:32:05 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		const writeFile = () => { | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 			this.outputFileSystem.writeFile( | 
					
						
							|  |  |  | 				this.recordsOutputPath, | 
					
						
							| 
									
										
										
										
											2019-01-27 18:47:31 +08:00
										 |  |  | 				JSON.stringify( | 
					
						
							|  |  |  | 					this.records, | 
					
						
							|  |  |  | 					(n, value) => { | 
					
						
							|  |  |  | 						if ( | 
					
						
							|  |  |  | 							typeof value === "object" && | 
					
						
							|  |  |  | 							value !== null && | 
					
						
							|  |  |  | 							!Array.isArray(value) | 
					
						
							|  |  |  | 						) { | 
					
						
							|  |  |  | 							const keys = Object.keys(value); | 
					
						
							|  |  |  | 							if (!isSorted(keys)) { | 
					
						
							|  |  |  | 								return sortObject(value, keys); | 
					
						
							|  |  |  | 							} | 
					
						
							|  |  |  | 						} | 
					
						
							|  |  |  | 						return value; | 
					
						
							|  |  |  | 					}, | 
					
						
							|  |  |  | 					2 | 
					
						
							|  |  |  | 				), | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 				callback | 
					
						
							|  |  |  | 			); | 
					
						
							| 
									
										
										
										
											2017-11-08 18:32:05 +08:00
										 |  |  | 		}; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-11 19:09:42 +08:00
										 |  |  | 		const recordsOutputPathDirectory = dirname( | 
					
						
							|  |  |  | 			this.outputFileSystem, | 
					
						
							|  |  |  | 			this.recordsOutputPath | 
					
						
							|  |  |  | 		); | 
					
						
							| 
									
										
										
										
											2018-05-29 20:50:40 +08:00
										 |  |  | 		if (!recordsOutputPathDirectory) { | 
					
						
							|  |  |  | 			return writeFile(); | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2019-06-11 19:09:42 +08:00
										 |  |  | 		mkdirp(this.outputFileSystem, recordsOutputPathDirectory, err => { | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 			if (err) return callback(err); | 
					
						
							| 
									
										
										
										
											2017-11-08 18:32:05 +08:00
										 |  |  | 			writeFile(); | 
					
						
							| 
									
										
										
										
											2017-06-21 10:44:55 +08:00
										 |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2013-06-10 20:25:54 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-10 18:34:59 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {Callback<void>} callback signals when the call finishes | 
					
						
							|  |  |  | 	 * @returns {void} | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2017-06-21 10:44:55 +08:00
										 |  |  | 	readRecords(callback) { | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		if (!this.recordsInputPath) { | 
					
						
							| 
									
										
										
										
											2017-07-01 23:47:36 +08:00
										 |  |  | 			this.records = {}; | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 			return callback(); | 
					
						
							| 
									
										
										
										
											2017-06-21 10:44:55 +08:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2017-07-01 23:47:36 +08:00
										 |  |  | 		this.inputFileSystem.stat(this.recordsInputPath, err => { | 
					
						
							| 
									
										
										
										
											2017-06-21 10:44:55 +08:00
										 |  |  | 			// It doesn't exist
 | 
					
						
							| 
									
										
										
										
											2017-07-01 23:47:36 +08:00
										 |  |  | 			// We can ignore this.
 | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 			if (err) return callback(); | 
					
						
							| 
									
										
										
										
											2013-06-10 20:25:54 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-07-01 23:47:36 +08:00
										 |  |  | 			this.inputFileSystem.readFile(this.recordsInputPath, (err, content) => { | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 				if (err) return callback(err); | 
					
						
							| 
									
										
										
										
											2013-05-31 18:22:40 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-21 10:44:55 +08:00
										 |  |  | 				try { | 
					
						
							| 
									
										
										
										
											2018-05-19 17:09:30 +08:00
										 |  |  | 					this.records = parseJson(content.toString("utf-8")); | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 				} catch (e) { | 
					
						
							| 
									
										
										
										
											2017-06-21 10:44:55 +08:00
										 |  |  | 					e.message = "Cannot parse records: " + e.message; | 
					
						
							|  |  |  | 					return callback(e); | 
					
						
							|  |  |  | 				} | 
					
						
							| 
									
										
										
										
											2013-05-31 18:22:40 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-21 10:44:55 +08:00
										 |  |  | 				return callback(); | 
					
						
							|  |  |  | 			}); | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 		}); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-10 18:34:59 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {Compilation} compilation the compilation | 
					
						
							|  |  |  | 	 * @param {string} compilerName the compiler's name | 
					
						
							|  |  |  | 	 * @param {number} compilerIndex the compiler's index | 
					
						
							|  |  |  | 	 * @param {OutputOptions} outputOptions the output options | 
					
						
							|  |  |  | 	 * @param {WebpackPluginInstance[]} plugins the plugins to apply | 
					
						
							|  |  |  | 	 * @returns {Compiler} a child compiler | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 	createChildCompiler( | 
					
						
							|  |  |  | 		compilation, | 
					
						
							|  |  |  | 		compilerName, | 
					
						
							|  |  |  | 		compilerIndex, | 
					
						
							|  |  |  | 		outputOptions, | 
					
						
							|  |  |  | 		plugins | 
					
						
							|  |  |  | 	) { | 
					
						
							| 
									
										
										
										
											2017-12-01 17:44:22 +08:00
										 |  |  | 		const childCompiler = new Compiler(this.context); | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		if (Array.isArray(plugins)) { | 
					
						
							| 
									
										
										
										
											2018-05-29 20:50:40 +08:00
										 |  |  | 			for (const plugin of plugins) { | 
					
						
							|  |  |  | 				plugin.apply(childCompiler); | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2017-06-21 10:44:55 +08:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		for (const name in this.hooks) { | 
					
						
							|  |  |  | 			if ( | 
					
						
							|  |  |  | 				![ | 
					
						
							|  |  |  | 					"make", | 
					
						
							|  |  |  | 					"compile", | 
					
						
							|  |  |  | 					"emit", | 
					
						
							|  |  |  | 					"afterEmit", | 
					
						
							|  |  |  | 					"invalid", | 
					
						
							|  |  |  | 					"done", | 
					
						
							|  |  |  | 					"thisCompilation" | 
					
						
							|  |  |  | 				].includes(name) | 
					
						
							|  |  |  | 			) { | 
					
						
							| 
									
										
										
										
											2018-05-29 20:50:40 +08:00
										 |  |  | 				if (childCompiler.hooks[name]) { | 
					
						
							| 
									
										
										
										
											2017-11-27 22:27:37 +08:00
										 |  |  | 					childCompiler.hooks[name].taps = this.hooks[name].taps.slice(); | 
					
						
							| 
									
										
										
										
											2018-05-29 20:50:40 +08:00
										 |  |  | 				} | 
					
						
							| 
									
										
										
										
											2017-11-27 22:27:37 +08:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2017-06-21 10:44:55 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		childCompiler.name = compilerName; | 
					
						
							|  |  |  | 		childCompiler.outputPath = this.outputPath; | 
					
						
							|  |  |  | 		childCompiler.inputFileSystem = this.inputFileSystem; | 
					
						
							|  |  |  | 		childCompiler.outputFileSystem = null; | 
					
						
							| 
									
										
										
										
											2017-11-17 21:26:23 +08:00
										 |  |  | 		childCompiler.resolverFactory = this.resolverFactory; | 
					
						
							| 
									
										
										
										
											2017-06-21 10:44:55 +08:00
										 |  |  | 		childCompiler.fileTimestamps = this.fileTimestamps; | 
					
						
							|  |  |  | 		childCompiler.contextTimestamps = this.contextTimestamps; | 
					
						
							| 
									
										
										
										
											2018-09-26 16:28:16 +08:00
										 |  |  | 		childCompiler.compilerPath = | 
					
						
							|  |  |  | 			this.compilerPath + "/" + compilerName + compilerIndex; | 
					
						
							| 
									
										
										
										
											2017-06-21 10:44:55 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-27 13:22:19 +08:00
										 |  |  | 		const relativeCompilerName = makePathsRelative( | 
					
						
							|  |  |  | 			this.context, | 
					
						
							|  |  |  | 			compilerName, | 
					
						
							|  |  |  | 			this.root | 
					
						
							|  |  |  | 		); | 
					
						
							| 
									
										
										
										
											2018-05-29 20:50:40 +08:00
										 |  |  | 		if (!this.records[relativeCompilerName]) { | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 			this.records[relativeCompilerName] = []; | 
					
						
							| 
									
										
										
										
											2018-05-29 20:50:40 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		if (this.records[relativeCompilerName][compilerIndex]) { | 
					
						
							| 
									
										
										
										
											2017-06-21 10:44:55 +08:00
										 |  |  | 			childCompiler.records = this.records[relativeCompilerName][compilerIndex]; | 
					
						
							| 
									
										
										
										
											2018-05-29 20:50:40 +08:00
										 |  |  | 		} else { | 
					
						
							|  |  |  | 			this.records[relativeCompilerName].push((childCompiler.records = {})); | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2017-06-21 10:44:55 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		childCompiler.options = Object.create(this.options); | 
					
						
							|  |  |  | 		childCompiler.options.output = Object.create(childCompiler.options.output); | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		for (const name in outputOptions) { | 
					
						
							| 
									
										
										
										
											2017-06-21 10:44:55 +08:00
										 |  |  | 			childCompiler.options.output[name] = outputOptions[name]; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		childCompiler.parentCompilation = compilation; | 
					
						
							| 
									
										
										
										
											2018-09-27 13:22:19 +08:00
										 |  |  | 		childCompiler.root = this.root; | 
					
						
							| 
									
										
										
										
											2017-09-13 22:29:37 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		compilation.hooks.childCompiler.call( | 
					
						
							|  |  |  | 			childCompiler, | 
					
						
							|  |  |  | 			compilerName, | 
					
						
							|  |  |  | 			compilerIndex | 
					
						
							|  |  |  | 		); | 
					
						
							| 
									
										
										
										
											2017-09-13 22:29:37 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-21 10:44:55 +08:00
										 |  |  | 		return childCompiler; | 
					
						
							| 
									
										
										
										
											2013-06-10 20:25:54 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2013-05-31 18:22:40 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-21 10:44:55 +08:00
										 |  |  | 	isChild() { | 
					
						
							|  |  |  | 		return !!this.parentCompilation; | 
					
						
							| 
									
										
										
										
											2013-05-31 18:22:40 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-21 10:44:55 +08:00
										 |  |  | 	createCompilation() { | 
					
						
							|  |  |  | 		return new Compilation(this); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2013-05-31 18:22:40 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-10 18:34:59 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {CompilationParams} params the compilation parameters | 
					
						
							|  |  |  | 	 * @returns {Compilation} the created compilation | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2017-06-21 10:44:55 +08:00
										 |  |  | 	newCompilation(params) { | 
					
						
							|  |  |  | 		const compilation = this.createCompilation(); | 
					
						
							|  |  |  | 		compilation.name = this.name; | 
					
						
							|  |  |  | 		compilation.records = this.records; | 
					
						
							| 
									
										
										
										
											2017-11-27 22:27:37 +08:00
										 |  |  | 		this.hooks.thisCompilation.call(compilation, params); | 
					
						
							|  |  |  | 		this.hooks.compilation.call(compilation, params); | 
					
						
							| 
									
										
										
										
											2017-06-21 10:44:55 +08:00
										 |  |  | 		return compilation; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2013-05-31 18:22:40 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-21 10:44:55 +08:00
										 |  |  | 	createNormalModuleFactory() { | 
					
						
							| 
									
										
										
										
											2019-06-11 19:09:42 +08:00
										 |  |  | 		const normalModuleFactory = new NormalModuleFactory({ | 
					
						
							|  |  |  | 			context: this.options.context, | 
					
						
							|  |  |  | 			fs: this.inputFileSystem, | 
					
						
							|  |  |  | 			resolverFactory: this.resolverFactory, | 
					
						
							|  |  |  | 			options: this.options.module || {} | 
					
						
							|  |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2017-11-27 22:27:37 +08:00
										 |  |  | 		this.hooks.normalModuleFactory.call(normalModuleFactory); | 
					
						
							| 
									
										
										
										
											2017-06-21 10:44:55 +08:00
										 |  |  | 		return normalModuleFactory; | 
					
						
							| 
									
										
										
										
											2017-01-18 05:26:38 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2013-02-04 21:44:34 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-21 10:44:55 +08:00
										 |  |  | 	createContextModuleFactory() { | 
					
						
							| 
									
										
										
										
											2018-03-29 13:03:28 +08:00
										 |  |  | 		const contextModuleFactory = new ContextModuleFactory(this.resolverFactory); | 
					
						
							| 
									
										
										
										
											2017-11-27 22:27:37 +08:00
										 |  |  | 		this.hooks.contextModuleFactory.call(contextModuleFactory); | 
					
						
							| 
									
										
										
										
											2017-06-21 10:44:55 +08:00
										 |  |  | 		return contextModuleFactory; | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2016-09-14 18:04:42 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-21 10:44:55 +08:00
										 |  |  | 	newCompilationParams() { | 
					
						
							|  |  |  | 		const params = { | 
					
						
							|  |  |  | 			normalModuleFactory: this.createNormalModuleFactory(), | 
					
						
							| 
									
										
										
										
											2019-01-05 02:17:37 +08:00
										 |  |  | 			contextModuleFactory: this.createContextModuleFactory() | 
					
						
							| 
									
										
										
										
											2017-06-21 10:44:55 +08:00
										 |  |  | 		}; | 
					
						
							|  |  |  | 		return params; | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2016-07-13 17:03:14 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-10 18:34:59 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {Callback<Compilation>} callback signals when the compilation finishes | 
					
						
							|  |  |  | 	 * @returns {void} | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2017-06-21 10:44:55 +08:00
										 |  |  | 	compile(callback) { | 
					
						
							| 
									
										
										
										
											2017-07-01 23:47:36 +08:00
										 |  |  | 		const params = this.newCompilationParams(); | 
					
						
							| 
									
										
										
										
											2017-11-27 22:27:37 +08:00
										 |  |  | 		this.hooks.beforeCompile.callAsync(params, err => { | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 			if (err) return callback(err); | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-27 22:27:37 +08:00
										 |  |  | 			this.hooks.compile.call(params); | 
					
						
							| 
									
										
										
										
											2016-09-14 18:04:42 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-07-01 23:47:36 +08:00
										 |  |  | 			const compilation = this.newCompilation(params); | 
					
						
							| 
									
										
										
										
											2017-06-21 10:44:55 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-07-26 19:44:28 +08:00
										 |  |  | 			const logger = compilation.getLogger("webpack.Compiler"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			logger.time("make hook"); | 
					
						
							| 
									
										
										
										
											2017-11-27 22:27:37 +08:00
										 |  |  | 			this.hooks.make.callAsync(compilation, err => { | 
					
						
							| 
									
										
										
										
											2019-07-26 19:44:28 +08:00
										 |  |  | 				logger.timeEnd("make hook"); | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 				if (err) return callback(err); | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-05 18:19:30 +08:00
										 |  |  | 				process.nextTick(() => { | 
					
						
							| 
									
										
										
										
											2019-07-26 19:44:28 +08:00
										 |  |  | 					logger.time("finish compilation"); | 
					
						
							| 
									
										
										
										
											2019-01-05 18:19:30 +08:00
										 |  |  | 					compilation.finish(err => { | 
					
						
							| 
									
										
										
										
											2019-07-26 19:44:28 +08:00
										 |  |  | 						logger.timeEnd("finish compilation"); | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 						if (err) return callback(err); | 
					
						
							| 
									
										
										
										
											2017-06-21 10:44:55 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-07-26 19:44:28 +08:00
										 |  |  | 						logger.time("seal compilation"); | 
					
						
							| 
									
										
										
										
											2019-01-05 18:19:30 +08:00
										 |  |  | 						compilation.seal(err => { | 
					
						
							| 
									
										
										
										
											2019-07-26 19:44:28 +08:00
										 |  |  | 							logger.timeEnd("seal compilation"); | 
					
						
							| 
									
										
										
										
											2018-12-30 21:54:47 +08:00
										 |  |  | 							if (err) return callback(err); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-07-26 19:44:28 +08:00
										 |  |  | 							logger.time("afterCompile hook"); | 
					
						
							| 
									
										
										
										
											2019-01-05 18:19:30 +08:00
										 |  |  | 							this.hooks.afterCompile.callAsync(compilation, err => { | 
					
						
							| 
									
										
										
										
											2019-07-26 19:44:28 +08:00
										 |  |  | 								logger.timeEnd("afterCompile hook"); | 
					
						
							| 
									
										
										
										
											2019-01-05 18:19:30 +08:00
										 |  |  | 								if (err) return callback(err); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 								return callback(null, compilation); | 
					
						
							|  |  |  | 							}); | 
					
						
							| 
									
										
										
										
											2018-12-30 21:54:47 +08:00
										 |  |  | 						}); | 
					
						
							| 
									
										
										
										
											2017-06-21 10:44:55 +08:00
										 |  |  | 					}); | 
					
						
							| 
									
										
										
										
											2016-09-14 18:04:42 +08:00
										 |  |  | 				}); | 
					
						
							| 
									
										
										
										
											2016-10-18 02:26:22 +08:00
										 |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2017-06-21 10:44:55 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-09-27 13:22:19 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-10 18:34:59 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {Callback<void>} callback signals when the compiler closes | 
					
						
							|  |  |  | 	 * @returns {void} | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2018-09-27 13:22:19 +08:00
										 |  |  | 	close(callback) { | 
					
						
							|  |  |  | 		this.cache.shutdown(callback); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-07-01 23:59:43 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | module.exports = Compiler; |