RuntimeIdRuntimeModule.js 926 B

12345678910111213141516171819202122232425262728293031323334
  1. /*
  2. MIT License http://www.opensource.org/licenses/mit-license.php
  3. */
  4. "use strict";
  5. const RuntimeGlobals = require("../RuntimeGlobals");
  6. const RuntimeModule = require("../RuntimeModule");
  7. /** @typedef {import("../Chunk")} Chunk */
  8. /** @typedef {import("../ChunkGraph")} ChunkGraph */
  9. class RuntimeIdRuntimeModule extends RuntimeModule {
  10. constructor() {
  11. super("runtimeId");
  12. }
  13. /**
  14. * Generates runtime code for this runtime module.
  15. * @returns {string | null} runtime code
  16. */
  17. generate() {
  18. const chunkGraph = /** @type {ChunkGraph} */ (this.chunkGraph);
  19. const chunk = /** @type {Chunk} */ (this.chunk);
  20. const runtime = chunk.runtime;
  21. if (typeof runtime !== "string") {
  22. throw new Error("RuntimeIdRuntimeModule must be in a single runtime");
  23. }
  24. const id = chunkGraph.getRuntimeId(runtime);
  25. return `${RuntimeGlobals.runtimeId} = ${JSON.stringify(id)};`;
  26. }
  27. }
  28. module.exports = RuntimeIdRuntimeModule;