RuntimeIdRuntimeModule.js 868 B

1234567891011121314151617181920212223242526272829303132
  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. * @returns {string | null} runtime code
  15. */
  16. generate() {
  17. const chunkGraph = /** @type {ChunkGraph} */ (this.chunkGraph);
  18. const chunk = /** @type {Chunk} */ (this.chunk);
  19. const runtime = chunk.runtime;
  20. if (typeof runtime !== "string")
  21. throw new Error("RuntimeIdRuntimeModule must be in a single runtime");
  22. const id = chunkGraph.getRuntimeId(runtime);
  23. return `${RuntimeGlobals.runtimeId} = ${JSON.stringify(id)};`;
  24. }
  25. }
  26. module.exports = RuntimeIdRuntimeModule;