ProvideSharedDependency.js 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /*
  2. MIT License http://www.opensource.org/licenses/mit-license.php
  3. Author Tobias Koppers @sokra
  4. */
  5. "use strict";
  6. const Dependency = require("../Dependency");
  7. const makeSerializable = require("../util/makeSerializable");
  8. /** @typedef {import("../serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
  9. /** @typedef {import("../serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
  10. class ProvideSharedDependency extends Dependency {
  11. /**
  12. * Creates an instance of ProvideSharedDependency.
  13. * @param {string} shareScope share scope
  14. * @param {string} name module name
  15. * @param {string | false} version version
  16. * @param {string} request request
  17. * @param {boolean} eager true, if this is an eager dependency
  18. */
  19. constructor(shareScope, name, version, request, eager) {
  20. super();
  21. this.shareScope = shareScope;
  22. this.name = name;
  23. this.version = version;
  24. this.request = request;
  25. this.eager = eager;
  26. }
  27. get type() {
  28. return "provide shared module";
  29. }
  30. /**
  31. * Returns an identifier to merge equal requests.
  32. * @returns {string | null} an identifier to merge equal requests
  33. */
  34. getResourceIdentifier() {
  35. return `provide module (${this.shareScope}) ${this.request} as ${
  36. this.name
  37. } @ ${this.version}${this.eager ? " (eager)" : ""}`;
  38. }
  39. /**
  40. * Serializes this instance into the provided serializer context.
  41. * @param {ObjectSerializerContext} context context
  42. */
  43. serialize(context) {
  44. context.write(this.shareScope);
  45. context.write(this.name);
  46. context.write(this.request);
  47. context.write(this.version);
  48. context.write(this.eager);
  49. super.serialize(context);
  50. }
  51. /**
  52. * Restores this instance from the provided deserializer context.
  53. * @param {ObjectDeserializerContext} context context
  54. * @returns {ProvideSharedDependency} deserialize fallback dependency
  55. */
  56. static deserialize(context) {
  57. const { read } = context;
  58. const obj = new ProvideSharedDependency(
  59. read(),
  60. read(),
  61. read(),
  62. read(),
  63. read()
  64. );
  65. this.shareScope = context.read();
  66. obj.deserialize(context);
  67. return obj;
  68. }
  69. }
  70. makeSerializable(
  71. ProvideSharedDependency,
  72. "webpack/lib/sharing/ProvideSharedDependency"
  73. );
  74. module.exports = ProvideSharedDependency;