| 
									
										
										
										
											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-02-11 11:16:18 +08:00
										 |  |  | "use strict"; | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-30 23:08:51 +08:00
										 |  |  | const { getContext, runLoaders } = require("loader-runner"); | 
					
						
							| 
									
										
										
										
											2018-09-27 13:22:19 +08:00
										 |  |  | const asyncLib = require("neo-async"); | 
					
						
							| 
									
										
										
										
											2018-03-22 19:05:58 +08:00
										 |  |  | const { | 
					
						
							|  |  |  | 	CachedSource, | 
					
						
							|  |  |  | 	LineToLineMappedSource, | 
					
						
							|  |  |  | 	OriginalSource, | 
					
						
							|  |  |  | 	RawSource, | 
					
						
							|  |  |  | 	SourceMapSource | 
					
						
							|  |  |  | } = require("webpack-sources"); | 
					
						
							| 
									
										
										
										
											2017-02-12 21:08:41 +08:00
										 |  |  | const Module = require("./Module"); | 
					
						
							| 
									
										
										
										
											2017-02-11 11:16:18 +08:00
										 |  |  | const ModuleBuildError = require("./ModuleBuildError"); | 
					
						
							|  |  |  | const ModuleError = require("./ModuleError"); | 
					
						
							| 
									
										
										
										
											2018-07-30 23:08:51 +08:00
										 |  |  | const ModuleParseError = require("./ModuleParseError"); | 
					
						
							| 
									
										
										
										
											2017-02-11 11:16:18 +08:00
										 |  |  | const ModuleWarning = require("./ModuleWarning"); | 
					
						
							| 
									
										
										
										
											2018-07-30 23:08:51 +08:00
										 |  |  | const WebpackError = require("./WebpackError"); | 
					
						
							| 
									
										
										
										
											2018-09-26 15:14:44 +08:00
										 |  |  | const compareLocations = require("./compareLocations"); | 
					
						
							| 
									
										
										
										
											2018-10-18 15:20:59 +08:00
										 |  |  | const { | 
					
						
							|  |  |  | 	concatComparators, | 
					
						
							|  |  |  | 	compareSelect, | 
					
						
							|  |  |  | 	keepOriginalOrder | 
					
						
							|  |  |  | } = require("./util/comparators"); | 
					
						
							| 
									
										
										
										
											2018-04-27 20:24:43 +08:00
										 |  |  | const createHash = require("./util/createHash"); | 
					
						
							| 
									
										
										
										
											2018-07-04 15:59:22 +08:00
										 |  |  | const contextify = require("./util/identifier").contextify; | 
					
						
							| 
									
										
										
										
											2018-10-09 20:30:59 +08:00
										 |  |  | const makeSerializable = require("./util/makeSerializable"); | 
					
						
							| 
									
										
										
										
											2017-02-11 11:16:18 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-30 23:08:51 +08:00
										 |  |  | /** @typedef {import("webpack-sources").Source} Source */ | 
					
						
							| 
									
										
										
										
											2018-08-23 01:23:48 +08:00
										 |  |  | /** @typedef {import("./ChunkGraph")} ChunkGraph */ | 
					
						
							| 
									
										
										
										
											2018-07-25 18:12:17 +08:00
										 |  |  | /** @typedef {import("./Compilation")} Compilation */ | 
					
						
							| 
									
										
										
										
											2018-07-30 23:08:51 +08:00
										 |  |  | /** @typedef {import("./DependencyTemplates")} DependencyTemplates */ | 
					
						
							| 
									
										
										
										
											2018-07-20 22:24:35 +08:00
										 |  |  | /** @typedef {import("./Module").LibIdentOptions} LibIdentOptions */ | 
					
						
							| 
									
										
										
										
											2018-09-26 15:14:44 +08:00
										 |  |  | /** @typedef {import("./Module").NeedBuildContext} NeedBuildContext */ | 
					
						
							| 
									
										
										
										
											2018-07-18 00:57:03 +08:00
										 |  |  | /** @typedef {import("./Module").SourceContext} SourceContext */ | 
					
						
							| 
									
										
										
										
											2018-07-25 18:12:17 +08:00
										 |  |  | /** @typedef {import("./RequestShortener")} RequestShortener */ | 
					
						
							|  |  |  | /** @typedef {import("./RuntimeTemplate")} RuntimeTemplate */ | 
					
						
							| 
									
										
										
										
											2018-07-30 23:08:51 +08:00
										 |  |  | /** @typedef {import("./util/createHash").Hash} Hash */ | 
					
						
							| 
									
										
										
										
											2018-07-11 19:05:13 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-27 13:22:19 +08:00
										 |  |  | const EARLY_RETURN_ERROR = new Error("flags early return is not an error"); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | const asString = buf => { | 
					
						
							|  |  |  | 	if (Buffer.isBuffer(buf)) { | 
					
						
							| 
									
										
										
										
											2016-01-04 04:42:56 +08:00
										 |  |  | 		return buf.toString("utf-8"); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return buf; | 
					
						
							| 
									
										
										
										
											2017-11-08 18:32:05 +08:00
										 |  |  | }; | 
					
						
							| 
									
										
										
										
											2016-01-04 04:42:56 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-30 20:56:57 +08:00
										 |  |  | const asBuffer = str => { | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 	if (!Buffer.isBuffer(str)) { | 
					
						
							| 
									
										
										
										
											2018-01-22 22:00:12 +08:00
										 |  |  | 		return Buffer.from(str, "utf-8"); | 
					
						
							| 
									
										
										
										
											2017-10-30 20:56:57 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	return str; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-25 05:17:47 +08:00
										 |  |  | class NonErrorEmittedError extends WebpackError { | 
					
						
							| 
									
										
										
										
											2017-03-22 20:00:57 +08:00
										 |  |  | 	constructor(error) { | 
					
						
							|  |  |  | 		super(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		this.name = "NonErrorEmittedError"; | 
					
						
							|  |  |  | 		this.message = "(Emitted value instead of an instance of Error) " + error; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		Error.captureStackTrace(this, this.constructor); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-25 16:49:51 +08:00
										 |  |  | makeSerializable( | 
					
						
							|  |  |  | 	NonErrorEmittedError, | 
					
						
							|  |  |  | 	"webpack/lib/NormalModule", | 
					
						
							|  |  |  | 	"NonErrorEmittedError" | 
					
						
							|  |  |  | ); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-28 00:53:07 +08:00
										 |  |  | /** | 
					
						
							|  |  |  |  * @typedef {Object} CachedSourceEntry | 
					
						
							| 
									
										
										
										
											2018-05-08 20:31:51 +08:00
										 |  |  |  * @property {TODO} source the generated source | 
					
						
							| 
									
										
										
										
											2018-04-28 00:53:07 +08:00
										 |  |  |  * @property {string} hash the hash value | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-11 11:16:18 +08:00
										 |  |  | class NormalModule extends Module { | 
					
						
							| 
									
										
										
										
											2018-01-24 06:09:26 +08:00
										 |  |  | 	constructor({ | 
					
						
							|  |  |  | 		type, | 
					
						
							|  |  |  | 		request, | 
					
						
							|  |  |  | 		userRequest, | 
					
						
							|  |  |  | 		rawRequest, | 
					
						
							|  |  |  | 		loaders, | 
					
						
							|  |  |  | 		resource, | 
					
						
							| 
									
										
										
										
											2018-06-01 20:54:54 +08:00
										 |  |  | 		matchResource, | 
					
						
							| 
									
										
										
										
											2018-01-24 06:09:26 +08:00
										 |  |  | 		parser, | 
					
						
							|  |  |  | 		generator, | 
					
						
							|  |  |  | 		resolveOptions | 
					
						
							|  |  |  | 	}) { | 
					
						
							| 
									
										
										
										
											2018-01-31 04:40:44 +08:00
										 |  |  | 		super(type, getContext(resource)); | 
					
						
							| 
									
										
										
										
											2017-11-06 20:02:35 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		// Info from Factory
 | 
					
						
							| 
									
										
										
										
											2017-02-11 11:16:18 +08:00
										 |  |  | 		this.request = request; | 
					
						
							|  |  |  | 		this.userRequest = userRequest; | 
					
						
							|  |  |  | 		this.rawRequest = rawRequest; | 
					
						
							| 
									
										
										
										
											2017-10-30 20:56:57 +08:00
										 |  |  | 		this.binary = type.startsWith("webassembly"); | 
					
						
							| 
									
										
										
										
											2017-02-11 11:16:18 +08:00
										 |  |  | 		this.parser = parser; | 
					
						
							| 
									
										
										
										
											2018-01-24 06:09:26 +08:00
										 |  |  | 		this.generator = generator; | 
					
						
							| 
									
										
										
										
											2017-02-11 11:16:18 +08:00
										 |  |  | 		this.resource = resource; | 
					
						
							| 
									
										
										
										
											2018-06-01 20:54:54 +08:00
										 |  |  | 		this.matchResource = matchResource; | 
					
						
							| 
									
										
										
										
											2017-02-11 11:16:18 +08:00
										 |  |  | 		this.loaders = loaders; | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		if (resolveOptions !== undefined) this.resolveOptions = resolveOptions; | 
					
						
							| 
									
										
										
										
											2017-11-06 20:02:35 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		// Info from Build
 | 
					
						
							| 
									
										
										
										
											2017-02-11 11:16:18 +08:00
										 |  |  | 		this.error = null; | 
					
						
							|  |  |  | 		this._source = null; | 
					
						
							| 
									
										
										
										
											2018-04-27 20:24:43 +08:00
										 |  |  | 		this._buildHash = ""; | 
					
						
							| 
									
										
										
										
											2017-11-06 20:02:35 +08:00
										 |  |  | 		this.buildTimestamp = undefined; | 
					
						
							| 
									
										
										
										
											2018-04-28 00:53:07 +08:00
										 |  |  | 		/** @private @type {Map<string, CachedSourceEntry>} */ | 
					
						
							|  |  |  | 		this._cachedSources = new Map(); | 
					
						
							| 
									
										
										
										
											2017-11-06 20:02:35 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		// Options for the NormalModule set by plugins
 | 
					
						
							|  |  |  | 		// TODO refactor this -> options object filled from Factory
 | 
					
						
							|  |  |  | 		this.useSourceMap = false; | 
					
						
							|  |  |  | 		this.lineToLine = false; | 
					
						
							| 
									
										
										
										
											2017-12-07 00:26:02 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		// Cache
 | 
					
						
							|  |  |  | 		this._lastSuccessfulBuildMeta = {}; | 
					
						
							| 
									
										
										
										
											2018-09-12 00:47:55 +08:00
										 |  |  | 		this._forceBuild = true; | 
					
						
							| 
									
										
										
										
											2017-02-11 11:16:18 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2016-09-14 18:04:42 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-25 18:12:17 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @returns {string} a unique identifier of the module | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2017-02-11 11:16:18 +08:00
										 |  |  | 	identifier() { | 
					
						
							|  |  |  | 		return this.request; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2016-01-04 04:42:56 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-25 18:12:17 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {RequestShortener} requestShortener the request shortener | 
					
						
							|  |  |  | 	 * @returns {string} a user readable identifier of the module | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2017-02-11 11:16:18 +08:00
										 |  |  | 	readableIdentifier(requestShortener) { | 
					
						
							|  |  |  | 		return requestShortener.shorten(this.userRequest); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2016-01-04 04:42:56 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-20 22:24:35 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {LibIdentOptions} options options | 
					
						
							|  |  |  | 	 * @returns {string | null} an identifier for library inclusion | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2017-02-11 11:16:18 +08:00
										 |  |  | 	libIdent(options) { | 
					
						
							| 
									
										
										
										
											2017-02-14 17:38:47 +08:00
										 |  |  | 		return contextify(options.context, this.userRequest); | 
					
						
							| 
									
										
										
										
											2017-02-11 11:16:18 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2016-01-04 04:42:56 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-25 18:12:17 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @returns {string | null} absolute path which should be used for condition matching (usually the resource path) | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2017-02-11 11:16:18 +08:00
										 |  |  | 	nameForCondition() { | 
					
						
							| 
									
										
										
										
											2018-06-01 20:54:54 +08:00
										 |  |  | 		const resource = this.matchResource || this.resource; | 
					
						
							|  |  |  | 		const idx = resource.indexOf("?"); | 
					
						
							|  |  |  | 		if (idx >= 0) return resource.substr(0, idx); | 
					
						
							|  |  |  | 		return resource; | 
					
						
							| 
									
										
										
										
											2017-02-11 11:16:18 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-25 18:12:17 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * Assuming this module is in the cache. Update the (cached) module with | 
					
						
							|  |  |  | 	 * the fresh module from the factory. Usually updates internal references | 
					
						
							|  |  |  | 	 * and properties. | 
					
						
							|  |  |  | 	 * @param {Module} module fresh module | 
					
						
							|  |  |  | 	 * @returns {void} | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2018-03-28 22:19:15 +08:00
										 |  |  | 	updateCacheModule(module) { | 
					
						
							| 
									
										
										
										
											2018-10-09 20:30:59 +08:00
										 |  |  | 		super.updateCacheModule(module); | 
					
						
							| 
									
										
										
										
											2018-07-25 18:12:17 +08:00
										 |  |  | 		const m = /** @type {NormalModule} */ (module); | 
					
						
							|  |  |  | 		this.request = m.request; | 
					
						
							|  |  |  | 		this.userRequest = m.userRequest; | 
					
						
							|  |  |  | 		this.rawRequest = m.rawRequest; | 
					
						
							|  |  |  | 		this.parser = m.parser; | 
					
						
							|  |  |  | 		this.generator = m.generator; | 
					
						
							|  |  |  | 		this.resource = m.resource; | 
					
						
							|  |  |  | 		this.matchResource = m.matchResource; | 
					
						
							|  |  |  | 		this.loaders = m.loaders; | 
					
						
							| 
									
										
										
										
											2018-03-28 22:19:15 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-11 14:07:01 +08:00
										 |  |  | 	createSourceForAsset(name, content, sourceMap) { | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		if (!sourceMap) { | 
					
						
							| 
									
										
										
										
											2017-02-11 14:07:01 +08:00
										 |  |  | 			return new RawSource(content); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		if (typeof sourceMap === "string") { | 
					
						
							| 
									
										
										
										
											2017-02-11 14:07:01 +08:00
										 |  |  | 			return new OriginalSource(content, sourceMap); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		return new SourceMapSource(content, name, sourceMap); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-11 12:32:48 +08:00
										 |  |  | 	createLoaderContext(resolver, options, compilation, fs) { | 
					
						
							| 
									
										
										
										
											2018-03-18 22:56:36 +08:00
										 |  |  | 		const requestShortener = compilation.runtimeTemplate.requestShortener; | 
					
						
							| 
									
										
										
										
											2017-02-11 11:16:18 +08:00
										 |  |  | 		const loaderContext = { | 
					
						
							|  |  |  | 			version: 2, | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 			emitWarning: warning => { | 
					
						
							| 
									
										
										
										
											2018-05-29 20:50:40 +08:00
										 |  |  | 				if (!(warning instanceof Error)) { | 
					
						
							| 
									
										
										
										
											2017-03-22 20:00:57 +08:00
										 |  |  | 					warning = new NonErrorEmittedError(warning); | 
					
						
							| 
									
										
										
										
											2018-05-29 20:50:40 +08:00
										 |  |  | 				} | 
					
						
							| 
									
										
										
										
											2018-03-02 17:57:46 +08:00
										 |  |  | 				const currentLoader = this.getCurrentLoader(loaderContext); | 
					
						
							|  |  |  | 				this.warnings.push( | 
					
						
							| 
									
										
										
										
											2018-10-30 05:18:08 +08:00
										 |  |  | 					new ModuleWarning(warning, { | 
					
						
							| 
									
										
										
										
											2018-03-18 22:56:36 +08:00
										 |  |  | 						from: requestShortener.shorten(currentLoader.loader) | 
					
						
							| 
									
										
										
										
											2018-03-02 17:57:46 +08:00
										 |  |  | 					}) | 
					
						
							|  |  |  | 				); | 
					
						
							| 
									
										
										
										
											2017-02-11 11:16:18 +08:00
										 |  |  | 			}, | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 			emitError: error => { | 
					
						
							| 
									
										
										
										
											2018-05-29 20:50:40 +08:00
										 |  |  | 				if (!(error instanceof Error)) { | 
					
						
							|  |  |  | 					error = new NonErrorEmittedError(error); | 
					
						
							|  |  |  | 				} | 
					
						
							| 
									
										
										
										
											2018-03-02 17:57:46 +08:00
										 |  |  | 				const currentLoader = this.getCurrentLoader(loaderContext); | 
					
						
							|  |  |  | 				this.errors.push( | 
					
						
							| 
									
										
										
										
											2018-10-30 05:18:08 +08:00
										 |  |  | 					new ModuleError(error, { | 
					
						
							| 
									
										
										
										
											2018-03-18 22:56:36 +08:00
										 |  |  | 						from: requestShortener.shorten(currentLoader.loader) | 
					
						
							| 
									
										
										
										
											2018-03-02 17:57:46 +08:00
										 |  |  | 					}) | 
					
						
							|  |  |  | 				); | 
					
						
							| 
									
										
										
										
											2017-02-11 11:16:18 +08:00
										 |  |  | 			}, | 
					
						
							| 
									
										
										
										
											2017-02-12 21:08:41 +08:00
										 |  |  | 			resolve(context, request, callback) { | 
					
						
							| 
									
										
										
										
											2017-12-31 23:23:45 +08:00
										 |  |  | 				resolver.resolve({}, context, request, {}, callback); | 
					
						
							| 
									
										
										
										
											2017-02-11 11:16:18 +08:00
										 |  |  | 			}, | 
					
						
							| 
									
										
										
										
											2017-02-11 12:32:48 +08:00
										 |  |  | 			emitFile: (name, content, sourceMap) => { | 
					
						
							| 
									
										
										
										
											2018-05-29 20:50:40 +08:00
										 |  |  | 				if (!this.buildInfo.assets) { | 
					
						
							|  |  |  | 					this.buildInfo.assets = Object.create(null); | 
					
						
							|  |  |  | 				} | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 				this.buildInfo.assets[name] = this.createSourceForAsset( | 
					
						
							|  |  |  | 					name, | 
					
						
							|  |  |  | 					content, | 
					
						
							|  |  |  | 					sourceMap | 
					
						
							|  |  |  | 				); | 
					
						
							| 
									
										
										
										
											2017-02-11 12:32:48 +08:00
										 |  |  | 			}, | 
					
						
							| 
									
										
										
										
											2017-09-14 15:00:22 +08:00
										 |  |  | 			rootContext: options.context, | 
					
						
							| 
									
										
										
										
											2017-02-11 12:32:48 +08:00
										 |  |  | 			webpack: true, | 
					
						
							|  |  |  | 			sourceMap: !!this.useSourceMap, | 
					
						
							|  |  |  | 			_module: this, | 
					
						
							|  |  |  | 			_compilation: compilation, | 
					
						
							|  |  |  | 			_compiler: compilation.compiler, | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 			fs: fs | 
					
						
							| 
									
										
										
										
											2017-02-11 11:16:18 +08:00
										 |  |  | 		}; | 
					
						
							| 
									
										
										
										
											2017-02-11 12:32:48 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-27 22:27:30 +08:00
										 |  |  | 		compilation.hooks.normalModuleLoader.call(loaderContext, this); | 
					
						
							| 
									
										
										
										
											2018-05-29 20:50:40 +08:00
										 |  |  | 		if (options.loader) { | 
					
						
							|  |  |  | 			Object.assign(loaderContext, options.loader); | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2017-02-11 12:32:48 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		return loaderContext; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-05 17:58:10 +08:00
										 |  |  | 	getCurrentLoader(loaderContext, index = loaderContext.loaderIndex) { | 
					
						
							| 
									
										
										
										
											2018-03-02 17:57:46 +08:00
										 |  |  | 		if ( | 
					
						
							|  |  |  | 			this.loaders && | 
					
						
							|  |  |  | 			this.loaders.length && | 
					
						
							| 
									
										
										
										
											2018-06-05 17:58:10 +08:00
										 |  |  | 			index < this.loaders.length && | 
					
						
							|  |  |  | 			index >= 0 && | 
					
						
							|  |  |  | 			this.loaders[index] | 
					
						
							| 
									
										
										
										
											2018-03-02 17:57:46 +08:00
										 |  |  | 		) { | 
					
						
							| 
									
										
										
										
											2018-06-05 17:58:10 +08:00
										 |  |  | 			return this.loaders[index]; | 
					
						
							| 
									
										
										
										
											2018-03-02 17:57:46 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		return null; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-11 14:07:18 +08:00
										 |  |  | 	createSource(source, resourceBuffer, sourceMap) { | 
					
						
							| 
									
										
										
										
											2017-02-11 12:57:52 +08:00
										 |  |  | 		// if there is no identifier return raw source
 | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		if (!this.identifier) { | 
					
						
							| 
									
										
										
										
											2017-02-11 12:57:52 +08:00
										 |  |  | 			return new RawSource(source); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		// from here on we assume we have an identifier
 | 
					
						
							|  |  |  | 		const identifier = this.identifier(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		if (this.lineToLine && resourceBuffer) { | 
					
						
							| 
									
										
										
										
											2017-02-11 12:57:52 +08:00
										 |  |  | 			return new LineToLineMappedSource( | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 				source, | 
					
						
							|  |  |  | 				identifier, | 
					
						
							|  |  |  | 				asString(resourceBuffer) | 
					
						
							|  |  |  | 			); | 
					
						
							| 
									
										
										
										
											2017-02-11 12:57:52 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		if (this.useSourceMap && sourceMap) { | 
					
						
							| 
									
										
										
										
											2017-02-11 12:57:52 +08:00
										 |  |  | 			return new SourceMapSource(source, identifier, sourceMap); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		if (Buffer.isBuffer(source)) { | 
					
						
							| 
									
										
										
										
											2018-05-04 00:57:02 +08:00
										 |  |  | 			// @ts-ignore
 | 
					
						
							|  |  |  | 			// TODO We need to fix @types/webpack-sources to allow RawSource to take a Buffer | string
 | 
					
						
							| 
									
										
										
										
											2017-10-30 20:56:57 +08:00
										 |  |  | 			return new RawSource(source); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-11 12:57:52 +08:00
										 |  |  | 		return new OriginalSource(source, identifier); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-11 12:32:48 +08:00
										 |  |  | 	doBuild(options, compilation, resolver, fs, callback) { | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		const loaderContext = this.createLoaderContext( | 
					
						
							|  |  |  | 			resolver, | 
					
						
							|  |  |  | 			options, | 
					
						
							|  |  |  | 			compilation, | 
					
						
							|  |  |  | 			fs | 
					
						
							|  |  |  | 		); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		runLoaders( | 
					
						
							|  |  |  | 			{ | 
					
						
							|  |  |  | 				resource: this.resource, | 
					
						
							|  |  |  | 				loaders: this.loaders, | 
					
						
							|  |  |  | 				context: loaderContext, | 
					
						
							|  |  |  | 				readResource: fs.readFile.bind(fs) | 
					
						
							|  |  |  | 			}, | 
					
						
							|  |  |  | 			(err, result) => { | 
					
						
							|  |  |  | 				if (result) { | 
					
						
							|  |  |  | 					this.buildInfo.cacheable = result.cacheable; | 
					
						
							|  |  |  | 					this.buildInfo.fileDependencies = new Set(result.fileDependencies); | 
					
						
							|  |  |  | 					this.buildInfo.contextDependencies = new Set( | 
					
						
							|  |  |  | 						result.contextDependencies | 
					
						
							|  |  |  | 					); | 
					
						
							|  |  |  | 				} | 
					
						
							| 
									
										
										
										
											2017-02-11 13:10:07 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 				if (err) { | 
					
						
							| 
									
										
										
										
											2018-06-05 19:41:00 +08:00
										 |  |  | 					if (!(err instanceof Error)) { | 
					
						
							|  |  |  | 						err = new NonErrorEmittedError(err); | 
					
						
							|  |  |  | 					} | 
					
						
							| 
									
										
										
										
											2018-03-02 17:57:46 +08:00
										 |  |  | 					const currentLoader = this.getCurrentLoader(loaderContext); | 
					
						
							| 
									
										
										
										
											2018-10-30 05:18:08 +08:00
										 |  |  | 					const error = new ModuleBuildError(err, { | 
					
						
							| 
									
										
										
										
											2018-06-05 17:58:10 +08:00
										 |  |  | 						from: | 
					
						
							|  |  |  | 							currentLoader && | 
					
						
							|  |  |  | 							compilation.runtimeTemplate.requestShortener.shorten( | 
					
						
							|  |  |  | 								currentLoader.loader | 
					
						
							|  |  |  | 							) | 
					
						
							| 
									
										
										
										
											2018-03-02 17:57:46 +08:00
										 |  |  | 					}); | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 					return callback(error); | 
					
						
							|  |  |  | 				} | 
					
						
							| 
									
										
										
										
											2016-07-03 19:13:01 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 				const resourceBuffer = result.resourceBuffer; | 
					
						
							|  |  |  | 				const source = result.result[0]; | 
					
						
							|  |  |  | 				const sourceMap = result.result.length >= 1 ? result.result[1] : null; | 
					
						
							|  |  |  | 				const extraInfo = result.result.length >= 2 ? result.result[2] : null; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				if (!Buffer.isBuffer(source) && typeof source !== "string") { | 
					
						
							| 
									
										
										
										
											2018-06-05 17:58:10 +08:00
										 |  |  | 					const currentLoader = this.getCurrentLoader(loaderContext, 0); | 
					
						
							|  |  |  | 					const err = new Error( | 
					
						
							|  |  |  | 						`Final loader (${ | 
					
						
							|  |  |  | 							currentLoader | 
					
						
							|  |  |  | 								? compilation.runtimeTemplate.requestShortener.shorten( | 
					
						
							|  |  |  | 										currentLoader.loader | 
					
						
							|  |  |  | 								  ) | 
					
						
							|  |  |  | 								: "unknown" | 
					
						
							|  |  |  | 						}) didn't return a Buffer or String`
 | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 					); | 
					
						
							| 
									
										
										
										
											2018-10-30 05:18:08 +08:00
										 |  |  | 					const error = new ModuleBuildError(err); | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 					return callback(error); | 
					
						
							|  |  |  | 				} | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 				this._source = this.createSource( | 
					
						
							|  |  |  | 					this.binary ? asBuffer(source) : asString(source), | 
					
						
							|  |  |  | 					resourceBuffer, | 
					
						
							|  |  |  | 					sourceMap | 
					
						
							|  |  |  | 				); | 
					
						
							|  |  |  | 				this._ast = | 
					
						
							|  |  |  | 					typeof extraInfo === "object" && | 
					
						
							|  |  |  | 					extraInfo !== null && | 
					
						
							|  |  |  | 					extraInfo.webpackAST !== undefined | 
					
						
							|  |  |  | 						? extraInfo.webpackAST | 
					
						
							|  |  |  | 						: null; | 
					
						
							|  |  |  | 				return callback(); | 
					
						
							| 
									
										
										
										
											2017-02-11 11:16:18 +08:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		); | 
					
						
							| 
									
										
										
										
											2014-05-17 06:31:52 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2015-07-13 06:20:09 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-13 18:38:55 +08:00
										 |  |  | 	markModuleAsErrored(error) { | 
					
						
							| 
									
										
										
										
											2018-02-26 10:48:51 +08:00
										 |  |  | 		// Restore build meta from successful build to keep importing state
 | 
					
						
							| 
									
										
										
										
											2017-12-07 00:26:02 +08:00
										 |  |  | 		this.buildMeta = Object.assign({}, this._lastSuccessfulBuildMeta); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-13 18:38:55 +08:00
										 |  |  | 		this.error = error; | 
					
						
							|  |  |  | 		this.errors.push(this.error); | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		this._source = new RawSource( | 
					
						
							|  |  |  | 			"throw new Error(" + JSON.stringify(this.error.message) + ");" | 
					
						
							|  |  |  | 		); | 
					
						
							| 
									
										
										
										
											2017-11-03 18:12:45 +08:00
										 |  |  | 		this._ast = null; | 
					
						
							| 
									
										
										
										
											2017-02-11 11:41:26 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-14 18:14:57 +08:00
										 |  |  | 	applyNoParseRule(rule, content) { | 
					
						
							| 
									
										
										
										
											2017-02-11 13:59:58 +08:00
										 |  |  | 		// must start with "rule" if rule is a string
 | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		if (typeof rule === "string") { | 
					
						
							| 
									
										
										
										
											2017-02-14 18:14:57 +08:00
										 |  |  | 			return content.indexOf(rule) === 0; | 
					
						
							| 
									
										
										
										
											2017-02-11 13:59:58 +08:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2017-06-03 08:28:54 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		if (typeof rule === "function") { | 
					
						
							| 
									
										
										
										
											2017-06-03 08:28:54 +08:00
										 |  |  | 			return rule(content); | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2017-02-11 13:59:58 +08:00
										 |  |  | 		// we assume rule is a regexp
 | 
					
						
							| 
									
										
										
										
											2017-02-14 18:14:57 +08:00
										 |  |  | 		return rule.test(content); | 
					
						
							| 
									
										
										
										
											2017-02-11 13:59:58 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// check if module should not be parsed
 | 
					
						
							|  |  |  | 	// returns "true" if the module should !not! be parsed
 | 
					
						
							|  |  |  | 	// returns "false" if the module !must! be parsed
 | 
					
						
							| 
									
										
										
										
											2017-02-16 05:01:09 +08:00
										 |  |  | 	shouldPreventParsing(noParseRule, request) { | 
					
						
							| 
									
										
										
										
											2017-02-11 13:59:58 +08:00
										 |  |  | 		// if no noParseRule exists, return false
 | 
					
						
							|  |  |  | 		// the module !must! be parsed.
 | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		if (!noParseRule) { | 
					
						
							| 
									
										
										
										
											2017-02-11 13:59:58 +08:00
										 |  |  | 			return false; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		// we only have one rule to check
 | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		if (!Array.isArray(noParseRule)) { | 
					
						
							| 
									
										
										
										
											2017-02-11 13:59:58 +08:00
										 |  |  | 			// returns "true" if the module is !not! to be parsed
 | 
					
						
							|  |  |  | 			return this.applyNoParseRule(noParseRule, request); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		for (let i = 0; i < noParseRule.length; i++) { | 
					
						
							| 
									
										
										
										
											2017-02-11 13:59:58 +08:00
										 |  |  | 			const rule = noParseRule[i]; | 
					
						
							|  |  |  | 			// early exit on first truthy match
 | 
					
						
							|  |  |  | 			// this module is !not! to be parsed
 | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 			if (this.applyNoParseRule(rule, request)) { | 
					
						
							| 
									
										
										
										
											2017-02-11 13:59:58 +08:00
										 |  |  | 				return true; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		// no match found, so this module !should! be parsed
 | 
					
						
							|  |  |  | 		return false; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-27 20:24:43 +08:00
										 |  |  | 	_initBuildHash(compilation) { | 
					
						
							|  |  |  | 		const hash = createHash(compilation.outputOptions.hashFunction); | 
					
						
							|  |  |  | 		if (this._source) { | 
					
						
							|  |  |  | 			hash.update("source"); | 
					
						
							|  |  |  | 			this._source.updateHash(hash); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		hash.update("meta"); | 
					
						
							|  |  |  | 		hash.update(JSON.stringify(this.buildMeta)); | 
					
						
							| 
									
										
										
										
											2018-05-03 00:08:36 +08:00
										 |  |  | 		this._buildHash = hash.digest("hex"); | 
					
						
							| 
									
										
										
										
											2018-04-27 20:24:43 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-25 18:12:17 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {TODO} options TODO | 
					
						
							|  |  |  | 	 * @param {Compilation} compilation the compilation | 
					
						
							|  |  |  | 	 * @param {TODO} resolver TODO | 
					
						
							|  |  |  | 	 * @param {TODO} fs the file system | 
					
						
							| 
									
										
										
										
											2018-09-12 00:47:55 +08:00
										 |  |  | 	 * @param {function(WebpackError=): void} callback callback function | 
					
						
							| 
									
										
										
										
											2018-07-25 18:12:17 +08:00
										 |  |  | 	 * @returns {void} | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2017-02-11 11:16:18 +08:00
										 |  |  | 	build(options, compilation, resolver, fs, callback) { | 
					
						
							| 
									
										
										
										
											2017-05-04 10:19:54 +08:00
										 |  |  | 		this.buildTimestamp = Date.now(); | 
					
						
							| 
									
										
										
										
											2018-09-12 00:47:55 +08:00
										 |  |  | 		this._forceBuild = false; | 
					
						
							| 
									
										
										
										
											2017-02-11 11:16:18 +08:00
										 |  |  | 		this._source = null; | 
					
						
							| 
									
										
										
										
											2017-11-03 18:12:45 +08:00
										 |  |  | 		this._ast = null; | 
					
						
							| 
									
										
										
										
											2018-04-27 20:24:43 +08:00
										 |  |  | 		this._buildHash = ""; | 
					
						
							| 
									
										
										
										
											2017-02-11 11:16:18 +08:00
										 |  |  | 		this.error = null; | 
					
						
							|  |  |  | 		this.errors.length = 0; | 
					
						
							|  |  |  | 		this.warnings.length = 0; | 
					
						
							| 
									
										
										
										
											2018-09-12 00:47:55 +08:00
										 |  |  | 		this.dependencies.length = 0; | 
					
						
							|  |  |  | 		this.blocks.length = 0; | 
					
						
							| 
									
										
										
										
											2017-12-06 19:09:17 +08:00
										 |  |  | 		this.buildMeta = {}; | 
					
						
							|  |  |  | 		this.buildInfo = { | 
					
						
							|  |  |  | 			cacheable: false, | 
					
						
							|  |  |  | 			fileDependencies: new Set(), | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 			contextDependencies: new Set() | 
					
						
							| 
									
										
										
										
											2017-12-06 19:09:17 +08:00
										 |  |  | 		}; | 
					
						
							| 
									
										
										
										
											2016-06-21 03:46:27 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		return this.doBuild(options, compilation, resolver, fs, err => { | 
					
						
							| 
									
										
										
										
											2018-04-28 00:53:07 +08:00
										 |  |  | 			this._cachedSources.clear(); | 
					
						
							| 
									
										
										
										
											2017-02-11 13:59:58 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 			// if we have an error mark module as failed and exit
 | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 			if (err) { | 
					
						
							| 
									
										
										
										
											2017-02-13 18:38:55 +08:00
										 |  |  | 				this.markModuleAsErrored(err); | 
					
						
							| 
									
										
										
										
											2018-04-27 20:24:43 +08:00
										 |  |  | 				this._initBuildHash(compilation); | 
					
						
							| 
									
										
										
										
											2017-02-11 11:41:26 +08:00
										 |  |  | 				return callback(); | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2017-02-11 13:59:58 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 			// check if this module should !not! be parsed.
 | 
					
						
							|  |  |  | 			// if so, exit here;
 | 
					
						
							|  |  |  | 			const noParseRule = options.module && options.module.noParse; | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 			if (this.shouldPreventParsing(noParseRule, this.request)) { | 
					
						
							| 
									
										
										
										
											2018-04-27 20:24:43 +08:00
										 |  |  | 				this._initBuildHash(compilation); | 
					
						
							| 
									
										
										
										
											2017-02-11 13:59:58 +08:00
										 |  |  | 				return callback(); | 
					
						
							| 
									
										
										
										
											2017-02-11 11:16:18 +08:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2017-02-11 13:59:58 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-14 08:21:44 +08:00
										 |  |  | 			const handleParseError = e => { | 
					
						
							|  |  |  | 				const source = this._source.source(); | 
					
						
							| 
									
										
										
										
											2018-10-30 05:18:08 +08:00
										 |  |  | 				const error = new ModuleParseError(source, e); | 
					
						
							| 
									
										
										
										
											2017-12-14 08:21:44 +08:00
										 |  |  | 				this.markModuleAsErrored(error); | 
					
						
							| 
									
										
										
										
											2018-04-27 20:24:43 +08:00
										 |  |  | 				this._initBuildHash(compilation); | 
					
						
							| 
									
										
										
										
											2017-12-14 08:21:44 +08:00
										 |  |  | 				return callback(); | 
					
						
							|  |  |  | 			}; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			const handleParseResult = result => { | 
					
						
							| 
									
										
										
										
											2018-10-18 15:20:59 +08:00
										 |  |  | 				this.dependencies.sort( | 
					
						
							|  |  |  | 					concatComparators( | 
					
						
							|  |  |  | 						compareSelect(a => a.loc, compareLocations), | 
					
						
							|  |  |  | 						keepOriginalOrder(this.dependencies) | 
					
						
							|  |  |  | 					) | 
					
						
							|  |  |  | 				); | 
					
						
							| 
									
										
										
										
											2017-12-14 08:21:44 +08:00
										 |  |  | 				this._lastSuccessfulBuildMeta = this.buildMeta; | 
					
						
							| 
									
										
										
										
											2018-04-27 20:24:43 +08:00
										 |  |  | 				this._initBuildHash(compilation); | 
					
						
							| 
									
										
										
										
											2017-12-14 08:21:44 +08:00
										 |  |  | 				return callback(); | 
					
						
							|  |  |  | 			}; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-11 11:16:18 +08:00
										 |  |  | 			try { | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 				const result = this.parser.parse( | 
					
						
							|  |  |  | 					this._ast || this._source.source(), | 
					
						
							|  |  |  | 					{ | 
					
						
							|  |  |  | 						current: this, | 
					
						
							|  |  |  | 						module: this, | 
					
						
							|  |  |  | 						compilation: compilation, | 
					
						
							|  |  |  | 						options: options | 
					
						
							|  |  |  | 					}, | 
					
						
							|  |  |  | 					(err, result) => { | 
					
						
							|  |  |  | 						if (err) { | 
					
						
							|  |  |  | 							handleParseError(err); | 
					
						
							|  |  |  | 						} else { | 
					
						
							|  |  |  | 							handleParseResult(result); | 
					
						
							|  |  |  | 						} | 
					
						
							| 
									
										
										
										
											2017-12-14 08:21:44 +08:00
										 |  |  | 					} | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 				); | 
					
						
							|  |  |  | 				if (result !== undefined) { | 
					
						
							| 
									
										
										
										
											2017-12-14 08:21:44 +08:00
										 |  |  | 					// parse is sync
 | 
					
						
							|  |  |  | 					handleParseResult(result); | 
					
						
							|  |  |  | 				} | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 			} catch (e) { | 
					
						
							| 
									
										
										
										
											2017-12-14 08:21:44 +08:00
										 |  |  | 				handleParseError(e); | 
					
						
							| 
									
										
										
										
											2017-02-11 11:16:18 +08:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2015-07-13 06:20:09 +08:00
										 |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2015-07-13 06:20:09 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-11 19:05:13 +08:00
										 |  |  | 	/** | 
					
						
							| 
									
										
										
										
											2018-08-23 01:23:48 +08:00
										 |  |  | 	 * @param {ChunkGraph} chunkGraph the chunk graph | 
					
						
							| 
									
										
										
										
											2018-07-11 19:05:13 +08:00
										 |  |  | 	 * @param {DependencyTemplates} dependencyTemplates dependency templates | 
					
						
							|  |  |  | 	 * @returns {string} hash | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2018-08-23 01:23:48 +08:00
										 |  |  | 	getHashDigest(chunkGraph, dependencyTemplates) { | 
					
						
							|  |  |  | 		const hash = chunkGraph.getModuleHash(this); | 
					
						
							|  |  |  | 		const dtHash = dependencyTemplates.getHash(); | 
					
						
							|  |  |  | 		return `${hash}-${dtHash}`; | 
					
						
							| 
									
										
										
										
											2017-02-13 19:09:16 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-02-11 11:16:18 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-25 18:12:17 +08:00
										 |  |  | 	/** | 
					
						
							| 
									
										
										
										
											2018-07-18 00:57:03 +08:00
										 |  |  | 	 * @param {SourceContext} sourceContext source context | 
					
						
							| 
									
										
										
										
											2018-07-25 18:12:17 +08:00
										 |  |  | 	 * @returns {Source} generated source | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2018-07-24 23:35:36 +08:00
										 |  |  | 	source({ | 
					
						
							|  |  |  | 		dependencyTemplates, | 
					
						
							|  |  |  | 		runtimeTemplate, | 
					
						
							|  |  |  | 		moduleGraph, | 
					
						
							| 
									
										
										
										
											2018-08-23 01:23:48 +08:00
										 |  |  | 		chunkGraph, | 
					
						
							| 
									
										
										
										
											2018-07-24 23:35:36 +08:00
										 |  |  | 		type = "javascript" | 
					
						
							|  |  |  | 	}) { | 
					
						
							| 
									
										
										
										
											2018-08-23 01:23:48 +08:00
										 |  |  | 		const hashDigest = this.getHashDigest(chunkGraph, dependencyTemplates); | 
					
						
							| 
									
										
										
										
											2018-04-28 00:53:07 +08:00
										 |  |  | 		const cacheEntry = this._cachedSources.get(type); | 
					
						
							|  |  |  | 		if (cacheEntry !== undefined && cacheEntry.hash === hashDigest) { | 
					
						
							| 
									
										
										
										
											2018-01-24 06:09:26 +08:00
										 |  |  | 			// We can reuse the cached source
 | 
					
						
							| 
									
										
										
										
											2018-04-28 00:53:07 +08:00
										 |  |  | 			return cacheEntry.source; | 
					
						
							| 
									
										
										
										
											2018-01-24 06:09:26 +08:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2017-02-16 05:01:09 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-18 00:57:03 +08:00
										 |  |  | 		const source = this.generator.generate(this, { | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 			dependencyTemplates, | 
					
						
							| 
									
										
										
										
											2018-04-28 00:53:07 +08:00
										 |  |  | 			runtimeTemplate, | 
					
						
							| 
									
										
										
										
											2018-07-24 23:35:36 +08:00
										 |  |  | 			moduleGraph, | 
					
						
							| 
									
										
										
										
											2018-08-23 02:17:49 +08:00
										 |  |  | 			chunkGraph, | 
					
						
							| 
									
										
										
										
											2018-04-28 00:53:07 +08:00
										 |  |  | 			type | 
					
						
							| 
									
										
										
										
											2018-07-18 00:57:03 +08:00
										 |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2017-12-01 18:07:23 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-01-24 06:09:26 +08:00
										 |  |  | 		const cachedSource = new CachedSource(source); | 
					
						
							| 
									
										
										
										
											2018-04-28 00:53:07 +08:00
										 |  |  | 		this._cachedSources.set(type, { | 
					
						
							|  |  |  | 			source: cachedSource, | 
					
						
							|  |  |  | 			hash: hashDigest | 
					
						
							|  |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2018-07-25 18:12:17 +08:00
										 |  |  | 		// TODO remove cast when webpack-sources types are fixed
 | 
					
						
							|  |  |  | 		// CachedSource is not a Source?
 | 
					
						
							| 
									
										
										
										
											2018-08-16 19:12:41 +08:00
										 |  |  | 		const fixedSource = /** @type {TODO} */ (cachedSource); | 
					
						
							| 
									
										
										
										
											2018-07-25 18:12:17 +08:00
										 |  |  | 		return fixedSource; | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-25 18:20:35 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @returns {Source | null} the original source for the module before webpack transformation | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2017-04-03 15:48:55 +08:00
										 |  |  | 	originalSource() { | 
					
						
							|  |  |  | 		return this._source; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-04-03 15:33:11 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-12 00:47:55 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @returns {void} | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	invalidateBuild() { | 
					
						
							|  |  |  | 		this._forceBuild = true; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-25 18:38:34 +08:00
										 |  |  | 	/** | 
					
						
							| 
									
										
										
										
											2018-09-26 15:14:44 +08:00
										 |  |  | 	 * @param {NeedBuildContext} context context info | 
					
						
							|  |  |  | 	 * @param {function(WebpackError=, boolean=): void} callback callback function, returns true, if the module needs a rebuild | 
					
						
							|  |  |  | 	 * @returns {void} | 
					
						
							| 
									
										
										
										
											2018-07-25 18:38:34 +08:00
										 |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2018-09-27 13:22:19 +08:00
										 |  |  | 	needBuild({ fileSystemInfo }, callback) { | 
					
						
							| 
									
										
										
										
											2018-09-12 00:47:55 +08:00
										 |  |  | 		// build if enforced
 | 
					
						
							| 
									
										
										
										
											2018-09-26 15:14:44 +08:00
										 |  |  | 		if (this._forceBuild) return callback(null, true); | 
					
						
							| 
									
										
										
										
											2018-09-12 00:47:55 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-26 15:14:44 +08:00
										 |  |  | 		// always try to build in case of an error
 | 
					
						
							|  |  |  | 		if (this.error) return callback(null, true); | 
					
						
							| 
									
										
										
										
											2017-11-06 20:02:35 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-26 15:14:44 +08:00
										 |  |  | 		// always build when module is not cacheable
 | 
					
						
							|  |  |  | 		if (!this.buildInfo.cacheable) return callback(null, true); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-06 23:41:26 +08:00
										 |  |  | 		// Check timestamps of all dependencies
 | 
					
						
							| 
									
										
										
										
											2018-09-26 15:14:44 +08:00
										 |  |  | 		// Missing timestamp -> need build
 | 
					
						
							|  |  |  | 		// Timestamp bigger than buildTimestamp -> need build
 | 
					
						
							| 
									
										
										
										
											2018-09-27 13:22:19 +08:00
										 |  |  | 		asyncLib.parallel( | 
					
						
							|  |  |  | 			[ | 
					
						
							|  |  |  | 				callback => | 
					
						
							|  |  |  | 					asyncLib.each( | 
					
						
							|  |  |  | 						this.buildInfo.fileDependencies, | 
					
						
							|  |  |  | 						(file, callback) => { | 
					
						
							|  |  |  | 							fileSystemInfo.getFileTimestamp(file, (err, info) => { | 
					
						
							|  |  |  | 								if (err) return callback(err); | 
					
						
							|  |  |  | 								if (!info || info.safeTime >= this.buildTimestamp) | 
					
						
							|  |  |  | 									return callback(EARLY_RETURN_ERROR); | 
					
						
							|  |  |  | 								callback(); | 
					
						
							|  |  |  | 							}); | 
					
						
							|  |  |  | 						}, | 
					
						
							|  |  |  | 						callback | 
					
						
							|  |  |  | 					), | 
					
						
							|  |  |  | 				callback => | 
					
						
							|  |  |  | 					asyncLib.each( | 
					
						
							|  |  |  | 						this.buildInfo.contextDependencies, | 
					
						
							|  |  |  | 						(context, callback) => { | 
					
						
							|  |  |  | 							fileSystemInfo.getContextTimestamp(context, (err, info) => { | 
					
						
							|  |  |  | 								if (err) return callback(err); | 
					
						
							|  |  |  | 								if (!info || info.safeTime >= this.buildTimestamp) | 
					
						
							|  |  |  | 									return callback(EARLY_RETURN_ERROR); | 
					
						
							|  |  |  | 								callback(); | 
					
						
							|  |  |  | 							}); | 
					
						
							|  |  |  | 						}, | 
					
						
							|  |  |  | 						callback | 
					
						
							|  |  |  | 					) | 
					
						
							|  |  |  | 			], | 
					
						
							|  |  |  | 			err => | 
					
						
							|  |  |  | 				err === EARLY_RETURN_ERROR ? callback(null, true) : callback(err, false) | 
					
						
							|  |  |  | 		); | 
					
						
							| 
									
										
										
										
											2017-02-11 11:16:18 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-25 18:12:17 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @returns {number} the estimated size of the module | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2017-02-11 11:16:18 +08:00
										 |  |  | 	size() { | 
					
						
							|  |  |  | 		return this._source ? this._source.size() : -1; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-21 00:17:51 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {Hash} hash the hash used to track dependencies | 
					
						
							| 
									
										
										
										
											2018-08-23 23:07:23 +08:00
										 |  |  | 	 * @param {ChunkGraph} chunkGraph the chunk graph | 
					
						
							| 
									
										
										
										
											2018-07-21 00:17:51 +08:00
										 |  |  | 	 * @returns {void} | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2018-08-23 23:07:23 +08:00
										 |  |  | 	updateHash(hash, chunkGraph) { | 
					
						
							| 
									
										
										
										
											2018-04-27 20:24:43 +08:00
										 |  |  | 		hash.update(this._buildHash); | 
					
						
							| 
									
										
										
										
											2018-08-23 23:07:23 +08:00
										 |  |  | 		super.updateHash(hash, chunkGraph); | 
					
						
							| 
									
										
										
										
											2017-02-11 11:16:18 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-10-09 20:30:59 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	serialize(context) { | 
					
						
							|  |  |  | 		const { write } = context; | 
					
						
							|  |  |  | 		// constructor
 | 
					
						
							|  |  |  | 		write(this.type); | 
					
						
							|  |  |  | 		write(this.resource); | 
					
						
							|  |  |  | 		// deserialize
 | 
					
						
							|  |  |  | 		write(this._source); | 
					
						
							|  |  |  | 		write(this._buildHash); | 
					
						
							|  |  |  | 		write(this.buildTimestamp); | 
					
						
							|  |  |  | 		write(this.lineToLine); | 
					
						
							|  |  |  | 		write(this.error); | 
					
						
							|  |  |  | 		write(this._cachedSources); | 
					
						
							|  |  |  | 		write(this._lastSuccessfulBuildMeta); | 
					
						
							|  |  |  | 		write(this._forceBuild); | 
					
						
							|  |  |  | 		super.serialize(context); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	static deserialize(context) { | 
					
						
							|  |  |  | 		const { read } = context; | 
					
						
							|  |  |  | 		const obj = new NormalModule({ | 
					
						
							|  |  |  | 			type: read(), | 
					
						
							|  |  |  | 			resource: read(), | 
					
						
							|  |  |  | 			// will be filled by updateCacheModule
 | 
					
						
							|  |  |  | 			request: null, | 
					
						
							|  |  |  | 			userRequest: null, | 
					
						
							|  |  |  | 			rawRequest: null, | 
					
						
							|  |  |  | 			loaders: null, | 
					
						
							|  |  |  | 			matchResource: null, | 
					
						
							|  |  |  | 			parser: null, | 
					
						
							|  |  |  | 			generator: null, | 
					
						
							|  |  |  | 			resolveOptions: null | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 		obj.deserialize(context); | 
					
						
							|  |  |  | 		return obj; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	deserialize(context) { | 
					
						
							|  |  |  | 		const { read } = context; | 
					
						
							|  |  |  | 		this._source = read(); | 
					
						
							|  |  |  | 		this._buildHash = read(); | 
					
						
							|  |  |  | 		this.buildTimestamp = read(); | 
					
						
							|  |  |  | 		this.lineToLine = read(); | 
					
						
							|  |  |  | 		this.error = read(); | 
					
						
							|  |  |  | 		this._cachedSources = read(); | 
					
						
							|  |  |  | 		this._lastSuccessfulBuildMeta = read(); | 
					
						
							|  |  |  | 		this._forceBuild = read(); | 
					
						
							|  |  |  | 		super.deserialize(context); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-02-11 11:16:18 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-09 20:30:59 +08:00
										 |  |  | makeSerializable(NormalModule, "webpack/lib/NormalModule"); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-11 11:16:18 +08:00
										 |  |  | module.exports = NormalModule; |