| 
									
										
										
										
											2018-11-28 20:07:40 +08:00
										 |  |  | /* | 
					
						
							|  |  |  | 	MIT License http://www.opensource.org/licenses/mit-license.php
 | 
					
						
							|  |  |  | */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | "use strict"; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | const RuntimeGlobals = require("../RuntimeGlobals"); | 
					
						
							|  |  |  | const RuntimeModule = require("../RuntimeModule"); | 
					
						
							|  |  |  | const Template = require("../Template"); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-18 05:05:08 +08:00
										 |  |  | /** @typedef {import("../Compilation")} Compilation */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-28 20:07:40 +08:00
										 |  |  | class GetMainFilenameRuntimeModule extends RuntimeModule { | 
					
						
							| 
									
										
										
										
											2018-12-18 05:05:08 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {string} name readable name | 
					
						
							|  |  |  | 	 * @param {string} global global object binding | 
					
						
							|  |  |  | 	 * @param {string} filename main file name | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2019-08-27 02:21:07 +08:00
										 |  |  | 	constructor(name, global, filename) { | 
					
						
							| 
									
										
										
										
											2018-11-28 20:07:40 +08:00
										 |  |  | 		super(`get ${name} filename`); | 
					
						
							|  |  |  | 		this.global = global; | 
					
						
							|  |  |  | 		this.filename = filename; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/** | 
					
						
							|  |  |  | 	 * @returns {string} runtime code | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	generate() { | 
					
						
							| 
									
										
										
										
											2020-11-28 19:42:03 +08:00
										 |  |  | 		const { global, filename, compilation, chunk } = this; | 
					
						
							| 
									
										
										
										
											2019-08-27 02:21:07 +08:00
										 |  |  | 		const { runtimeTemplate } = compilation; | 
					
						
							| 
									
										
										
										
											2019-10-04 18:24:52 +08:00
										 |  |  | 		const url = compilation.getPath(JSON.stringify(filename), { | 
					
						
							| 
									
										
										
										
											2018-11-28 20:07:40 +08:00
										 |  |  | 			hash: `" + ${RuntimeGlobals.getFullHash}() + "`, | 
					
						
							|  |  |  | 			hashWithLength: length => | 
					
						
							| 
									
										
										
										
											2020-11-28 19:42:03 +08:00
										 |  |  | 				`" + ${RuntimeGlobals.getFullHash}().slice(0, ${length}) + "`, | 
					
						
							|  |  |  | 			chunk, | 
					
						
							|  |  |  | 			runtime: chunk.runtime | 
					
						
							| 
									
										
										
										
											2018-11-28 20:07:40 +08:00
										 |  |  | 		}); | 
					
						
							|  |  |  | 		return Template.asString([ | 
					
						
							| 
									
										
										
										
											2019-08-27 02:21:07 +08:00
										 |  |  | 			`${global} = ${runtimeTemplate.returningFunction(url)};` | 
					
						
							| 
									
										
										
										
											2018-11-28 20:07:40 +08:00
										 |  |  | 		]); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | module.exports = GetMainFilenameRuntimeModule; |