| [9af201e] | 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 | /** @type {string} */
|
|---|
| 23 | this.global = global;
|
|---|
| 24 | /** @type {string} */
|
|---|
| 25 | this.filename = filename;
|
|---|
| 26 | }
|
|---|
| 27 |
|
|---|
| 28 | /**
|
|---|
| 29 | * Generates runtime code for this runtime module.
|
|---|
| 30 | * @returns {string | null} runtime code
|
|---|
| 31 | */
|
|---|
| 32 | generate() {
|
|---|
| 33 | const { global, filename } = this;
|
|---|
| 34 | const compilation = /** @type {Compilation} */ (this.compilation);
|
|---|
| 35 | const chunk = /** @type {Chunk} */ (this.chunk);
|
|---|
| 36 | const { runtimeTemplate } = compilation;
|
|---|
| 37 | const url = compilation.getPath(JSON.stringify(filename), {
|
|---|
| 38 | hash: `" + ${RuntimeGlobals.getFullHash}() + "`,
|
|---|
| 39 | hashWithLength: (length) =>
|
|---|
| 40 | `" + ${RuntimeGlobals.getFullHash}().slice(0, ${length}) + "`,
|
|---|
| 41 | chunk,
|
|---|
| 42 | runtime: chunk.runtime
|
|---|
| 43 | });
|
|---|
| 44 | return Template.asString([
|
|---|
| 45 | `${global} = ${runtimeTemplate.returningFunction(url)};`
|
|---|
| 46 | ]);
|
|---|
| 47 | }
|
|---|
| 48 | }
|
|---|
| 49 |
|
|---|
| 50 | module.exports = GetMainFilenameRuntimeModule;
|
|---|