TryNextPlugin.js 919 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. /*
  2. MIT License http://www.opensource.org/licenses/mit-license.php
  3. Author Tobias Koppers @sokra
  4. */
  5. "use strict";
  6. /** @typedef {import("./Resolver")} Resolver */
  7. /** @typedef {import("./Resolver").ResolveStepHook} ResolveStepHook */
  8. module.exports = class TryNextPlugin {
  9. /**
  10. * @param {string | ResolveStepHook} source source
  11. * @param {string} message message
  12. * @param {string | ResolveStepHook} target target
  13. */
  14. constructor(source, message, target) {
  15. this.source = source;
  16. this.message = message;
  17. this.target = target;
  18. }
  19. /**
  20. * @param {Resolver} resolver the resolver
  21. * @returns {void}
  22. */
  23. apply(resolver) {
  24. const target = resolver.ensureHook(this.target);
  25. resolver
  26. .getHook(this.source)
  27. .tapAsync("TryNextPlugin", (request, resolveContext, callback) => {
  28. resolver.doResolve(
  29. target,
  30. request,
  31. this.message,
  32. resolveContext,
  33. callback
  34. );
  35. });
  36. }
  37. };