FallbackDependency.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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 FallbackDependency extends Dependency {
  11. /**
  12. * @param {string[]} requests requests
  13. */
  14. constructor(requests) {
  15. super();
  16. this.requests = requests;
  17. }
  18. /**
  19. * @returns {string | null} an identifier to merge equal requests
  20. */
  21. getResourceIdentifier() {
  22. return `fallback ${this.requests.join(" ")}`;
  23. }
  24. get type() {
  25. return "fallback";
  26. }
  27. get category() {
  28. return "esm";
  29. }
  30. /**
  31. * @param {ObjectSerializerContext} context context
  32. */
  33. serialize(context) {
  34. const { write } = context;
  35. write(this.requests);
  36. super.serialize(context);
  37. }
  38. /**
  39. * @param {ObjectDeserializerContext} context context
  40. * @returns {FallbackDependency} deserialize fallback dependency
  41. */
  42. static deserialize(context) {
  43. const { read } = context;
  44. const obj = new FallbackDependency(read());
  45. obj.deserialize(context);
  46. return obj;
  47. }
  48. }
  49. makeSerializable(
  50. FallbackDependency,
  51. "webpack/lib/container/FallbackDependency"
  52. );
  53. module.exports = FallbackDependency;