| 
									
										
										
										
											2014-02-13 18:40:16 +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-01-13 11:32:24 +08:00
										 |  |  | "use strict"; | 
					
						
							| 
									
										
										
										
											2014-02-13 18:40:16 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-12-16 23:19:39 +08:00
										 |  |  | const { ConcatSource, RawSource } = require("webpack-sources"); | 
					
						
							| 
									
										
										
										
											2019-10-02 17:19:44 +08:00
										 |  |  | const ModuleFilenameHelpers = require("./ModuleFilenameHelpers"); | 
					
						
							|  |  |  | const NormalModule = require("./NormalModule"); | 
					
						
							| 
									
										
										
										
											2021-09-08 19:09:01 +08:00
										 |  |  | const RuntimeGlobals = require("./RuntimeGlobals"); | 
					
						
							| 
									
										
										
										
											2017-01-13 11:32:24 +08:00
										 |  |  | const SourceMapDevToolModuleOptionsPlugin = require("./SourceMapDevToolModuleOptionsPlugin"); | 
					
						
							| 
									
										
										
										
											2019-10-11 21:46:57 +08:00
										 |  |  | const JavascriptModulesPlugin = require("./javascript/JavascriptModulesPlugin"); | 
					
						
							| 
									
										
										
										
											2019-11-11 22:25:03 +08:00
										 |  |  | const ConcatenatedModule = require("./optimize/ConcatenatedModule"); | 
					
						
							| 
									
										
										
										
											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-01-13 11:32:24 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-06-03 01:18:59 +08:00
										 |  |  | /** @typedef {import("webpack-sources").RawSourceMap} RawSourceMap */ | 
					
						
							| 
									
										
										
										
											2019-10-02 17:19:44 +08:00
										 |  |  | /** @typedef {import("webpack-sources").Source} Source */ | 
					
						
							| 
									
										
										
										
											2020-08-03 02:09:36 +08:00
										 |  |  | /** @typedef {import("../declarations/WebpackOptions").DevTool} DevToolOptions */ | 
					
						
							|  |  |  | /** @typedef {import("../declarations/plugins/SourceMapDevToolPlugin").SourceMapDevToolPluginOptions} SourceMapDevToolPluginOptions */ | 
					
						
							| 
									
										
										
										
											2024-08-06 11:08:48 +08:00
										 |  |  | /** @typedef {import("./ChunkGraph").ModuleId} ModuleId */ | 
					
						
							| 
									
										
										
										
											2018-07-06 17:19:30 +08:00
										 |  |  | /** @typedef {import("./Compiler")} Compiler */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-02 17:19:44 +08:00
										 |  |  | /** @type {WeakMap<Source, Source>} */ | 
					
						
							|  |  |  | const cache = new WeakMap(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-12-18 21:47:24 +08:00
										 |  |  | const devtoolWarning = new RawSource(`/*
 | 
					
						
							|  |  |  |  * ATTENTION: An "eval-source-map" devtool has been used. | 
					
						
							| 
									
										
										
										
											2021-01-01 14:07:17 +08:00
										 |  |  |  * This devtool is neither made for production nor for readable output files. | 
					
						
							| 
									
										
										
										
											2019-12-18 21:47:24 +08:00
										 |  |  |  * It uses "eval()" calls to create a separate source file with attached SourceMaps in the browser devtools. | 
					
						
							|  |  |  |  * If you are trying to read the output file, select a different devtool (https://webpack.js.org/configuration/devtool/)
 | 
					
						
							|  |  |  |  * or disable the default devtool with "devtool: false". | 
					
						
							|  |  |  |  * If you are looking for production-ready output files, see mode: "production" (https://webpack.js.org/configuration/mode/).
 | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | `);
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-04-23 20:03:37 +08:00
										 |  |  | const PLUGIN_NAME = "EvalSourceMapDevToolPlugin"; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-13 11:32:24 +08:00
										 |  |  | class EvalSourceMapDevToolPlugin { | 
					
						
							| 
									
										
										
										
											2018-07-06 17:19:30 +08:00
										 |  |  | 	/** | 
					
						
							| 
									
										
										
										
											2025-04-26 01:43:01 +08:00
										 |  |  | 	 * @param {SourceMapDevToolPluginOptions | string} inputOptions Options object | 
					
						
							| 
									
										
										
										
											2018-07-06 17:19:30 +08:00
										 |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2020-08-03 02:09:36 +08:00
										 |  |  | 	constructor(inputOptions) { | 
					
						
							|  |  |  | 		/** @type {SourceMapDevToolPluginOptions} */ | 
					
						
							|  |  |  | 		let options; | 
					
						
							|  |  |  | 		if (typeof inputOptions === "string") { | 
					
						
							| 
									
										
										
										
											2017-01-13 11:32:24 +08:00
										 |  |  | 			options = { | 
					
						
							| 
									
										
										
										
											2020-08-03 02:09:36 +08:00
										 |  |  | 				append: inputOptions | 
					
						
							| 
									
										
										
										
											2017-01-13 11:32:24 +08:00
										 |  |  | 			}; | 
					
						
							| 
									
										
										
										
											2020-08-03 02:09:36 +08:00
										 |  |  | 		} else { | 
					
						
							|  |  |  | 			options = inputOptions; | 
					
						
							| 
									
										
										
										
											2017-01-13 11:32:24 +08:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2019-10-02 17:19:44 +08:00
										 |  |  | 		this.sourceMapComment = | 
					
						
							| 
									
										
										
										
											2023-05-24 13:39:36 +08:00
										 |  |  | 			options.append && typeof options.append !== "function" | 
					
						
							|  |  |  | 				? options.append | 
					
						
							|  |  |  | 				: "//# sourceURL=[module]\n//# sourceMappingURL=[url]"; | 
					
						
							| 
									
										
										
										
											2019-10-02 17:19:44 +08:00
										 |  |  | 		this.moduleFilenameTemplate = | 
					
						
							|  |  |  | 			options.moduleFilenameTemplate || | 
					
						
							|  |  |  | 			"webpack://[namespace]/[resource-path]?[hash]"; | 
					
						
							|  |  |  | 		this.namespace = options.namespace || ""; | 
					
						
							| 
									
										
										
										
											2017-01-13 11:32:24 +08:00
										 |  |  | 		this.options = options; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-06 17:19:30 +08:00
										 |  |  | 	/** | 
					
						
							| 
									
										
										
										
											2020-04-23 16:48:36 +08:00
										 |  |  | 	 * Apply the plugin | 
					
						
							| 
									
										
										
										
											2018-11-03 04:05:46 +08:00
										 |  |  | 	 * @param {Compiler} compiler the compiler instance | 
					
						
							| 
									
										
										
										
											2018-07-06 17:19:30 +08:00
										 |  |  | 	 * @returns {void} | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2017-01-13 11:32:24 +08:00
										 |  |  | 	apply(compiler) { | 
					
						
							| 
									
										
										
										
											2017-02-05 07:23:50 +08:00
										 |  |  | 		const options = this.options; | 
					
						
							| 
									
										
										
										
											2025-04-23 20:03:37 +08:00
										 |  |  | 		compiler.hooks.compilation.tap(PLUGIN_NAME, compilation => { | 
					
						
							|  |  |  | 			const hooks = JavascriptModulesPlugin.getCompilationHooks(compilation); | 
					
						
							|  |  |  | 			new SourceMapDevToolModuleOptionsPlugin(options).apply(compilation); | 
					
						
							|  |  |  | 			const matchModule = ModuleFilenameHelpers.matchObject.bind( | 
					
						
							|  |  |  | 				ModuleFilenameHelpers, | 
					
						
							|  |  |  | 				options | 
					
						
							|  |  |  | 			); | 
					
						
							|  |  |  | 			hooks.renderModuleContent.tap( | 
					
						
							|  |  |  | 				PLUGIN_NAME, | 
					
						
							|  |  |  | 				(source, m, { chunk, runtimeTemplate, chunkGraph }) => { | 
					
						
							|  |  |  | 					const cachedSource = cache.get(source); | 
					
						
							|  |  |  | 					if (cachedSource !== undefined) { | 
					
						
							|  |  |  | 						return cachedSource; | 
					
						
							|  |  |  | 					} | 
					
						
							| 
									
										
										
										
											2019-10-02 17:19:44 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-04-23 20:03:37 +08:00
										 |  |  | 					/** | 
					
						
							|  |  |  | 					 * @param {Source} r result | 
					
						
							|  |  |  | 					 * @returns {Source} result | 
					
						
							|  |  |  | 					 */ | 
					
						
							|  |  |  | 					const result = r => { | 
					
						
							|  |  |  | 						cache.set(source, r); | 
					
						
							|  |  |  | 						return r; | 
					
						
							|  |  |  | 					}; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 					if (m instanceof NormalModule) { | 
					
						
							|  |  |  | 						const module = /** @type {NormalModule} */ (m); | 
					
						
							|  |  |  | 						if (!matchModule(module.resource)) { | 
					
						
							|  |  |  | 							return result(source); | 
					
						
							|  |  |  | 						} | 
					
						
							|  |  |  | 					} else if (m instanceof ConcatenatedModule) { | 
					
						
							|  |  |  | 						const concatModule = /** @type {ConcatenatedModule} */ (m); | 
					
						
							|  |  |  | 						if (concatModule.rootModule instanceof NormalModule) { | 
					
						
							|  |  |  | 							const module = /** @type {NormalModule} */ ( | 
					
						
							|  |  |  | 								concatModule.rootModule | 
					
						
							|  |  |  | 							); | 
					
						
							| 
									
										
										
										
											2019-11-11 22:25:03 +08:00
										 |  |  | 							if (!matchModule(module.resource)) { | 
					
						
							| 
									
										
										
										
											2021-01-04 22:35:30 +08:00
										 |  |  | 								return result(source); | 
					
						
							| 
									
										
										
										
											2019-11-11 22:25:03 +08:00
										 |  |  | 							} | 
					
						
							|  |  |  | 						} else { | 
					
						
							| 
									
										
										
										
											2021-01-04 22:35:30 +08:00
										 |  |  | 							return result(source); | 
					
						
							| 
									
										
										
										
											2019-10-02 17:19:44 +08:00
										 |  |  | 						} | 
					
						
							| 
									
										
										
										
											2025-04-23 20:03:37 +08:00
										 |  |  | 					} else { | 
					
						
							|  |  |  | 						return result(source); | 
					
						
							|  |  |  | 					} | 
					
						
							| 
									
										
										
										
											2019-10-02 17:19:44 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-04-23 20:03:37 +08:00
										 |  |  | 					const namespace = compilation.getPath(this.namespace, { | 
					
						
							|  |  |  | 						chunk | 
					
						
							|  |  |  | 					}); | 
					
						
							| 
									
										
										
										
											2025-06-03 01:18:59 +08:00
										 |  |  | 					/** @type {RawSourceMap} */ | 
					
						
							| 
									
										
										
										
											2025-04-23 20:03:37 +08:00
										 |  |  | 					let sourceMap; | 
					
						
							|  |  |  | 					let content; | 
					
						
							|  |  |  | 					if (source.sourceAndMap) { | 
					
						
							|  |  |  | 						const sourceAndMap = source.sourceAndMap(options); | 
					
						
							| 
									
										
										
										
											2025-06-03 01:18:59 +08:00
										 |  |  | 						sourceMap = /** @type {RawSourceMap} */ (sourceAndMap.map); | 
					
						
							| 
									
										
										
										
											2025-04-23 20:03:37 +08:00
										 |  |  | 						content = sourceAndMap.source; | 
					
						
							|  |  |  | 					} else { | 
					
						
							| 
									
										
										
										
											2025-06-03 01:18:59 +08:00
										 |  |  | 						sourceMap = /** @type {RawSourceMap} */ (source.map(options)); | 
					
						
							| 
									
										
										
										
											2025-04-23 20:03:37 +08:00
										 |  |  | 						content = source.source(); | 
					
						
							|  |  |  | 					} | 
					
						
							|  |  |  | 					if (!sourceMap) { | 
					
						
							|  |  |  | 						return result(source); | 
					
						
							|  |  |  | 					} | 
					
						
							| 
									
										
										
										
											2019-10-02 17:19:44 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-04-23 20:03:37 +08:00
										 |  |  | 					// Clone (flat) the sourcemap to ensure that the mutations below do not persist.
 | 
					
						
							|  |  |  | 					sourceMap = { ...sourceMap }; | 
					
						
							|  |  |  | 					const context = /** @type {string} */ (compiler.options.context); | 
					
						
							|  |  |  | 					const root = compiler.root; | 
					
						
							|  |  |  | 					const modules = sourceMap.sources.map(source => { | 
					
						
							|  |  |  | 						if (!source.startsWith("webpack://")) return source; | 
					
						
							|  |  |  | 						source = makePathsAbsolute(context, source.slice(10), root); | 
					
						
							|  |  |  | 						const module = compilation.findModule(source); | 
					
						
							|  |  |  | 						return module || source; | 
					
						
							|  |  |  | 					}); | 
					
						
							|  |  |  | 					let moduleFilenames = modules.map(module => | 
					
						
							|  |  |  | 						ModuleFilenameHelpers.createFilename( | 
					
						
							|  |  |  | 							module, | 
					
						
							|  |  |  | 							{ | 
					
						
							|  |  |  | 								moduleFilenameTemplate: this.moduleFilenameTemplate, | 
					
						
							|  |  |  | 								namespace | 
					
						
							|  |  |  | 							}, | 
					
						
							|  |  |  | 							{ | 
					
						
							|  |  |  | 								requestShortener: runtimeTemplate.requestShortener, | 
					
						
							|  |  |  | 								chunkGraph, | 
					
						
							|  |  |  | 								hashFunction: compilation.outputOptions.hashFunction | 
					
						
							| 
									
										
										
										
											2019-10-02 17:19:44 +08:00
										 |  |  | 							} | 
					
						
							| 
									
										
										
										
											2025-04-23 20:03:37 +08:00
										 |  |  | 						) | 
					
						
							|  |  |  | 					); | 
					
						
							|  |  |  | 					moduleFilenames = ModuleFilenameHelpers.replaceDuplicates( | 
					
						
							|  |  |  | 						moduleFilenames, | 
					
						
							|  |  |  | 						(filename, i, n) => { | 
					
						
							|  |  |  | 							for (let j = 0; j < n; j++) filename += "*"; | 
					
						
							|  |  |  | 							return filename; | 
					
						
							| 
									
										
										
										
											2024-11-21 21:03:36 +08:00
										 |  |  | 						} | 
					
						
							| 
									
										
										
										
											2025-04-23 20:03:37 +08:00
										 |  |  | 					); | 
					
						
							|  |  |  | 					sourceMap.sources = moduleFilenames; | 
					
						
							|  |  |  | 					if (options.noSources) { | 
					
						
							|  |  |  | 						sourceMap.sourcesContent = undefined; | 
					
						
							|  |  |  | 					} | 
					
						
							|  |  |  | 					sourceMap.sourceRoot = options.sourceRoot || ""; | 
					
						
							|  |  |  | 					const moduleId = | 
					
						
							|  |  |  | 						/** @type {ModuleId} */ | 
					
						
							|  |  |  | 						(chunkGraph.getModuleId(m)); | 
					
						
							|  |  |  | 					sourceMap.file = | 
					
						
							|  |  |  | 						typeof moduleId === "number" ? `${moduleId}.js` : moduleId; | 
					
						
							| 
									
										
										
										
											2024-11-21 21:03:36 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-04-23 20:03:37 +08:00
										 |  |  | 					if (options.debugIds) { | 
					
						
							|  |  |  | 						sourceMap.debugId = generateDebugId(content, sourceMap.file); | 
					
						
							| 
									
										
										
										
											2019-10-02 17:19:44 +08:00
										 |  |  | 					} | 
					
						
							| 
									
										
										
										
											2025-04-23 20:03:37 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 					const footer = `${this.sourceMapComment.replace( | 
					
						
							|  |  |  | 						/\[url\]/g, | 
					
						
							|  |  |  | 						`data:application/json;charset=utf-8;base64,${Buffer.from( | 
					
						
							|  |  |  | 							JSON.stringify(sourceMap), | 
					
						
							|  |  |  | 							"utf8" | 
					
						
							|  |  |  | 						).toString("base64")}`
 | 
					
						
							|  |  |  | 					)}\n//# sourceURL=webpack-internal:///${moduleId}\n`; // workaround for chrome bug
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 					return result( | 
					
						
							|  |  |  | 						new RawSource( | 
					
						
							|  |  |  | 							`eval(${ | 
					
						
							|  |  |  | 								compilation.outputOptions.trustedTypes | 
					
						
							|  |  |  | 									? `${RuntimeGlobals.createScript}(${JSON.stringify( | 
					
						
							|  |  |  | 											content + footer | 
					
						
							|  |  |  | 										)})`
 | 
					
						
							|  |  |  | 									: JSON.stringify(content + footer) | 
					
						
							|  |  |  | 							});`
 | 
					
						
							|  |  |  | 						) | 
					
						
							| 
									
										
										
										
											2021-09-07 18:40:07 +08:00
										 |  |  | 					); | 
					
						
							|  |  |  | 				} | 
					
						
							| 
									
										
										
										
											2025-04-23 20:03:37 +08:00
										 |  |  | 			); | 
					
						
							|  |  |  | 			hooks.inlineInRuntimeBailout.tap( | 
					
						
							| 
									
										
										
										
											2025-06-04 02:20:37 +08:00
										 |  |  | 				PLUGIN_NAME, | 
					
						
							| 
									
										
										
										
											2025-04-23 20:03:37 +08:00
										 |  |  | 				() => "the eval-source-map devtool is used." | 
					
						
							|  |  |  | 			); | 
					
						
							|  |  |  | 			hooks.render.tap( | 
					
						
							|  |  |  | 				PLUGIN_NAME, | 
					
						
							|  |  |  | 				source => new ConcatSource(devtoolWarning, source) | 
					
						
							|  |  |  | 			); | 
					
						
							|  |  |  | 			hooks.chunkHash.tap(PLUGIN_NAME, (chunk, hash) => { | 
					
						
							|  |  |  | 				hash.update(PLUGIN_NAME); | 
					
						
							|  |  |  | 				hash.update("2"); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 			if (compilation.outputOptions.trustedTypes) { | 
					
						
							|  |  |  | 				compilation.hooks.additionalModuleRuntimeRequirements.tap( | 
					
						
							|  |  |  | 					PLUGIN_NAME, | 
					
						
							|  |  |  | 					(module, set, context) => { | 
					
						
							|  |  |  | 						set.add(RuntimeGlobals.createScript); | 
					
						
							|  |  |  | 					} | 
					
						
							|  |  |  | 				); | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2025-04-23 20:03:37 +08:00
										 |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2015-04-05 07:52:30 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2014-02-13 18:40:16 +08:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2017-01-13 11:32:24 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-13 18:40:16 +08:00
										 |  |  | module.exports = EvalSourceMapDevToolPlugin; |