ContainerExposedDependency.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /*
  2. MIT License http://www.opensource.org/licenses/mit-license.php
  3. Author Tobias Koppers @sokra, Zackary Jackson @ScriptedAlchemy, Marais Rossouw @maraisr
  4. */
  5. "use strict";
  6. const ModuleDependency = require("../dependencies/ModuleDependency");
  7. const makeSerializable = require("../util/makeSerializable");
  8. /** @typedef {import("../serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
  9. /** @typedef {import("../serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
  10. class ContainerExposedDependency extends ModuleDependency {
  11. /**
  12. * @param {string} exposedName public name
  13. * @param {string} request request to module
  14. */
  15. constructor(exposedName, request) {
  16. super(request);
  17. this.exposedName = exposedName;
  18. }
  19. get type() {
  20. return "container exposed";
  21. }
  22. get category() {
  23. return "esm";
  24. }
  25. /**
  26. * @returns {string | null} an identifier to merge equal requests
  27. */
  28. getResourceIdentifier() {
  29. return `exposed dependency ${this.exposedName}=${this.request}`;
  30. }
  31. /**
  32. * @param {ObjectSerializerContext} context context
  33. */
  34. serialize(context) {
  35. context.write(this.exposedName);
  36. super.serialize(context);
  37. }
  38. /**
  39. * @param {ObjectDeserializerContext} context context
  40. */
  41. deserialize(context) {
  42. this.exposedName = context.read();
  43. super.deserialize(context);
  44. }
  45. }
  46. makeSerializable(
  47. ContainerExposedDependency,
  48. "webpack/lib/container/ContainerExposedDependency"
  49. );
  50. module.exports = ContainerExposedDependency;