UnsupportedDependency.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /*
  2. MIT License http://www.opensource.org/licenses/mit-license.php
  3. Author Tobias Koppers @sokra
  4. */
  5. "use strict";
  6. const makeSerializable = require("../util/makeSerializable");
  7. const NullDependency = require("./NullDependency");
  8. /** @typedef {import("webpack-sources").ReplaceSource} ReplaceSource */
  9. /** @typedef {import("../Dependency")} Dependency */
  10. /** @typedef {import("../DependencyTemplate").DependencyTemplateContext} DependencyTemplateContext */
  11. class UnsupportedDependency extends NullDependency {
  12. constructor(request, range) {
  13. super();
  14. this.request = request;
  15. this.range = range;
  16. }
  17. serialize(context) {
  18. const { write } = context;
  19. write(this.request);
  20. write(this.range);
  21. super.serialize(context);
  22. }
  23. deserialize(context) {
  24. const { read } = context;
  25. this.request = read();
  26. this.range = read();
  27. super.deserialize(context);
  28. }
  29. }
  30. makeSerializable(
  31. UnsupportedDependency,
  32. "webpack/lib/dependencies/UnsupportedDependency"
  33. );
  34. UnsupportedDependency.Template = class UnsupportedDependencyTemplate extends (
  35. NullDependency.Template
  36. ) {
  37. /**
  38. * @param {Dependency} dependency the dependency for which the template should be applied
  39. * @param {ReplaceSource} source the current replace source which can be modified
  40. * @param {DependencyTemplateContext} templateContext the context object
  41. * @returns {void}
  42. */
  43. apply(dependency, source, { runtimeTemplate }) {
  44. const dep = /** @type {UnsupportedDependency} */ (dependency);
  45. source.replace(
  46. dep.range[0],
  47. dep.range[1],
  48. runtimeTemplate.missingModule({
  49. request: dep.request
  50. })
  51. );
  52. }
  53. };
  54. module.exports = UnsupportedDependency;