[6a3a178] | 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("../Compilation")} Compilation */
|
---|
| 12 |
|
---|
| 13 | class GetMainFilenameRuntimeModule extends RuntimeModule {
|
---|
| 14 | /**
|
---|
| 15 | * @param {string} name readable name
|
---|
| 16 | * @param {string} global global object binding
|
---|
| 17 | * @param {string} filename main file name
|
---|
| 18 | */
|
---|
| 19 | constructor(name, global, filename) {
|
---|
| 20 | super(`get ${name} filename`);
|
---|
| 21 | this.global = global;
|
---|
| 22 | this.filename = filename;
|
---|
| 23 | }
|
---|
| 24 |
|
---|
| 25 | /**
|
---|
| 26 | * @returns {string} runtime code
|
---|
| 27 | */
|
---|
| 28 | generate() {
|
---|
| 29 | const { global, filename, compilation, chunk } = this;
|
---|
| 30 | const { runtimeTemplate } = compilation;
|
---|
| 31 | const url = compilation.getPath(JSON.stringify(filename), {
|
---|
| 32 | hash: `" + ${RuntimeGlobals.getFullHash}() + "`,
|
---|
| 33 | hashWithLength: length =>
|
---|
| 34 | `" + ${RuntimeGlobals.getFullHash}().slice(0, ${length}) + "`,
|
---|
| 35 | chunk,
|
---|
| 36 | runtime: chunk.runtime
|
---|
| 37 | });
|
---|
| 38 | return Template.asString([
|
---|
| 39 | `${global} = ${runtimeTemplate.returningFunction(url)};`
|
---|
| 40 | ]);
|
---|
| 41 | }
|
---|
| 42 | }
|
---|
| 43 |
|
---|
| 44 | module.exports = GetMainFilenameRuntimeModule;
|
---|