| 
									
										
										
										
											2013-03-26 23:54:41 +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-04-06 20:46:40 +08:00
										 |  |  | "use strict"; | 
					
						
							| 
									
										
										
										
											2013-03-26 23:54:41 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-16 03:30:21 +08:00
										 |  |  | const asyncLib = require("neo-async"); | 
					
						
							| 
									
										
										
										
											2018-03-22 19:05:58 +08:00
										 |  |  | const { ConcatSource, RawSource } = require("webpack-sources"); | 
					
						
							| 
									
										
										
										
											2020-05-12 18:16:51 +08:00
										 |  |  | const Compilation = require("./Compilation"); | 
					
						
							| 
									
										
										
										
											2017-04-06 20:46:40 +08:00
										 |  |  | const ModuleFilenameHelpers = require("./ModuleFilenameHelpers"); | 
					
						
							| 
									
										
										
										
											2018-11-27 07:06:02 +08:00
										 |  |  | const ProgressPlugin = require("./ProgressPlugin"); | 
					
						
							| 
									
										
										
										
											2017-04-06 20:46:40 +08:00
										 |  |  | const SourceMapDevToolModuleOptionsPlugin = require("./SourceMapDevToolModuleOptionsPlugin"); | 
					
						
							| 
									
										
										
										
											2021-04-16 21:35:18 +08:00
										 |  |  | const createSchemaValidation = require("./util/create-schema-validation"); | 
					
						
							| 
									
										
										
										
											2017-11-23 17:59:29 +08:00
										 |  |  | const createHash = require("./util/createHash"); | 
					
						
							| 
									
										
										
										
											2019-06-11 19:09:42 +08:00
										 |  |  | const { relative, dirname } = require("./util/fs"); | 
					
						
							| 
									
										
										
										
											2021-08-19 20:01:44 +08:00
										 |  |  | const { makePathsAbsolute } = require("./util/identifier"); | 
					
						
							| 
									
										
										
										
											2017-04-06 20:46:40 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-26 21:41:46 +08:00
										 |  |  | /** @typedef {import("webpack-sources").MapOptions} MapOptions */ | 
					
						
							| 
									
										
										
										
											2019-06-14 16:45:56 +08:00
										 |  |  | /** @typedef {import("webpack-sources").Source} Source */ | 
					
						
							| 
									
										
										
										
											2018-09-20 16:13:55 +08:00
										 |  |  | /** @typedef {import("../declarations/plugins/SourceMapDevToolPlugin").SourceMapDevToolPluginOptions} SourceMapDevToolPluginOptions */ | 
					
						
							| 
									
										
										
										
											2019-11-12 20:55:13 +08:00
										 |  |  | /** @typedef {import("./Cache").Etag} Etag */ | 
					
						
							| 
									
										
										
										
											2020-07-15 17:14:28 +08:00
										 |  |  | /** @typedef {import("./CacheFacade").ItemCacheFacade} ItemCacheFacade */ | 
					
						
							| 
									
										
										
										
											2018-08-23 01:23:48 +08:00
										 |  |  | /** @typedef {import("./Chunk")} Chunk */ | 
					
						
							| 
									
										
										
										
											2020-08-19 03:14:43 +08:00
										 |  |  | /** @typedef {import("./Compilation").AssetInfo} AssetInfo */ | 
					
						
							| 
									
										
										
										
											2018-08-23 01:23:48 +08:00
										 |  |  | /** @typedef {import("./Compiler")} Compiler */ | 
					
						
							| 
									
										
										
										
											2019-06-14 16:45:56 +08:00
										 |  |  | /** @typedef {import("./Module")} Module */ | 
					
						
							| 
									
										
										
										
											2021-04-23 03:43:43 +08:00
										 |  |  | /** @typedef {import("./NormalModule").SourceMap} SourceMap */ | 
					
						
							| 
									
										
										
										
											2019-10-31 03:47:17 +08:00
										 |  |  | /** @typedef {import("./util/Hash")} Hash */ | 
					
						
							| 
									
										
										
										
											2018-08-23 01:23:48 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-04-16 21:35:18 +08:00
										 |  |  | const validate = createSchemaValidation( | 
					
						
							|  |  |  | 	require("../schemas/plugins/SourceMapDevToolPlugin.check.js"), | 
					
						
							|  |  |  | 	() => require("../schemas/plugins/SourceMapDevToolPlugin.json"), | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		name: "SourceMap DevTool Plugin", | 
					
						
							|  |  |  | 		baseDataPath: "options" | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | ); | 
					
						
							| 
									
										
										
										
											2019-06-14 16:45:56 +08:00
										 |  |  | /** | 
					
						
							| 
									
										
										
										
											2019-06-27 00:40:56 +08:00
										 |  |  |  * @typedef {object} SourceMapTask | 
					
						
							| 
									
										
										
										
											2019-06-14 16:45:56 +08:00
										 |  |  |  * @property {Source} asset | 
					
						
							| 
									
										
										
										
											2020-08-19 03:14:43 +08:00
										 |  |  |  * @property {AssetInfo} assetInfo | 
					
						
							| 
									
										
										
										
											2019-07-17 22:02:33 +08:00
										 |  |  |  * @property {(string | Module)[]} modules | 
					
						
							| 
									
										
										
										
											2019-06-14 16:45:56 +08:00
										 |  |  |  * @property {string} source | 
					
						
							| 
									
										
										
										
											2019-06-27 00:40:56 +08:00
										 |  |  |  * @property {string} file | 
					
						
							|  |  |  |  * @property {SourceMap} sourceMap | 
					
						
							| 
									
										
										
										
											2020-07-15 17:14:28 +08:00
										 |  |  |  * @property {ItemCacheFacade} cacheItem cache item | 
					
						
							| 
									
										
										
										
											2019-06-14 16:45:56 +08:00
										 |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-19 03:14:43 +08:00
										 |  |  | /** | 
					
						
							|  |  |  |  * Escapes regular expression metacharacters | 
					
						
							|  |  |  |  * @param {string} str String to quote | 
					
						
							|  |  |  |  * @returns {string} Escaped string | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | const quoteMeta = str => { | 
					
						
							|  |  |  | 	return str.replace(/[-[\]\\/{}()*+?.^$|]/g, "\\$&"); | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-14 16:45:56 +08:00
										 |  |  | /** | 
					
						
							| 
									
										
										
										
											2019-06-27 00:40:56 +08:00
										 |  |  |  * Creating {@link SourceMapTask} for given file | 
					
						
							| 
									
										
										
										
											2019-07-09 04:31:11 +08:00
										 |  |  |  * @param {string} file current compiled file | 
					
						
							| 
									
										
										
										
											2019-07-25 04:41:14 +08:00
										 |  |  |  * @param {Source} asset the asset | 
					
						
							| 
									
										
										
										
											2020-08-19 03:14:43 +08:00
										 |  |  |  * @param {AssetInfo} assetInfo the asset info | 
					
						
							| 
									
										
										
										
											2020-10-26 21:41:46 +08:00
										 |  |  |  * @param {MapOptions} options source map options | 
					
						
							| 
									
										
										
										
											2019-07-09 04:31:11 +08:00
										 |  |  |  * @param {Compilation} compilation compilation instance | 
					
						
							| 
									
										
										
										
											2020-07-15 17:14:28 +08:00
										 |  |  |  * @param {ItemCacheFacade} cacheItem cache item | 
					
						
							| 
									
										
										
										
											2019-07-09 04:31:11 +08:00
										 |  |  |  * @returns {SourceMapTask | undefined} created task instance or `undefined` | 
					
						
							| 
									
										
										
										
											2019-06-14 16:45:56 +08:00
										 |  |  |  */ | 
					
						
							| 
									
										
										
										
											2020-08-19 03:14:43 +08:00
										 |  |  | const getTaskForFile = ( | 
					
						
							|  |  |  | 	file, | 
					
						
							|  |  |  | 	asset, | 
					
						
							|  |  |  | 	assetInfo, | 
					
						
							|  |  |  | 	options, | 
					
						
							|  |  |  | 	compilation, | 
					
						
							|  |  |  | 	cacheItem | 
					
						
							|  |  |  | ) => { | 
					
						
							| 
									
										
										
										
											2019-06-14 16:45:56 +08:00
										 |  |  | 	let source; | 
					
						
							| 
									
										
										
										
											2019-07-17 22:02:33 +08:00
										 |  |  | 	/** @type {SourceMap} */ | 
					
						
							| 
									
										
										
										
											2019-06-14 16:45:56 +08:00
										 |  |  | 	let sourceMap; | 
					
						
							| 
									
										
										
										
											2019-06-27 00:40:56 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * Check if asset can build source map | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 	if (asset.sourceAndMap) { | 
					
						
							| 
									
										
										
										
											2017-07-17 13:15:42 +08:00
										 |  |  | 		const sourceAndMap = asset.sourceAndMap(options); | 
					
						
							| 
									
										
										
										
											2019-07-17 22:02:33 +08:00
										 |  |  | 		sourceMap = /** @type {SourceMap} */ (sourceAndMap.map); | 
					
						
							| 
									
										
										
										
											2017-07-17 13:15:42 +08:00
										 |  |  | 		source = sourceAndMap.source; | 
					
						
							|  |  |  | 	} else { | 
					
						
							| 
									
										
										
										
											2019-07-17 22:02:33 +08:00
										 |  |  | 		sourceMap = /** @type {SourceMap} */ (asset.map(options)); | 
					
						
							| 
									
										
										
										
											2017-07-17 13:15:42 +08:00
										 |  |  | 		source = asset.source(); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2019-06-14 16:45:56 +08:00
										 |  |  | 	if (!sourceMap || typeof source !== "string") return; | 
					
						
							| 
									
										
										
										
											2019-11-11 22:25:03 +08:00
										 |  |  | 	const context = compilation.options.context; | 
					
						
							|  |  |  | 	const root = compilation.compiler.root; | 
					
						
							| 
									
										
										
										
											2021-08-19 20:01:44 +08:00
										 |  |  | 	const cachedAbsolutify = makePathsAbsolute.bindContextCache(context, root); | 
					
						
							| 
									
										
										
										
											2019-06-14 16:45:56 +08:00
										 |  |  | 	const modules = sourceMap.sources.map(source => { | 
					
						
							| 
									
										
										
										
											2019-11-11 22:25:03 +08:00
										 |  |  | 		if (!source.startsWith("webpack://")) return source; | 
					
						
							| 
									
										
										
										
											2020-04-17 16:54:27 +08:00
										 |  |  | 		source = cachedAbsolutify(source.slice(10)); | 
					
						
							| 
									
										
										
										
											2019-06-14 16:45:56 +08:00
										 |  |  | 		const module = compilation.findModule(source); | 
					
						
							|  |  |  | 		return module || source; | 
					
						
							|  |  |  | 	}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return { | 
					
						
							|  |  |  | 		file, | 
					
						
							|  |  |  | 		asset, | 
					
						
							|  |  |  | 		source, | 
					
						
							| 
									
										
										
										
											2020-08-19 03:14:43 +08:00
										 |  |  | 		assetInfo, | 
					
						
							| 
									
										
										
										
											2019-06-14 16:45:56 +08:00
										 |  |  | 		sourceMap, | 
					
						
							| 
									
										
										
										
											2019-10-31 03:47:17 +08:00
										 |  |  | 		modules, | 
					
						
							| 
									
										
										
										
											2020-07-15 17:14:28 +08:00
										 |  |  | 		cacheItem | 
					
						
							| 
									
										
										
										
											2019-06-14 16:45:56 +08:00
										 |  |  | 	}; | 
					
						
							| 
									
										
										
										
											2017-11-08 18:32:05 +08:00
										 |  |  | }; | 
					
						
							| 
									
										
										
										
											2017-07-17 13:15:42 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-04-06 20:46:40 +08:00
										 |  |  | class SourceMapDevToolPlugin { | 
					
						
							| 
									
										
										
										
											2018-09-20 16:13:55 +08:00
										 |  |  | 	/** | 
					
						
							| 
									
										
										
										
											2019-07-09 04:31:11 +08:00
										 |  |  | 	 * @param {SourceMapDevToolPluginOptions} [options] options object | 
					
						
							| 
									
										
										
										
											2019-06-27 00:40:56 +08:00
										 |  |  | 	 * @throws {Error} throws error, if got more than 1 arguments | 
					
						
							| 
									
										
										
										
											2018-09-20 16:13:55 +08:00
										 |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2018-07-06 17:19:30 +08:00
										 |  |  | 	constructor(options = {}) { | 
					
						
							| 
									
										
										
										
											2021-04-16 21:35:18 +08:00
										 |  |  | 		validate(options); | 
					
						
							| 
									
										
										
										
											2017-10-28 05:23:38 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-25 22:07:42 +08:00
										 |  |  | 		/** @type {string | false} */ | 
					
						
							| 
									
										
										
										
											2017-04-06 20:46:40 +08:00
										 |  |  | 		this.sourceMapFilename = options.filename; | 
					
						
							| 
									
										
										
										
											2018-09-20 16:13:55 +08:00
										 |  |  | 		/** @type {string | false} */ | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		this.sourceMappingURLComment = | 
					
						
							|  |  |  | 			options.append === false | 
					
						
							|  |  |  | 				? false | 
					
						
							| 
									
										
										
										
											2019-10-18 21:10:03 +08:00
										 |  |  | 				: options.append || "\n//# source" + "MappingURL=[url]"; | 
					
						
							| 
									
										
										
										
											2019-06-27 00:40:56 +08:00
										 |  |  | 		/** @type {string | Function} */ | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		this.moduleFilenameTemplate = | 
					
						
							|  |  |  | 			options.moduleFilenameTemplate || "webpack://[namespace]/[resourcePath]"; | 
					
						
							| 
									
										
										
										
											2019-06-27 00:40:56 +08:00
										 |  |  | 		/** @type {string | Function} */ | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		this.fallbackModuleFilenameTemplate = | 
					
						
							|  |  |  | 			options.fallbackModuleFilenameTemplate || | 
					
						
							|  |  |  | 			"webpack://[namespace]/[resourcePath]?[hash]"; | 
					
						
							| 
									
										
										
										
											2019-06-27 00:40:56 +08:00
										 |  |  | 		/** @type {string} */ | 
					
						
							| 
									
										
										
										
											2017-10-20 04:23:28 +08:00
										 |  |  | 		this.namespace = options.namespace || ""; | 
					
						
							| 
									
										
										
										
											2019-06-27 00:40:56 +08:00
										 |  |  | 		/** @type {SourceMapDevToolPluginOptions} */ | 
					
						
							| 
									
										
										
										
											2017-04-06 20:46:40 +08:00
										 |  |  | 		this.options = options; | 
					
						
							| 
									
										
										
										
											2015-02-19 08:11:29 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-04-06 20:46:40 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-23 01:23:48 +08:00
										 |  |  | 	/** | 
					
						
							| 
									
										
										
										
											2020-04-23 16:48:36 +08:00
										 |  |  | 	 * Apply the plugin | 
					
						
							| 
									
										
										
										
											2019-07-09 04:31:11 +08:00
										 |  |  | 	 * @param {Compiler} compiler compiler instance | 
					
						
							| 
									
										
										
										
											2018-08-23 01:23:48 +08:00
										 |  |  | 	 * @returns {void} | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2017-04-06 20:46:40 +08:00
										 |  |  | 	apply(compiler) { | 
					
						
							| 
									
										
										
										
											2019-06-11 19:09:42 +08:00
										 |  |  | 		const outputFs = compiler.outputFileSystem; | 
					
						
							| 
									
										
										
										
											2017-04-06 20:46:40 +08:00
										 |  |  | 		const sourceMapFilename = this.sourceMapFilename; | 
					
						
							|  |  |  | 		const sourceMappingURLComment = this.sourceMappingURLComment; | 
					
						
							|  |  |  | 		const moduleFilenameTemplate = this.moduleFilenameTemplate; | 
					
						
							| 
									
										
										
										
											2017-10-20 04:23:28 +08:00
										 |  |  | 		const namespace = this.namespace; | 
					
						
							| 
									
										
										
										
											2017-04-06 20:46:40 +08:00
										 |  |  | 		const fallbackModuleFilenameTemplate = this.fallbackModuleFilenameTemplate; | 
					
						
							| 
									
										
										
										
											2017-12-01 17:44:22 +08:00
										 |  |  | 		const requestShortener = compiler.requestShortener; | 
					
						
							| 
									
										
										
										
											2017-04-06 20:46:40 +08:00
										 |  |  | 		const options = this.options; | 
					
						
							| 
									
										
										
										
											2021-07-09 02:04:23 +08:00
										 |  |  | 		options.test = options.test || /\.((c|m)?js|css)($|\?)/i; | 
					
						
							| 
									
										
										
										
											2017-07-17 13:15:42 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		const matchObject = ModuleFilenameHelpers.matchObject.bind( | 
					
						
							|  |  |  | 			undefined, | 
					
						
							|  |  |  | 			options | 
					
						
							|  |  |  | 		); | 
					
						
							| 
									
										
										
										
											2017-07-17 13:15:42 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		compiler.hooks.compilation.tap("SourceMapDevToolPlugin", compilation => { | 
					
						
							| 
									
										
										
										
											2017-04-06 20:46:40 +08:00
										 |  |  | 			new SourceMapDevToolModuleOptionsPlugin(options).apply(compilation); | 
					
						
							| 
									
										
										
										
											2017-07-17 13:15:42 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-12 18:16:51 +08:00
										 |  |  | 			compilation.hooks.processAssets.tapAsync( | 
					
						
							|  |  |  | 				{ | 
					
						
							|  |  |  | 					name: "SourceMapDevToolPlugin", | 
					
						
							| 
									
										
										
										
											2020-11-09 18:58:18 +08:00
										 |  |  | 					stage: Compilation.PROCESS_ASSETS_STAGE_DEV_TOOLING, | 
					
						
							|  |  |  | 					additionalAssets: true | 
					
						
							| 
									
										
										
										
											2020-05-12 18:16:51 +08:00
										 |  |  | 				}, | 
					
						
							| 
									
										
										
										
											2019-10-31 03:47:17 +08:00
										 |  |  | 				(assets, callback) => { | 
					
						
							| 
									
										
										
										
											2018-08-28 17:50:33 +08:00
										 |  |  | 					const chunkGraph = compilation.chunkGraph; | 
					
						
							| 
									
										
										
										
											2020-07-15 17:14:28 +08:00
										 |  |  | 					const cache = compilation.getCache("SourceMapDevToolPlugin"); | 
					
						
							| 
									
										
										
										
											2019-06-27 00:40:56 +08:00
										 |  |  | 					/** @type {Map<string | Module, string>} */ | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 					const moduleToSourceNameMapping = new Map(); | 
					
						
							| 
									
										
										
										
											2019-06-27 00:40:56 +08:00
										 |  |  | 					/** | 
					
						
							|  |  |  | 					 * @type {Function} | 
					
						
							|  |  |  | 					 * @returns {void} | 
					
						
							|  |  |  | 					 */ | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 					const reportProgress = | 
					
						
							| 
									
										
										
										
											2018-11-27 07:06:02 +08:00
										 |  |  | 						ProgressPlugin.getReporter(compilation.compiler) || (() => {}); | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-09-09 18:18:06 +08:00
										 |  |  | 					/** @type {Map<string, Chunk>} */ | 
					
						
							|  |  |  | 					const fileToChunk = new Map(); | 
					
						
							|  |  |  | 					for (const chunk of compilation.chunks) { | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 						for (const file of chunk.files) { | 
					
						
							| 
									
										
										
										
											2019-09-09 18:18:06 +08:00
										 |  |  | 							fileToChunk.set(file, chunk); | 
					
						
							|  |  |  | 						} | 
					
						
							|  |  |  | 						for (const file of chunk.auxiliaryFiles) { | 
					
						
							|  |  |  | 							fileToChunk.set(file, chunk); | 
					
						
							|  |  |  | 						} | 
					
						
							|  |  |  | 					} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 					/** @type {string[]} */ | 
					
						
							|  |  |  | 					const files = []; | 
					
						
							|  |  |  | 					for (const file of Object.keys(assets)) { | 
					
						
							|  |  |  | 						if (matchObject(file)) { | 
					
						
							|  |  |  | 							files.push(file); | 
					
						
							| 
									
										
										
										
											2017-07-07 18:51:55 +08:00
										 |  |  | 						} | 
					
						
							| 
									
										
										
										
											2018-01-22 20:52:43 +08:00
										 |  |  | 					} | 
					
						
							| 
									
										
										
										
											2017-07-17 13:15:42 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 					reportProgress(0.0); | 
					
						
							| 
									
										
										
										
											2019-07-17 22:02:33 +08:00
										 |  |  | 					/** @type {SourceMapTask[]} */ | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 					const tasks = []; | 
					
						
							| 
									
										
										
										
											2019-10-16 03:30:21 +08:00
										 |  |  | 					let fileIndex = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 					asyncLib.each( | 
					
						
							|  |  |  | 						files, | 
					
						
							| 
									
										
										
										
											2019-10-31 03:47:17 +08:00
										 |  |  | 						(file, callback) => { | 
					
						
							| 
									
										
										
										
											2020-08-01 04:03:14 +08:00
										 |  |  | 							const asset = compilation.getAsset(file); | 
					
						
							|  |  |  | 							if (asset.info.related && asset.info.related.sourceMap) { | 
					
						
							|  |  |  | 								fileIndex++; | 
					
						
							|  |  |  | 								return callback(); | 
					
						
							|  |  |  | 							} | 
					
						
							| 
									
										
										
										
											2020-07-15 17:14:28 +08:00
										 |  |  | 							const cacheItem = cache.getItemCache( | 
					
						
							|  |  |  | 								file, | 
					
						
							| 
									
										
										
										
											2021-03-06 19:07:57 +08:00
										 |  |  | 								cache.mergeEtags( | 
					
						
							|  |  |  | 									cache.getLazyHashedEtag(asset.source), | 
					
						
							|  |  |  | 									namespace | 
					
						
							|  |  |  | 								) | 
					
						
							| 
									
										
										
										
											2020-07-15 17:14:28 +08:00
										 |  |  | 							); | 
					
						
							| 
									
										
										
										
											2018-01-04 22:41:26 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-01 04:03:14 +08:00
										 |  |  | 							cacheItem.get((err, cacheEntry) => { | 
					
						
							| 
									
										
										
										
											2019-10-31 03:47:17 +08:00
										 |  |  | 								if (err) { | 
					
						
							|  |  |  | 									return callback(err); | 
					
						
							|  |  |  | 								} | 
					
						
							|  |  |  | 								/** | 
					
						
							|  |  |  | 								 * If presented in cache, reassigns assets. Cache assets already have source maps. | 
					
						
							|  |  |  | 								 */ | 
					
						
							| 
									
										
										
										
											2020-08-01 04:03:14 +08:00
										 |  |  | 								if (cacheEntry) { | 
					
						
							|  |  |  | 									const { assets, assetsInfo } = cacheEntry; | 
					
						
							|  |  |  | 									for (const cachedFile of Object.keys(assets)) { | 
					
						
							| 
									
										
										
										
											2019-10-31 03:47:17 +08:00
										 |  |  | 										if (cachedFile === file) { | 
					
						
							| 
									
										
										
										
											2020-08-01 04:03:14 +08:00
										 |  |  | 											compilation.updateAsset( | 
					
						
							|  |  |  | 												cachedFile, | 
					
						
							|  |  |  | 												assets[cachedFile], | 
					
						
							|  |  |  | 												assetsInfo[cachedFile] | 
					
						
							|  |  |  | 											); | 
					
						
							| 
									
										
										
										
											2019-10-31 03:47:17 +08:00
										 |  |  | 										} else { | 
					
						
							| 
									
										
										
										
											2020-08-01 04:03:14 +08:00
										 |  |  | 											compilation.emitAsset( | 
					
						
							|  |  |  | 												cachedFile, | 
					
						
							|  |  |  | 												assets[cachedFile], | 
					
						
							|  |  |  | 												assetsInfo[cachedFile] | 
					
						
							|  |  |  | 											); | 
					
						
							| 
									
										
										
										
											2019-10-31 03:47:17 +08:00
										 |  |  | 										} | 
					
						
							|  |  |  | 										/** | 
					
						
							|  |  |  | 										 * Add file to chunk, if not presented there | 
					
						
							|  |  |  | 										 */ | 
					
						
							|  |  |  | 										if (cachedFile !== file) { | 
					
						
							|  |  |  | 											const chunk = fileToChunk.get(file); | 
					
						
							|  |  |  | 											if (chunk !== undefined) | 
					
						
							|  |  |  | 												chunk.auxiliaryFiles.add(cachedFile); | 
					
						
							|  |  |  | 										} | 
					
						
							| 
									
										
										
										
											2019-10-16 03:30:21 +08:00
										 |  |  | 									} | 
					
						
							| 
									
										
										
										
											2018-01-04 22:41:26 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-16 03:30:21 +08:00
										 |  |  | 									reportProgress( | 
					
						
							| 
									
										
										
										
											2019-11-12 21:35:19 +08:00
										 |  |  | 										(0.5 * ++fileIndex) / files.length, | 
					
						
							| 
									
										
										
										
											2019-10-16 03:30:21 +08:00
										 |  |  | 										file, | 
					
						
							| 
									
										
										
										
											2019-11-12 21:35:19 +08:00
										 |  |  | 										"restored cached SourceMap" | 
					
						
							| 
									
										
										
										
											2019-10-16 03:30:21 +08:00
										 |  |  | 									); | 
					
						
							| 
									
										
										
										
											2018-01-04 22:41:26 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-31 03:47:17 +08:00
										 |  |  | 									return callback(); | 
					
						
							|  |  |  | 								} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-12 21:35:19 +08:00
										 |  |  | 								reportProgress( | 
					
						
							|  |  |  | 									(0.5 * fileIndex) / files.length, | 
					
						
							|  |  |  | 									file, | 
					
						
							|  |  |  | 									"generate SourceMap" | 
					
						
							|  |  |  | 								); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-31 03:47:17 +08:00
										 |  |  | 								/** @type {SourceMapTask | undefined} */ | 
					
						
							|  |  |  | 								const task = getTaskForFile( | 
					
						
							|  |  |  | 									file, | 
					
						
							| 
									
										
										
										
											2020-08-01 04:03:14 +08:00
										 |  |  | 									asset.source, | 
					
						
							| 
									
										
										
										
											2020-08-19 03:14:43 +08:00
										 |  |  | 									asset.info, | 
					
						
							| 
									
										
										
										
											2020-10-26 21:41:46 +08:00
										 |  |  | 									{ | 
					
						
							|  |  |  | 										module: options.module, | 
					
						
							|  |  |  | 										columns: options.columns | 
					
						
							|  |  |  | 									}, | 
					
						
							| 
									
										
										
										
											2019-10-31 03:47:17 +08:00
										 |  |  | 									compilation, | 
					
						
							| 
									
										
										
										
											2020-07-15 17:14:28 +08:00
										 |  |  | 									cacheItem | 
					
						
							| 
									
										
										
										
											2019-10-31 03:47:17 +08:00
										 |  |  | 								); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 								if (task) { | 
					
						
							|  |  |  | 									const modules = task.modules; | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-31 03:47:17 +08:00
										 |  |  | 									for (let idx = 0; idx < modules.length; idx++) { | 
					
						
							|  |  |  | 										const module = modules[idx]; | 
					
						
							|  |  |  | 										if (!moduleToSourceNameMapping.get(module)) { | 
					
						
							|  |  |  | 											moduleToSourceNameMapping.set( | 
					
						
							|  |  |  | 												module, | 
					
						
							|  |  |  | 												ModuleFilenameHelpers.createFilename( | 
					
						
							| 
									
										
										
										
											2019-10-16 03:30:21 +08:00
										 |  |  | 													module, | 
					
						
							| 
									
										
										
										
											2019-10-31 03:47:17 +08:00
										 |  |  | 													{ | 
					
						
							|  |  |  | 														moduleFilenameTemplate: moduleFilenameTemplate, | 
					
						
							|  |  |  | 														namespace: namespace | 
					
						
							|  |  |  | 													}, | 
					
						
							|  |  |  | 													{ | 
					
						
							|  |  |  | 														requestShortener, | 
					
						
							| 
									
										
										
										
											2021-09-22 18:12:46 +08:00
										 |  |  | 														chunkGraph, | 
					
						
							|  |  |  | 														hashFunction: compilation.outputOptions.hashFunction | 
					
						
							| 
									
										
										
										
											2019-10-31 03:47:17 +08:00
										 |  |  | 													} | 
					
						
							|  |  |  | 												) | 
					
						
							|  |  |  | 											); | 
					
						
							| 
									
										
										
										
											2019-10-16 03:30:21 +08:00
										 |  |  | 										} | 
					
						
							|  |  |  | 									} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-31 03:47:17 +08:00
										 |  |  | 									tasks.push(task); | 
					
						
							| 
									
										
										
										
											2019-10-16 03:30:21 +08:00
										 |  |  | 								} | 
					
						
							| 
									
										
										
										
											2019-10-31 03:47:17 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 								reportProgress( | 
					
						
							| 
									
										
										
										
											2019-11-12 21:35:19 +08:00
										 |  |  | 									(0.5 * ++fileIndex) / files.length, | 
					
						
							| 
									
										
										
										
											2019-10-31 03:47:17 +08:00
										 |  |  | 									file, | 
					
						
							| 
									
										
										
										
											2019-11-12 21:35:19 +08:00
										 |  |  | 									"generated SourceMap" | 
					
						
							| 
									
										
										
										
											2019-10-31 03:47:17 +08:00
										 |  |  | 								); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 								callback(); | 
					
						
							|  |  |  | 							}); | 
					
						
							| 
									
										
										
										
											2019-10-16 03:30:21 +08:00
										 |  |  | 						}, | 
					
						
							| 
									
										
										
										
											2019-10-31 03:47:17 +08:00
										 |  |  | 						err => { | 
					
						
							|  |  |  | 							if (err) { | 
					
						
							|  |  |  | 								return callback(err); | 
					
						
							|  |  |  | 							} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-16 03:30:21 +08:00
										 |  |  | 							reportProgress(0.5, "resolve sources"); | 
					
						
							|  |  |  | 							/** @type {Set<string>} */ | 
					
						
							|  |  |  | 							const usedNamesSet = new Set(moduleToSourceNameMapping.values()); | 
					
						
							|  |  |  | 							/** @type {Set<string>} */ | 
					
						
							|  |  |  | 							const conflictDetectionSet = new Set(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-27 00:40:56 +08:00
										 |  |  | 							/** | 
					
						
							| 
									
										
										
										
											2019-10-16 03:30:21 +08:00
										 |  |  | 							 * all modules in defined order (longest identifier first) | 
					
						
							|  |  |  | 							 * @type {Array<string | Module>} | 
					
						
							| 
									
										
										
										
											2019-06-27 00:40:56 +08:00
										 |  |  | 							 */ | 
					
						
							| 
									
										
										
										
											2019-10-16 03:30:21 +08:00
										 |  |  | 							const allModules = Array.from( | 
					
						
							|  |  |  | 								moduleToSourceNameMapping.keys() | 
					
						
							|  |  |  | 							).sort((a, b) => { | 
					
						
							|  |  |  | 								const ai = typeof a === "string" ? a : a.identifier(); | 
					
						
							|  |  |  | 								const bi = typeof b === "string" ? b : b.identifier(); | 
					
						
							|  |  |  | 								return ai.length - bi.length; | 
					
						
							| 
									
										
										
										
											2019-09-11 17:13:46 +08:00
										 |  |  | 							}); | 
					
						
							| 
									
										
										
										
											2019-10-16 03:30:21 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 							// find modules with conflicting source names
 | 
					
						
							|  |  |  | 							for (let idx = 0; idx < allModules.length; idx++) { | 
					
						
							|  |  |  | 								const module = allModules[idx]; | 
					
						
							|  |  |  | 								let sourceName = moduleToSourceNameMapping.get(module); | 
					
						
							|  |  |  | 								let hasName = conflictDetectionSet.has(sourceName); | 
					
						
							|  |  |  | 								if (!hasName) { | 
					
						
							|  |  |  | 									conflictDetectionSet.add(sourceName); | 
					
						
							|  |  |  | 									continue; | 
					
						
							|  |  |  | 								} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 								// try the fallback name first
 | 
					
						
							|  |  |  | 								sourceName = ModuleFilenameHelpers.createFilename( | 
					
						
							|  |  |  | 									module, | 
					
						
							|  |  |  | 									{ | 
					
						
							|  |  |  | 										moduleFilenameTemplate: fallbackModuleFilenameTemplate, | 
					
						
							|  |  |  | 										namespace: namespace | 
					
						
							|  |  |  | 									}, | 
					
						
							|  |  |  | 									{ | 
					
						
							|  |  |  | 										requestShortener, | 
					
						
							| 
									
										
										
										
											2021-09-22 18:12:46 +08:00
										 |  |  | 										chunkGraph, | 
					
						
							|  |  |  | 										hashFunction: compilation.outputOptions.hashFunction | 
					
						
							| 
									
										
										
										
											2019-10-16 03:30:21 +08:00
										 |  |  | 									} | 
					
						
							| 
									
										
										
										
											2018-09-20 16:13:55 +08:00
										 |  |  | 								); | 
					
						
							| 
									
										
										
										
											2019-10-16 03:30:21 +08:00
										 |  |  | 								hasName = usedNamesSet.has(sourceName); | 
					
						
							|  |  |  | 								if (!hasName) { | 
					
						
							|  |  |  | 									moduleToSourceNameMapping.set(module, sourceName); | 
					
						
							|  |  |  | 									usedNamesSet.add(sourceName); | 
					
						
							|  |  |  | 									continue; | 
					
						
							|  |  |  | 								} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-13 00:51:26 +08:00
										 |  |  | 								// otherwise just append stars until we have a valid name
 | 
					
						
							| 
									
										
										
										
											2019-10-16 03:30:21 +08:00
										 |  |  | 								while (hasName) { | 
					
						
							|  |  |  | 									sourceName += "*"; | 
					
						
							|  |  |  | 									hasName = usedNamesSet.has(sourceName); | 
					
						
							|  |  |  | 								} | 
					
						
							|  |  |  | 								moduleToSourceNameMapping.set(module, sourceName); | 
					
						
							|  |  |  | 								usedNamesSet.add(sourceName); | 
					
						
							| 
									
										
										
										
											2018-09-20 16:13:55 +08:00
										 |  |  | 							} | 
					
						
							| 
									
										
										
										
											2019-10-16 03:30:21 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 							let taskIndex = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 							asyncLib.each( | 
					
						
							|  |  |  | 								tasks, | 
					
						
							| 
									
										
										
										
											2019-10-31 03:47:17 +08:00
										 |  |  | 								(task, callback) => { | 
					
						
							| 
									
										
										
										
											2019-10-16 03:30:21 +08:00
										 |  |  | 									const assets = Object.create(null); | 
					
						
							| 
									
										
										
										
											2020-08-01 04:03:14 +08:00
										 |  |  | 									const assetsInfo = Object.create(null); | 
					
						
							| 
									
										
										
										
											2019-10-16 03:30:21 +08:00
										 |  |  | 									const file = task.file; | 
					
						
							|  |  |  | 									const chunk = fileToChunk.get(file); | 
					
						
							|  |  |  | 									const sourceMap = task.sourceMap; | 
					
						
							|  |  |  | 									const source = task.source; | 
					
						
							|  |  |  | 									const modules = task.modules; | 
					
						
							| 
									
										
										
										
											2019-11-12 21:35:19 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 									reportProgress( | 
					
						
							|  |  |  | 										0.5 + (0.5 * taskIndex) / tasks.length, | 
					
						
							|  |  |  | 										file, | 
					
						
							|  |  |  | 										"attach SourceMap" | 
					
						
							|  |  |  | 									); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-16 03:30:21 +08:00
										 |  |  | 									const moduleFilenames = modules.map(m => | 
					
						
							|  |  |  | 										moduleToSourceNameMapping.get(m) | 
					
						
							|  |  |  | 									); | 
					
						
							|  |  |  | 									sourceMap.sources = moduleFilenames; | 
					
						
							|  |  |  | 									if (options.noSources) { | 
					
						
							|  |  |  | 										sourceMap.sourcesContent = undefined; | 
					
						
							|  |  |  | 									} | 
					
						
							|  |  |  | 									sourceMap.sourceRoot = options.sourceRoot || ""; | 
					
						
							|  |  |  | 									sourceMap.file = file; | 
					
						
							| 
									
										
										
										
											2020-08-19 03:14:43 +08:00
										 |  |  | 									const usesContentHash = | 
					
						
							|  |  |  | 										sourceMapFilename && | 
					
						
							|  |  |  | 										/\[contenthash(:\w+)?\]/.test(sourceMapFilename); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 									// If SourceMap and asset uses contenthash, avoid a circular dependency by hiding hash in `file`
 | 
					
						
							|  |  |  | 									if (usesContentHash && task.assetInfo.contenthash) { | 
					
						
							|  |  |  | 										const contenthash = task.assetInfo.contenthash; | 
					
						
							|  |  |  | 										let pattern; | 
					
						
							|  |  |  | 										if (Array.isArray(contenthash)) { | 
					
						
							|  |  |  | 											pattern = contenthash.map(quoteMeta).join("|"); | 
					
						
							|  |  |  | 										} else { | 
					
						
							|  |  |  | 											pattern = quoteMeta(contenthash); | 
					
						
							|  |  |  | 										} | 
					
						
							|  |  |  | 										sourceMap.file = sourceMap.file.replace( | 
					
						
							|  |  |  | 											new RegExp(pattern, "g"), | 
					
						
							|  |  |  | 											m => "x".repeat(m.length) | 
					
						
							|  |  |  | 										); | 
					
						
							|  |  |  | 									} | 
					
						
							| 
									
										
										
										
											2019-10-16 03:30:21 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-31 03:47:17 +08:00
										 |  |  | 									/** @type {string | false} */ | 
					
						
							|  |  |  | 									let currentSourceMappingURLComment = sourceMappingURLComment; | 
					
						
							|  |  |  | 									if ( | 
					
						
							|  |  |  | 										currentSourceMappingURLComment !== false && | 
					
						
							|  |  |  | 										/\.css($|\?)/i.test(file) | 
					
						
							|  |  |  | 									) { | 
					
						
							| 
									
										
										
										
											2021-05-11 15:31:46 +08:00
										 |  |  | 										currentSourceMappingURLComment = | 
					
						
							|  |  |  | 											currentSourceMappingURLComment.replace( | 
					
						
							|  |  |  | 												/^\n\/\/(.*)$/, | 
					
						
							|  |  |  | 												"\n/*$1*/" | 
					
						
							|  |  |  | 											); | 
					
						
							| 
									
										
										
										
											2019-10-31 03:47:17 +08:00
										 |  |  | 									} | 
					
						
							|  |  |  | 									const sourceMapString = JSON.stringify(sourceMap); | 
					
						
							|  |  |  | 									if (sourceMapFilename) { | 
					
						
							|  |  |  | 										let filename = file; | 
					
						
							| 
									
										
										
										
											2020-08-19 03:14:43 +08:00
										 |  |  | 										const sourceMapContentHash = | 
					
						
							|  |  |  | 											usesContentHash && | 
					
						
							| 
									
										
										
										
											2021-05-11 15:31:46 +08:00
										 |  |  | 											/** @type {string} */ ( | 
					
						
							| 
									
										
										
										
											2021-09-22 18:12:46 +08:00
										 |  |  | 												createHash(compilation.outputOptions.hashFunction) | 
					
						
							|  |  |  | 													.update(sourceMapString) | 
					
						
							|  |  |  | 													.digest("hex") | 
					
						
							| 
									
										
										
										
											2021-05-11 15:31:46 +08:00
										 |  |  | 											); | 
					
						
							| 
									
										
										
										
											2019-10-31 03:47:17 +08:00
										 |  |  | 										const pathParams = { | 
					
						
							|  |  |  | 											chunk, | 
					
						
							|  |  |  | 											filename: options.fileContext | 
					
						
							|  |  |  | 												? relative( | 
					
						
							|  |  |  | 														outputFs, | 
					
						
							|  |  |  | 														`/${options.fileContext}`, | 
					
						
							|  |  |  | 														`/${filename}` | 
					
						
							|  |  |  | 												  ) | 
					
						
							|  |  |  | 												: filename, | 
					
						
							| 
									
										
										
										
											2020-08-19 03:14:43 +08:00
										 |  |  | 											contentHash: sourceMapContentHash | 
					
						
							| 
									
										
										
										
											2019-10-31 03:47:17 +08:00
										 |  |  | 										}; | 
					
						
							| 
									
										
										
										
											2021-05-11 15:31:46 +08:00
										 |  |  | 										const { path: sourceMapFile, info: sourceMapInfo } = | 
					
						
							|  |  |  | 											compilation.getPathWithInfo( | 
					
						
							|  |  |  | 												sourceMapFilename, | 
					
						
							|  |  |  | 												pathParams | 
					
						
							|  |  |  | 											); | 
					
						
							| 
									
										
										
										
											2019-10-31 03:47:17 +08:00
										 |  |  | 										const sourceMapUrl = options.publicPath | 
					
						
							|  |  |  | 											? options.publicPath + sourceMapFile | 
					
						
							|  |  |  | 											: relative( | 
					
						
							|  |  |  | 													outputFs, | 
					
						
							|  |  |  | 													dirname(outputFs, `/${file}`), | 
					
						
							|  |  |  | 													`/${sourceMapFile}` | 
					
						
							|  |  |  | 											  ); | 
					
						
							| 
									
										
										
										
											2020-08-01 04:03:14 +08:00
										 |  |  | 										/** @type {Source} */ | 
					
						
							|  |  |  | 										let asset = new RawSource(source); | 
					
						
							| 
									
										
										
										
											2019-10-31 03:47:17 +08:00
										 |  |  | 										if (currentSourceMappingURLComment !== false) { | 
					
						
							| 
									
										
										
										
											2020-08-01 04:03:14 +08:00
										 |  |  | 											// Add source map url to compilation asset, if currentSourceMappingURLComment is set
 | 
					
						
							|  |  |  | 											asset = new ConcatSource( | 
					
						
							|  |  |  | 												asset, | 
					
						
							| 
									
										
										
										
											2019-10-31 03:47:17 +08:00
										 |  |  | 												compilation.getPath( | 
					
						
							|  |  |  | 													currentSourceMappingURLComment, | 
					
						
							|  |  |  | 													Object.assign({ url: sourceMapUrl }, pathParams) | 
					
						
							|  |  |  | 												) | 
					
						
							|  |  |  | 											); | 
					
						
							|  |  |  | 										} | 
					
						
							| 
									
										
										
										
											2020-08-01 04:03:14 +08:00
										 |  |  | 										const assetInfo = { | 
					
						
							|  |  |  | 											related: { sourceMap: sourceMapFile } | 
					
						
							|  |  |  | 										}; | 
					
						
							|  |  |  | 										assets[file] = asset; | 
					
						
							|  |  |  | 										assetsInfo[file] = assetInfo; | 
					
						
							|  |  |  | 										compilation.updateAsset(file, asset, assetInfo); | 
					
						
							|  |  |  | 										// Add source map file to compilation assets and chunk files
 | 
					
						
							|  |  |  | 										const sourceMapAsset = new RawSource(sourceMapString); | 
					
						
							|  |  |  | 										const sourceMapAssetInfo = { | 
					
						
							| 
									
										
										
										
											2020-08-19 03:14:43 +08:00
										 |  |  | 											...sourceMapInfo, | 
					
						
							| 
									
										
										
										
											2019-10-31 03:47:17 +08:00
										 |  |  | 											development: true | 
					
						
							| 
									
										
										
										
											2020-08-01 04:03:14 +08:00
										 |  |  | 										}; | 
					
						
							|  |  |  | 										assets[sourceMapFile] = sourceMapAsset; | 
					
						
							|  |  |  | 										assetsInfo[sourceMapFile] = sourceMapAssetInfo; | 
					
						
							|  |  |  | 										compilation.emitAsset( | 
					
						
							|  |  |  | 											sourceMapFile, | 
					
						
							|  |  |  | 											sourceMapAsset, | 
					
						
							|  |  |  | 											sourceMapAssetInfo | 
					
						
							|  |  |  | 										); | 
					
						
							| 
									
										
										
										
											2019-10-31 03:47:17 +08:00
										 |  |  | 										if (chunk !== undefined) | 
					
						
							|  |  |  | 											chunk.auxiliaryFiles.add(sourceMapFile); | 
					
						
							|  |  |  | 									} else { | 
					
						
							|  |  |  | 										if (currentSourceMappingURLComment === false) { | 
					
						
							|  |  |  | 											throw new Error( | 
					
						
							|  |  |  | 												"SourceMapDevToolPlugin: append can't be false when no filename is provided" | 
					
						
							|  |  |  | 											); | 
					
						
							|  |  |  | 										} | 
					
						
							|  |  |  | 										/** | 
					
						
							|  |  |  | 										 * Add source map as data url to asset | 
					
						
							|  |  |  | 										 */ | 
					
						
							|  |  |  | 										const asset = new ConcatSource( | 
					
						
							|  |  |  | 											new RawSource(source), | 
					
						
							|  |  |  | 											currentSourceMappingURLComment | 
					
						
							|  |  |  | 												.replace(/\[map\]/g, () => sourceMapString) | 
					
						
							|  |  |  | 												.replace( | 
					
						
							|  |  |  | 													/\[url\]/g, | 
					
						
							|  |  |  | 													() => | 
					
						
							|  |  |  | 														`data:application/json;charset=utf-8;base64,${Buffer.from( | 
					
						
							|  |  |  | 															sourceMapString, | 
					
						
							|  |  |  | 															"utf-8" | 
					
						
							|  |  |  | 														).toString("base64")}`
 | 
					
						
							|  |  |  | 												) | 
					
						
							|  |  |  | 										); | 
					
						
							|  |  |  | 										assets[file] = asset; | 
					
						
							| 
									
										
										
										
											2020-08-01 04:03:14 +08:00
										 |  |  | 										assetsInfo[file] = undefined; | 
					
						
							| 
									
										
										
										
											2019-10-31 03:47:17 +08:00
										 |  |  | 										compilation.updateAsset(file, asset); | 
					
						
							|  |  |  | 									} | 
					
						
							| 
									
										
										
										
											2019-10-16 03:30:21 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-01 04:03:14 +08:00
										 |  |  | 									task.cacheItem.store({ assets, assetsInfo }, err => { | 
					
						
							| 
									
										
										
										
											2020-07-15 17:14:28 +08:00
										 |  |  | 										reportProgress( | 
					
						
							|  |  |  | 											0.5 + (0.5 * ++taskIndex) / tasks.length, | 
					
						
							|  |  |  | 											task.file, | 
					
						
							|  |  |  | 											"attached SourceMap" | 
					
						
							|  |  |  | 										); | 
					
						
							| 
									
										
										
										
											2019-10-31 03:47:17 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-15 17:14:28 +08:00
										 |  |  | 										if (err) { | 
					
						
							|  |  |  | 											return callback(err); | 
					
						
							| 
									
										
										
										
											2019-10-16 03:30:21 +08:00
										 |  |  | 										} | 
					
						
							| 
									
										
										
										
											2020-07-15 17:14:28 +08:00
										 |  |  | 										callback(); | 
					
						
							|  |  |  | 									}); | 
					
						
							| 
									
										
										
										
											2019-10-16 03:30:21 +08:00
										 |  |  | 								}, | 
					
						
							| 
									
										
										
										
											2019-10-31 03:47:17 +08:00
										 |  |  | 								err => { | 
					
						
							|  |  |  | 									reportProgress(1.0); | 
					
						
							|  |  |  | 									callback(err); | 
					
						
							|  |  |  | 								} | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 							); | 
					
						
							| 
									
										
										
										
											2017-04-06 20:46:40 +08:00
										 |  |  | 						} | 
					
						
							| 
									
										
										
										
											2019-10-16 03:30:21 +08:00
										 |  |  | 					); | 
					
						
							| 
									
										
										
										
											2018-11-27 07:06:02 +08:00
										 |  |  | 				} | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 			); | 
					
						
							| 
									
										
										
										
											2013-03-26 23:54:41 +08:00
										 |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2017-04-06 20:46:40 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2014-06-17 22:35:31 +08:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2017-04-06 20:46:40 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | module.exports = SourceMapDevToolPlugin; |