ProvideSharedDependency.js 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. * @param {string} shareScope share scope
  13. * @param {string} name module name
  14. * @param {string | false} version version
  15. * @param {string} request request
  16. * @param {boolean} eager true, if this is an eager dependency
  17. */
  18. constructor(shareScope, name, version, request, eager) {
  19. super();
  20. this.shareScope = shareScope;
  21. this.name = name;
  22. this.version = version;
  23. this.request = request;
  24. this.eager = eager;
  25. }
  26. get type() {
  27. return "provide shared module";
  28. }
  29. /**
  30. * @returns {string | null} an identifier to merge equal requests
  31. */
  32. getResourceIdentifier() {
  33. return `provide module (${this.shareScope}) ${this.request} as ${
  34. this.name
  35. } @ ${this.version}${this.eager ? " (eager)" : ""}`;
  36. }
  37. /**
  38. * @param {ObjectSerializerContext} context context
  39. */
  40. serialize(context) {
  41. context.write(this.shareScope);
  42. context.write(this.name);
  43. context.write(this.request);
  44. context.write(this.version);
  45. context.write(this.eager);
  46. super.serialize(context);
  47. }
  48. /**
  49. * @param {ObjectDeserializerContext} context context
  50. * @returns {ProvideSharedDependency} deserialize fallback dependency
  51. */
  52. static deserialize(context) {
  53. const { read } = context;
  54. const obj = new ProvideSharedDependency(
  55. read(),
  56. read(),
  57. read(),
  58. read(),
  59. read()
  60. );
  61. this.shareScope = context.read();
  62. obj.deserialize(context);
  63. return obj;
  64. }
  65. }
  66. makeSerializable(
  67. ProvideSharedDependency,
  68. "webpack/lib/sharing/ProvideSharedDependency"
  69. );
  70. module.exports = ProvideSharedDependency;