ProvideSharedDependency.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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. class ProvideSharedDependency extends Dependency {
  9. constructor(shareScope, name, version, request, eager) {
  10. super();
  11. this.shareScope = shareScope;
  12. this.name = name;
  13. this.version = version;
  14. this.request = request;
  15. this.eager = eager;
  16. }
  17. get type() {
  18. return "provide shared module";
  19. }
  20. /**
  21. * @returns {string | null} an identifier to merge equal requests
  22. */
  23. getResourceIdentifier() {
  24. return `provide module (${this.shareScope}) ${this.request} as ${
  25. this.name
  26. } @ ${this.version}${this.eager ? " (eager)" : ""}`;
  27. }
  28. serialize(context) {
  29. context.write(this.shareScope);
  30. context.write(this.name);
  31. context.write(this.request);
  32. context.write(this.version);
  33. context.write(this.eager);
  34. super.serialize(context);
  35. }
  36. static deserialize(context) {
  37. const { read } = context;
  38. const obj = new ProvideSharedDependency(
  39. read(),
  40. read(),
  41. read(),
  42. read(),
  43. read()
  44. );
  45. this.shareScope = context.read();
  46. obj.deserialize(context);
  47. return obj;
  48. }
  49. }
  50. makeSerializable(
  51. ProvideSharedDependency,
  52. "webpack/lib/sharing/ProvideSharedDependency"
  53. );
  54. module.exports = ProvideSharedDependency;