| 
									
										
										
										
											2021-11-30 18:57:32 +08:00
										 |  |  | /* | 
					
						
							|  |  |  | 	MIT License http://www.opensource.org/licenses/mit-license.php
 | 
					
						
							|  |  |  | 	Author Ivan Kopeykin @vankop | 
					
						
							|  |  |  | */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | "use strict"; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | const makeSerializable = require("../util/makeSerializable"); | 
					
						
							|  |  |  | const CachedConstDependency = require("./CachedConstDependency"); | 
					
						
							| 
									
										
										
										
											2022-04-05 15:56:31 +08:00
										 |  |  | const ExternalModuleInitFragment = require("./ExternalModuleInitFragment"); | 
					
						
							| 
									
										
										
										
											2021-11-30 18:57:32 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | /** @typedef {import("webpack-sources").ReplaceSource} ReplaceSource */ | 
					
						
							|  |  |  | /** @typedef {import("../Dependency")} Dependency */ | 
					
						
							| 
									
										
										
										
											2022-04-05 14:26:24 +08:00
										 |  |  | /** @typedef {import("../Dependency").UpdateHashContext} UpdateHashContext */ | 
					
						
							| 
									
										
										
										
											2021-11-30 18:57:32 +08:00
										 |  |  | /** @typedef {import("../DependencyTemplate").DependencyTemplateContext} DependencyTemplateContext */ | 
					
						
							|  |  |  | /** @typedef {import("../javascript/JavascriptModulesPlugin").ChunkRenderContext} ChunkRenderContext */ | 
					
						
							| 
									
										
										
										
											2024-01-26 22:47:14 +08:00
										 |  |  | /** @typedef {import("../javascript/JavascriptParser").Range} Range */ | 
					
						
							| 
									
										
										
										
											2024-01-09 07:50:36 +08:00
										 |  |  | /** @typedef {import("../serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */ | 
					
						
							|  |  |  | /** @typedef {import("../serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */ | 
					
						
							| 
									
										
										
										
											2022-04-05 14:26:24 +08:00
										 |  |  | /** @typedef {import("../util/Hash")} Hash */ | 
					
						
							| 
									
										
										
										
											2021-11-30 18:57:32 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | class ExternalModuleDependency extends CachedConstDependency { | 
					
						
							| 
									
										
										
										
											2024-01-26 22:47:14 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {string} module module | 
					
						
							|  |  |  | 	 * @param {{ name: string, value: string }[]} importSpecifiers import specifiers | 
					
						
							|  |  |  | 	 * @param {string | undefined} defaultImport default import | 
					
						
							|  |  |  | 	 * @param {string} expression expression | 
					
						
							|  |  |  | 	 * @param {Range} range range | 
					
						
							|  |  |  | 	 * @param {string} identifier identifier | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2022-04-05 15:56:31 +08:00
										 |  |  | 	constructor( | 
					
						
							|  |  |  | 		module, | 
					
						
							|  |  |  | 		importSpecifiers, | 
					
						
							|  |  |  | 		defaultImport, | 
					
						
							|  |  |  | 		expression, | 
					
						
							|  |  |  | 		range, | 
					
						
							|  |  |  | 		identifier | 
					
						
							|  |  |  | 	) { | 
					
						
							| 
									
										
										
										
											2021-11-30 18:57:32 +08:00
										 |  |  | 		super(expression, range, identifier); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		this.importedModule = module; | 
					
						
							| 
									
										
										
										
											2022-04-05 15:56:31 +08:00
										 |  |  | 		this.specifiers = importSpecifiers; | 
					
						
							|  |  |  | 		this.default = defaultImport; | 
					
						
							| 
									
										
										
										
											2021-11-30 18:57:32 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/** | 
					
						
							| 
									
										
										
										
											2022-04-05 15:56:31 +08:00
										 |  |  | 	 * @returns {string} hash update | 
					
						
							| 
									
										
										
										
											2021-11-30 18:57:32 +08:00
										 |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2022-04-05 15:56:31 +08:00
										 |  |  | 	_createHashUpdate() { | 
					
						
							|  |  |  | 		return `${this.importedModule}${JSON.stringify(this.specifiers)}${ | 
					
						
							|  |  |  | 			this.default || "null" | 
					
						
							|  |  |  | 		}${super._createHashUpdate()}`;
 | 
					
						
							| 
									
										
										
										
											2021-11-30 18:57:32 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-01-09 07:50:36 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {ObjectSerializerContext} context context | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2021-11-30 18:57:32 +08:00
										 |  |  | 	serialize(context) { | 
					
						
							|  |  |  | 		super.serialize(context); | 
					
						
							|  |  |  | 		const { write } = context; | 
					
						
							|  |  |  | 		write(this.importedModule); | 
					
						
							| 
									
										
										
										
											2022-04-05 15:56:31 +08:00
										 |  |  | 		write(this.specifiers); | 
					
						
							|  |  |  | 		write(this.default); | 
					
						
							| 
									
										
										
										
											2021-11-30 18:57:32 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-01-09 07:50:36 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {ObjectDeserializerContext} context context | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2021-11-30 18:57:32 +08:00
										 |  |  | 	deserialize(context) { | 
					
						
							|  |  |  | 		super.deserialize(context); | 
					
						
							|  |  |  | 		const { read } = context; | 
					
						
							|  |  |  | 		this.importedModule = read(); | 
					
						
							| 
									
										
										
										
											2022-04-05 15:56:31 +08:00
										 |  |  | 		this.specifiers = read(); | 
					
						
							|  |  |  | 		this.default = read(); | 
					
						
							| 
									
										
										
										
											2021-11-30 18:57:32 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | makeSerializable( | 
					
						
							|  |  |  | 	ExternalModuleDependency, | 
					
						
							|  |  |  | 	"webpack/lib/dependencies/ExternalModuleDependency" | 
					
						
							|  |  |  | ); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ExternalModuleDependency.Template = class ExternalModuleDependencyTemplate extends ( | 
					
						
							|  |  |  | 	CachedConstDependency.Template | 
					
						
							|  |  |  | ) { | 
					
						
							|  |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {Dependency} dependency the dependency for which the template should be applied | 
					
						
							|  |  |  | 	 * @param {ReplaceSource} source the current replace source which can be modified | 
					
						
							|  |  |  | 	 * @param {DependencyTemplateContext} templateContext the context object | 
					
						
							|  |  |  | 	 * @returns {void} | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	apply(dependency, source, templateContext) { | 
					
						
							|  |  |  | 		super.apply(dependency, source, templateContext); | 
					
						
							|  |  |  | 		const dep = /** @type {ExternalModuleDependency} */ (dependency); | 
					
						
							| 
									
										
										
										
											2024-04-12 20:08:08 +08:00
										 |  |  | 		const { chunkInitFragments, runtimeTemplate } = templateContext; | 
					
						
							| 
									
										
										
										
											2021-11-30 18:57:32 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		chunkInitFragments.push( | 
					
						
							| 
									
										
										
										
											2022-04-05 15:56:31 +08:00
										 |  |  | 			new ExternalModuleInitFragment( | 
					
						
							| 
									
										
										
										
											2024-04-12 20:08:08 +08:00
										 |  |  | 				`${runtimeTemplate.supportNodePrefixForCoreModules() ? "node:" : ""}${ | 
					
						
							|  |  |  | 					dep.importedModule | 
					
						
							|  |  |  | 				}`,
 | 
					
						
							| 
									
										
										
										
											2022-04-05 15:56:31 +08:00
										 |  |  | 				dep.specifiers, | 
					
						
							|  |  |  | 				dep.default | 
					
						
							| 
									
										
										
										
											2021-11-30 18:57:32 +08:00
										 |  |  | 			) | 
					
						
							|  |  |  | 		); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | module.exports = ExternalModuleDependency; |