| 
									
										
										
										
											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"); | 
					
						
							| 
									
										
										
										
											2021-08-19 20:01:44 +08:00
										 |  |  | const { makePathsAbsolute } = require("./util/identifier"); | 
					
						
							| 
									
										
										
										
											2017-01-13 11:32:24 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											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 */ | 
					
						
							| 
									
										
										
										
											2018-07-06 17:19:30 +08:00
										 |  |  | /** @typedef {import("./Compiler")} Compiler */ | 
					
						
							| 
									
										
										
										
											2022-08-29 15:09:23 +08:00
										 |  |  | /** @typedef {import("./NormalModule").SourceMap} SourceMap */ | 
					
						
							| 
									
										
										
										
											2018-07-06 17:19:30 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											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/).
 | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | `);
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-13 11:32:24 +08:00
										 |  |  | class EvalSourceMapDevToolPlugin { | 
					
						
							| 
									
										
										
										
											2018-07-06 17:19:30 +08:00
										 |  |  | 	/** | 
					
						
							| 
									
										
										
										
											2020-08-03 02:09:36 +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; | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		compiler.hooks.compilation.tap( | 
					
						
							|  |  |  | 			"EvalSourceMapDevToolPlugin", | 
					
						
							|  |  |  | 			compilation => { | 
					
						
							| 
									
										
										
										
											2019-10-02 17:19:44 +08:00
										 |  |  | 				const hooks = JavascriptModulesPlugin.getCompilationHooks(compilation); | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 				new SourceMapDevToolModuleOptionsPlugin(options).apply(compilation); | 
					
						
							| 
									
										
										
										
											2019-10-02 17:19:44 +08:00
										 |  |  | 				const matchModule = ModuleFilenameHelpers.matchObject.bind( | 
					
						
							|  |  |  | 					ModuleFilenameHelpers, | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 					options | 
					
						
							| 
									
										
										
										
											2019-10-02 17:19:44 +08:00
										 |  |  | 				); | 
					
						
							|  |  |  | 				hooks.renderModuleContent.tap( | 
					
						
							|  |  |  | 					"EvalSourceMapDevToolPlugin", | 
					
						
							|  |  |  | 					(source, m, { runtimeTemplate, chunkGraph }) => { | 
					
						
							|  |  |  | 						const cachedSource = cache.get(source); | 
					
						
							|  |  |  | 						if (cachedSource !== undefined) { | 
					
						
							|  |  |  | 							return cachedSource; | 
					
						
							|  |  |  | 						} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-06-17 01:13:03 +08:00
										 |  |  | 						/** | 
					
						
							|  |  |  | 						 * @param {Source} r result | 
					
						
							|  |  |  | 						 * @returns {Source} result | 
					
						
							|  |  |  | 						 */ | 
					
						
							| 
									
										
										
										
											2021-01-04 22:35:30 +08:00
										 |  |  | 						const result = r => { | 
					
						
							|  |  |  | 							cache.set(source, r); | 
					
						
							|  |  |  | 							return r; | 
					
						
							|  |  |  | 						}; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-11 22:25:03 +08:00
										 |  |  | 						if (m instanceof NormalModule) { | 
					
						
							|  |  |  | 							const module = /** @type {NormalModule} */ (m); | 
					
						
							|  |  |  | 							if (!matchModule(module.resource)) { | 
					
						
							| 
									
										
										
										
											2021-01-04 22:35:30 +08:00
										 |  |  | 								return result(source); | 
					
						
							| 
									
										
										
										
											2019-11-11 22:25:03 +08:00
										 |  |  | 							} | 
					
						
							|  |  |  | 						} else if (m instanceof ConcatenatedModule) { | 
					
						
							|  |  |  | 							const concatModule = /** @type {ConcatenatedModule} */ (m); | 
					
						
							|  |  |  | 							if (concatModule.rootModule instanceof NormalModule) { | 
					
						
							| 
									
										
										
										
											2021-05-11 15:31:46 +08:00
										 |  |  | 								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-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
										 |  |  | 						} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-08-29 15:09:23 +08:00
										 |  |  | 						/** @type {SourceMap} */ | 
					
						
							| 
									
										
										
										
											2019-10-02 17:19:44 +08:00
										 |  |  | 						let sourceMap; | 
					
						
							|  |  |  | 						let content; | 
					
						
							|  |  |  | 						if (source.sourceAndMap) { | 
					
						
							|  |  |  | 							const sourceAndMap = source.sourceAndMap(options); | 
					
						
							| 
									
										
										
										
											2022-08-29 15:09:23 +08:00
										 |  |  | 							sourceMap = /** @type {SourceMap} */ (sourceAndMap.map); | 
					
						
							| 
									
										
										
										
											2019-10-02 17:19:44 +08:00
										 |  |  | 							content = sourceAndMap.source; | 
					
						
							|  |  |  | 						} else { | 
					
						
							| 
									
										
										
										
											2022-08-29 15:09:23 +08:00
										 |  |  | 							sourceMap = /** @type {SourceMap} */ (source.map(options)); | 
					
						
							| 
									
										
										
										
											2019-10-02 17:19:44 +08:00
										 |  |  | 							content = source.source(); | 
					
						
							|  |  |  | 						} | 
					
						
							|  |  |  | 						if (!sourceMap) { | 
					
						
							| 
									
										
										
										
											2021-01-04 22:35:30 +08:00
										 |  |  | 							return result(source); | 
					
						
							| 
									
										
										
										
											2019-10-02 17:19:44 +08:00
										 |  |  | 						} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 						// Clone (flat) the sourcemap to ensure that the mutations below do not persist.
 | 
					
						
							| 
									
										
										
										
											2020-01-18 04:19:37 +08:00
										 |  |  | 						sourceMap = { ...sourceMap }; | 
					
						
							| 
									
										
										
										
											2024-01-27 00:17:45 +08:00
										 |  |  | 						const context = /** @type {string} */ (compiler.options.context); | 
					
						
							| 
									
										
										
										
											2019-11-11 22:25:03 +08:00
										 |  |  | 						const root = compiler.root; | 
					
						
							| 
									
										
										
										
											2019-10-02 17:19:44 +08:00
										 |  |  | 						const modules = sourceMap.sources.map(source => { | 
					
						
							| 
									
										
										
										
											2019-11-11 22:25:03 +08:00
										 |  |  | 							if (!source.startsWith("webpack://")) return source; | 
					
						
							| 
									
										
										
										
											2021-08-19 20:01:44 +08:00
										 |  |  | 							source = makePathsAbsolute(context, source.slice(10), root); | 
					
						
							| 
									
										
										
										
											2019-10-02 17:19:44 +08:00
										 |  |  | 							const module = compilation.findModule(source); | 
					
						
							|  |  |  | 							return module || source; | 
					
						
							|  |  |  | 						}); | 
					
						
							|  |  |  | 						let moduleFilenames = modules.map(module => { | 
					
						
							|  |  |  | 							return ModuleFilenameHelpers.createFilename( | 
					
						
							|  |  |  | 								module, | 
					
						
							|  |  |  | 								{ | 
					
						
							|  |  |  | 									moduleFilenameTemplate: this.moduleFilenameTemplate, | 
					
						
							|  |  |  | 									namespace: this.namespace | 
					
						
							|  |  |  | 								}, | 
					
						
							|  |  |  | 								{ | 
					
						
							|  |  |  | 									requestShortener: runtimeTemplate.requestShortener, | 
					
						
							| 
									
										
										
										
											2021-09-22 18:12:46 +08:00
										 |  |  | 									chunkGraph, | 
					
						
							|  |  |  | 									hashFunction: compilation.outputOptions.hashFunction | 
					
						
							| 
									
										
										
										
											2019-10-02 17:19:44 +08:00
										 |  |  | 								} | 
					
						
							|  |  |  | 							); | 
					
						
							|  |  |  | 						}); | 
					
						
							|  |  |  | 						moduleFilenames = ModuleFilenameHelpers.replaceDuplicates( | 
					
						
							|  |  |  | 							moduleFilenames, | 
					
						
							|  |  |  | 							(filename, i, n) => { | 
					
						
							|  |  |  | 								for (let j = 0; j < n; j++) filename += "*"; | 
					
						
							|  |  |  | 								return filename; | 
					
						
							|  |  |  | 							} | 
					
						
							|  |  |  | 						); | 
					
						
							|  |  |  | 						sourceMap.sources = moduleFilenames; | 
					
						
							| 
									
										
										
										
											2022-10-07 01:00:44 +08:00
										 |  |  | 						if (options.noSources) { | 
					
						
							|  |  |  | 							sourceMap.sourcesContent = undefined; | 
					
						
							|  |  |  | 						} | 
					
						
							| 
									
										
										
										
											2019-10-02 17:19:44 +08:00
										 |  |  | 						sourceMap.sourceRoot = options.sourceRoot || ""; | 
					
						
							| 
									
										
										
										
											2019-11-11 22:25:03 +08:00
										 |  |  | 						const moduleId = chunkGraph.getModuleId(m); | 
					
						
							| 
									
										
										
										
											2023-06-06 07:00:12 +08:00
										 |  |  | 						sourceMap.file = | 
					
						
							|  |  |  | 							typeof moduleId === "number" ? `${moduleId}.js` : moduleId; | 
					
						
							| 
									
										
										
										
											2019-10-02 17:19:44 +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
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-04 22:35:30 +08:00
										 |  |  | 						return result( | 
					
						
							| 
									
										
										
										
											2021-09-07 18:40:07 +08:00
										 |  |  | 							new RawSource( | 
					
						
							|  |  |  | 								`eval(${ | 
					
						
							|  |  |  | 									compilation.outputOptions.trustedTypes | 
					
						
							|  |  |  | 										? `${RuntimeGlobals.createScript}(${JSON.stringify( | 
					
						
							|  |  |  | 												content + footer | 
					
						
							| 
									
										
										
										
											2024-01-14 09:41:34 +08:00
										 |  |  | 											)})`
 | 
					
						
							| 
									
										
										
										
											2021-09-07 18:40:07 +08:00
										 |  |  | 										: JSON.stringify(content + footer) | 
					
						
							|  |  |  | 								});`
 | 
					
						
							|  |  |  | 							) | 
					
						
							| 
									
										
										
										
											2019-10-02 17:19:44 +08:00
										 |  |  | 						); | 
					
						
							|  |  |  | 					} | 
					
						
							|  |  |  | 				); | 
					
						
							| 
									
										
										
										
											2021-02-11 02:14:50 +08:00
										 |  |  | 				hooks.inlineInRuntimeBailout.tap( | 
					
						
							|  |  |  | 					"EvalDevToolModulePlugin", | 
					
						
							|  |  |  | 					() => "the eval-source-map devtool is used." | 
					
						
							|  |  |  | 				); | 
					
						
							| 
									
										
										
										
											2019-12-16 23:19:39 +08:00
										 |  |  | 				hooks.render.tap( | 
					
						
							|  |  |  | 					"EvalSourceMapDevToolPlugin", | 
					
						
							|  |  |  | 					source => new ConcatSource(devtoolWarning, source) | 
					
						
							|  |  |  | 				); | 
					
						
							| 
									
										
										
										
											2019-10-02 17:19:44 +08:00
										 |  |  | 				hooks.chunkHash.tap("EvalSourceMapDevToolPlugin", (chunk, hash) => { | 
					
						
							|  |  |  | 					hash.update("EvalSourceMapDevToolPlugin"); | 
					
						
							| 
									
										
										
										
											2019-12-18 21:47:24 +08:00
										 |  |  | 					hash.update("2"); | 
					
						
							| 
									
										
										
										
											2019-10-02 17:19:44 +08:00
										 |  |  | 				}); | 
					
						
							| 
									
										
										
										
											2021-09-07 18:40:07 +08:00
										 |  |  | 				if (compilation.outputOptions.trustedTypes) { | 
					
						
							|  |  |  | 					compilation.hooks.additionalModuleRuntimeRequirements.tap( | 
					
						
							|  |  |  | 						"EvalSourceMapDevToolPlugin", | 
					
						
							|  |  |  | 						(module, set, context) => { | 
					
						
							|  |  |  | 							set.add(RuntimeGlobals.createScript); | 
					
						
							|  |  |  | 						} | 
					
						
							|  |  |  | 					); | 
					
						
							|  |  |  | 				} | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +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; |