[79a0317] | 1 | /*
|
---|
| 2 | MIT License http://www.opensource.org/licenses/mit-license.php
|
---|
| 3 | */
|
---|
| 4 |
|
---|
| 5 | "use strict";
|
---|
| 6 |
|
---|
| 7 | const RuntimeGlobals = require("../RuntimeGlobals");
|
---|
| 8 | const RuntimeModule = require("../RuntimeModule");
|
---|
| 9 | const Template = require("../Template");
|
---|
| 10 |
|
---|
| 11 | /** @typedef {import("../Chunk")} Chunk */
|
---|
| 12 | /** @typedef {import("../Compilation")} Compilation */
|
---|
| 13 |
|
---|
| 14 | class GetMainFilenameRuntimeModule extends RuntimeModule {
|
---|
| 15 | /**
|
---|
| 16 | * @param {string} name readable name
|
---|
| 17 | * @param {string} global global object binding
|
---|
| 18 | * @param {string} filename main file name
|
---|
| 19 | */
|
---|
| 20 | constructor(name, global, filename) {
|
---|
| 21 | super(`get ${name} filename`);
|
---|
| 22 | this.global = global;
|
---|
| 23 | this.filename = filename;
|
---|
| 24 | }
|
---|
| 25 |
|
---|
| 26 | /**
|
---|
| 27 | * @returns {string | null} runtime code
|
---|
| 28 | */
|
---|
| 29 | generate() {
|
---|
| 30 | const { global, filename } = this;
|
---|
| 31 | const compilation = /** @type {Compilation} */ (this.compilation);
|
---|
| 32 | const chunk = /** @type {Chunk} */ (this.chunk);
|
---|
| 33 | const { runtimeTemplate } = compilation;
|
---|
| 34 | const url = compilation.getPath(JSON.stringify(filename), {
|
---|
| 35 | hash: `" + ${RuntimeGlobals.getFullHash}() + "`,
|
---|
| 36 | hashWithLength: length =>
|
---|
| 37 | `" + ${RuntimeGlobals.getFullHash}().slice(0, ${length}) + "`,
|
---|
| 38 | chunk,
|
---|
| 39 | runtime: chunk.runtime
|
---|
| 40 | });
|
---|
| 41 | return Template.asString([
|
---|
| 42 | `${global} = ${runtimeTemplate.returningFunction(url)};`
|
---|
| 43 | ]);
|
---|
| 44 | }
|
---|
| 45 | }
|
---|
| 46 |
|
---|
| 47 | module.exports = GetMainFilenameRuntimeModule;
|
---|