| 
									
										
										
										
											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"); | 
					
						
							| 
									
										
										
										
											2024-11-21 21:03:36 +08:00
										 |  |  | const generateDebugId = require("./util/generateDebugId"); | 
					
						
							| 
									
										
										
										
											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 */ | 
					
						
							| 
									
										
										
										
											2023-06-17 01:13:03 +08:00
										 |  |  | /** @typedef {import("./Compilation").Asset} Asset */ | 
					
						
							| 
									
										
										
										
											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 */ | 
					
						
							| 
									
										
										
										
											2024-08-08 02:59:26 +08:00
										 |  |  | /** @typedef {import("./TemplatedPathPlugin").TemplatePath} TemplatePath */ | 
					
						
							| 
									
										
										
										
											2019-10-31 03:47:17 +08:00
										 |  |  | /** @typedef {import("./util/Hash")} Hash */ | 
					
						
							| 
									
										
										
										
											2024-08-09 01:03:17 +08:00
										 |  |  | /** @typedef {import("./util/createHash").Algorithm} Algorithm */ | 
					
						
							| 
									
										
										
										
											2024-03-12 00:33:52 +08:00
										 |  |  | /** @typedef {import("./util/fs").OutputFileSystem} OutputFileSystem */ | 
					
						
							| 
									
										
										
										
											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
										 |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-04-27 00:34:51 +08:00
										 |  |  | const METACHARACTERS_REGEXP = /[-[\]\\/{}()*+?.^$|]/g; | 
					
						
							|  |  |  | const CONTENT_HASH_DETECT_REGEXP = /\[contenthash(:\w+)?\]/; | 
					
						
							|  |  |  | const CSS_AND_JS_MODULE_EXTENSIONS_REGEXP = /\.((c|m)?js|css)($|\?)/i; | 
					
						
							|  |  |  | const CSS_EXTENSION_DETECT_REGEXP = /\.css($|\?)/i; | 
					
						
							|  |  |  | const MAP_URL_COMMENT_REGEXP = /\[map\]/g; | 
					
						
							|  |  |  | const URL_COMMENT_REGEXP = /\[url\]/g; | 
					
						
							|  |  |  | const URL_FORMATTING_REGEXP = /^\n\/\/(.*)$/; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-04-27 04:46:26 +08:00
										 |  |  | /** | 
					
						
							|  |  |  |  * Reset's .lastIndex of stateful Regular Expressions | 
					
						
							|  |  |  |  * For when `test` or `exec` is called on them | 
					
						
							|  |  |  |  * @param {RegExp} regexp Stateful Regular Expression to be reset | 
					
						
							|  |  |  |  * @returns {void} | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | const resetRegexpState = regexp => { | 
					
						
							|  |  |  | 	regexp.lastIndex = -1; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-19 03:14:43 +08:00
										 |  |  | /** | 
					
						
							|  |  |  |  * Escapes regular expression metacharacters | 
					
						
							|  |  |  |  * @param {string} str String to quote | 
					
						
							|  |  |  |  * @returns {string} Escaped string | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2024-07-31 11:31:11 +08:00
										 |  |  | const quoteMeta = str => str.replace(METACHARACTERS_REGEXP, "\\$&"); | 
					
						
							| 
									
										
										
										
											2020-08-19 03:14:43 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											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; | 
					
						
							| 
									
										
										
										
											2024-08-06 11:08:48 +08:00
										 |  |  | 	const context = /** @type {string} */ (compilation.options.context); | 
					
						
							| 
									
										
										
										
											2019-11-11 22:25:03 +08:00
										 |  |  | 	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
										 |  |  | 	/** | 
					
						
							| 
									
										
										
										
											2025-04-16 22:04: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
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-08-06 11:08:48 +08:00
										 |  |  | 		this.sourceMapFilename = /** @type {string | false} */ (options.filename); | 
					
						
							| 
									
										
										
										
											2024-08-08 02:59:26 +08:00
										 |  |  | 		/** @type {false | TemplatePath}} */ | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		this.sourceMappingURLComment = | 
					
						
							|  |  |  | 			options.append === false | 
					
						
							|  |  |  | 				? false | 
					
						
							| 
									
										
										
										
											2024-07-31 09:37:24 +08:00
										 |  |  | 				: // eslint-disable-next-line no-useless-concat
 | 
					
						
							|  |  |  | 					options.append || "\n//# source" + "MappingURL=[url]"; | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		this.moduleFilenameTemplate = | 
					
						
							|  |  |  | 			options.moduleFilenameTemplate || "webpack://[namespace]/[resourcePath]"; | 
					
						
							|  |  |  | 		this.fallbackModuleFilenameTemplate = | 
					
						
							|  |  |  | 			options.fallbackModuleFilenameTemplate || | 
					
						
							|  |  |  | 			"webpack://[namespace]/[resourcePath]?[hash]"; | 
					
						
							| 
									
										
										
										
											2017-10-20 04:23:28 +08:00
										 |  |  | 		this.namespace = options.namespace || ""; | 
					
						
							| 
									
										
										
										
											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) { | 
					
						
							| 
									
										
										
										
											2024-03-12 00:33:52 +08:00
										 |  |  | 		const outputFs = /** @type {OutputFileSystem} */ ( | 
					
						
							|  |  |  | 			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; | 
					
						
							| 
									
										
										
										
											2022-04-27 00:34:51 +08:00
										 |  |  | 		options.test = options.test || CSS_AND_JS_MODULE_EXTENSIONS_REGEXP; | 
					
						
							| 
									
										
										
										
											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(); | 
					
						
							|  |  |  | 					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
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-07-31 16:17:46 +08:00
										 |  |  | 					reportProgress(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) => { | 
					
						
							| 
									
										
										
										
											2023-06-17 01:13:03 +08:00
										 |  |  | 							const asset = | 
					
						
							|  |  |  | 								/** @type {Readonly<Asset>} */ | 
					
						
							|  |  |  | 								(compilation.getAsset(file)); | 
					
						
							| 
									
										
										
										
											2020-08-01 04:03:14 +08:00
										 |  |  | 							if (asset.info.related && asset.info.related.sourceMap) { | 
					
						
							|  |  |  | 								fileIndex++; | 
					
						
							|  |  |  | 								return callback(); | 
					
						
							|  |  |  | 							} | 
					
						
							| 
									
										
										
										
											2024-06-09 09:31:31 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 							const chunk = fileToChunk.get(file); | 
					
						
							|  |  |  | 							const sourceMapNamespace = compilation.getPath(this.namespace, { | 
					
						
							| 
									
										
										
										
											2024-10-10 23:37:04 +08:00
										 |  |  | 								chunk | 
					
						
							| 
									
										
										
										
											2024-06-09 09:31:31 +08:00
										 |  |  | 							}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											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), | 
					
						
							| 
									
										
										
										
											2024-06-09 09:31:31 +08:00
										 |  |  | 									sourceMapNamespace | 
					
						
							| 
									
										
										
										
											2021-03-06 19:07:57 +08:00
										 |  |  | 								) | 
					
						
							| 
									
										
										
										
											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 | 
					
						
							|  |  |  | 										 */ | 
					
						
							| 
									
										
										
										
											2024-10-10 23:37:04 +08:00
										 |  |  | 										if (cachedFile !== file && 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]; | 
					
						
							| 
									
										
										
										
											2024-08-03 00:25:52 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 										if ( | 
					
						
							|  |  |  | 											typeof module === "string" && | 
					
						
							|  |  |  | 											/^(data|https?):/.test(module) | 
					
						
							|  |  |  | 										) { | 
					
						
							|  |  |  | 											moduleToSourceNameMapping.set(module, module); | 
					
						
							|  |  |  | 											continue; | 
					
						
							|  |  |  | 										} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-31 03:47:17 +08:00
										 |  |  | 										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
										 |  |  | 													{ | 
					
						
							| 
									
										
										
										
											2024-07-31 04:09:42 +08:00
										 |  |  | 														moduleFilenameTemplate, | 
					
						
							| 
									
										
										
										
											2024-06-09 09:31:31 +08:00
										 |  |  | 														namespace: sourceMapNamespace | 
					
						
							| 
									
										
										
										
											2019-10-31 03:47:17 +08:00
										 |  |  | 													}, | 
					
						
							|  |  |  | 													{ | 
					
						
							|  |  |  | 														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]; | 
					
						
							| 
									
										
										
										
											2023-06-17 01:13:03 +08:00
										 |  |  | 								let sourceName = | 
					
						
							|  |  |  | 									/** @type {string} */ | 
					
						
							|  |  |  | 									(moduleToSourceNameMapping.get(module)); | 
					
						
							| 
									
										
										
										
											2019-10-16 03:30:21 +08:00
										 |  |  | 								let hasName = conflictDetectionSet.has(sourceName); | 
					
						
							|  |  |  | 								if (!hasName) { | 
					
						
							|  |  |  | 									conflictDetectionSet.add(sourceName); | 
					
						
							|  |  |  | 									continue; | 
					
						
							|  |  |  | 								} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 								// try the fallback name first
 | 
					
						
							|  |  |  | 								sourceName = ModuleFilenameHelpers.createFilename( | 
					
						
							|  |  |  | 									module, | 
					
						
							|  |  |  | 									{ | 
					
						
							|  |  |  | 										moduleFilenameTemplate: fallbackModuleFilenameTemplate, | 
					
						
							| 
									
										
										
										
											2024-07-31 04:09:42 +08:00
										 |  |  | 										namespace | 
					
						
							| 
									
										
										
										
											2019-10-16 03:30:21 +08:00
										 |  |  | 									}, | 
					
						
							|  |  |  | 									{ | 
					
						
							|  |  |  | 										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) | 
					
						
							|  |  |  | 									); | 
					
						
							| 
									
										
										
										
											2024-08-09 01:03:17 +08:00
										 |  |  | 									sourceMap.sources = /** @type {string[]} */ (moduleFilenames); | 
					
						
							| 
									
										
										
										
											2019-10-16 03:30:21 +08:00
										 |  |  | 									if (options.noSources) { | 
					
						
							|  |  |  | 										sourceMap.sourcesContent = undefined; | 
					
						
							|  |  |  | 									} | 
					
						
							|  |  |  | 									sourceMap.sourceRoot = options.sourceRoot || ""; | 
					
						
							|  |  |  | 									sourceMap.file = file; | 
					
						
							| 
									
										
										
										
											2020-08-19 03:14:43 +08:00
										 |  |  | 									const usesContentHash = | 
					
						
							|  |  |  | 										sourceMapFilename && | 
					
						
							| 
									
										
										
										
											2022-04-27 00:34:51 +08:00
										 |  |  | 										CONTENT_HASH_DETECT_REGEXP.test(sourceMapFilename); | 
					
						
							| 
									
										
										
										
											2020-08-19 03:14:43 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-04-27 04:46:26 +08:00
										 |  |  | 									resetRegexpState(CONTENT_HASH_DETECT_REGEXP); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-19 03:14:43 +08:00
										 |  |  | 									// 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; | 
					
						
							| 
									
										
										
										
											2024-08-02 02:36:27 +08:00
										 |  |  | 										const pattern = Array.isArray(contenthash) | 
					
						
							|  |  |  | 											? contenthash.map(quoteMeta).join("|") | 
					
						
							|  |  |  | 											: quoteMeta(contenthash); | 
					
						
							| 
									
										
										
										
											2020-08-19 03:14:43 +08:00
										 |  |  | 										sourceMap.file = sourceMap.file.replace( | 
					
						
							|  |  |  | 											new RegExp(pattern, "g"), | 
					
						
							|  |  |  | 											m => "x".repeat(m.length) | 
					
						
							|  |  |  | 										); | 
					
						
							|  |  |  | 									} | 
					
						
							| 
									
										
										
										
											2019-10-16 03:30:21 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-08-08 02:59:26 +08:00
										 |  |  | 									/** @type {false | TemplatePath} */ | 
					
						
							| 
									
										
										
										
											2019-10-31 03:47:17 +08:00
										 |  |  | 									let currentSourceMappingURLComment = sourceMappingURLComment; | 
					
						
							| 
									
										
										
										
											2024-07-31 04:09:42 +08:00
										 |  |  | 									const cssExtensionDetected = | 
					
						
							| 
									
										
										
										
											2022-04-27 04:46:26 +08:00
										 |  |  | 										CSS_EXTENSION_DETECT_REGEXP.test(file); | 
					
						
							|  |  |  | 									resetRegexpState(CSS_EXTENSION_DETECT_REGEXP); | 
					
						
							| 
									
										
										
										
											2019-10-31 03:47:17 +08:00
										 |  |  | 									if ( | 
					
						
							|  |  |  | 										currentSourceMappingURLComment !== false && | 
					
						
							| 
									
										
										
										
											2023-05-24 13:39:36 +08:00
										 |  |  | 										typeof currentSourceMappingURLComment !== "function" && | 
					
						
							| 
									
										
										
										
											2022-04-27 04:46:26 +08:00
										 |  |  | 										cssExtensionDetected | 
					
						
							| 
									
										
										
										
											2019-10-31 03:47:17 +08:00
										 |  |  | 									) { | 
					
						
							| 
									
										
										
										
											2021-05-11 15:31:46 +08:00
										 |  |  | 										currentSourceMappingURLComment = | 
					
						
							|  |  |  | 											currentSourceMappingURLComment.replace( | 
					
						
							| 
									
										
										
										
											2022-04-27 00:34:51 +08:00
										 |  |  | 												URL_FORMATTING_REGEXP, | 
					
						
							| 
									
										
										
										
											2021-05-11 15:31:46 +08:00
										 |  |  | 												"\n/*$1*/" | 
					
						
							|  |  |  | 											); | 
					
						
							| 
									
										
										
										
											2019-10-31 03:47:17 +08:00
										 |  |  | 									} | 
					
						
							| 
									
										
										
										
											2024-11-08 20:49:08 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 									if (options.debugIds) { | 
					
						
							| 
									
										
										
										
											2024-11-21 21:03:36 +08:00
										 |  |  | 										const debugId = generateDebugId(source, sourceMap.file); | 
					
						
							| 
									
										
										
										
											2024-11-08 20:49:08 +08:00
										 |  |  | 										sourceMap.debugId = debugId; | 
					
						
							|  |  |  | 										currentSourceMappingURLComment = `\n//# debugId=${debugId}${currentSourceMappingURLComment}`; | 
					
						
							|  |  |  | 									} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-31 03:47:17 +08:00
										 |  |  | 									const sourceMapString = JSON.stringify(sourceMap); | 
					
						
							|  |  |  | 									if (sourceMapFilename) { | 
					
						
							| 
									
										
										
										
											2024-07-31 04:09:42 +08:00
										 |  |  | 										const filename = file; | 
					
						
							| 
									
										
										
										
											2020-08-19 03:14:43 +08:00
										 |  |  | 										const sourceMapContentHash = | 
					
						
							| 
									
										
										
										
											2024-08-09 01:03:17 +08:00
										 |  |  | 											/** @type {string} */ | 
					
						
							|  |  |  | 											( | 
					
						
							|  |  |  | 												usesContentHash && | 
					
						
							|  |  |  | 													createHash( | 
					
						
							|  |  |  | 														/** @type {Algorithm} */ | 
					
						
							|  |  |  | 														(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}` | 
					
						
							| 
									
										
										
										
											2024-07-31 05:43:19 +08:00
										 |  |  | 													) | 
					
						
							| 
									
										
										
										
											2019-10-31 03:47:17 +08:00
										 |  |  | 												: 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}` | 
					
						
							| 
									
										
										
										
											2024-07-31 05:43:19 +08:00
										 |  |  | 												); | 
					
						
							| 
									
										
										
										
											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, | 
					
						
							| 
									
										
										
										
											2024-07-31 09:37:24 +08:00
										 |  |  | 												compilation.getPath(currentSourceMappingURLComment, { | 
					
						
							|  |  |  | 													url: sourceMapUrl, | 
					
						
							|  |  |  | 													...pathParams | 
					
						
							|  |  |  | 												}) | 
					
						
							| 
									
										
										
										
											2019-10-31 03:47:17 +08:00
										 |  |  | 											); | 
					
						
							|  |  |  | 										} | 
					
						
							| 
									
										
										
										
											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" | 
					
						
							|  |  |  | 											); | 
					
						
							|  |  |  | 										} | 
					
						
							| 
									
										
										
										
											2023-05-24 13:39:36 +08:00
										 |  |  | 										if (typeof currentSourceMappingURLComment === "function") { | 
					
						
							|  |  |  | 											throw new Error( | 
					
						
							|  |  |  | 												"SourceMapDevToolPlugin: append can't be a function when no filename is provided" | 
					
						
							|  |  |  | 											); | 
					
						
							|  |  |  | 										} | 
					
						
							| 
									
										
										
										
											2019-10-31 03:47:17 +08:00
										 |  |  | 										/** | 
					
						
							|  |  |  | 										 * Add source map as data url to asset | 
					
						
							|  |  |  | 										 */ | 
					
						
							|  |  |  | 										const asset = new ConcatSource( | 
					
						
							|  |  |  | 											new RawSource(source), | 
					
						
							|  |  |  | 											currentSourceMappingURLComment | 
					
						
							| 
									
										
										
										
											2022-04-27 00:34:51 +08:00
										 |  |  | 												.replace(MAP_URL_COMMENT_REGEXP, () => sourceMapString) | 
					
						
							| 
									
										
										
										
											2019-10-31 03:47:17 +08:00
										 |  |  | 												.replace( | 
					
						
							| 
									
										
										
										
											2022-04-27 00:34:51 +08:00
										 |  |  | 													URL_COMMENT_REGEXP, | 
					
						
							| 
									
										
										
										
											2019-10-31 03:47:17 +08:00
										 |  |  | 													() => | 
					
						
							|  |  |  | 														`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 => { | 
					
						
							| 
									
										
										
										
											2024-07-31 16:17:46 +08:00
										 |  |  | 									reportProgress(1); | 
					
						
							| 
									
										
										
										
											2019-10-31 03:47:17 +08:00
										 |  |  | 									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; |