NextPlugin.js 803 B

123456789101112131415161718192021222324252627282930313233
  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 NextPlugin {
  9. /**
  10. * @param {string | ResolveStepHook} source source
  11. * @param {string | ResolveStepHook} target target
  12. */
  13. constructor(source, target) {
  14. this.source = source;
  15. this.target = target;
  16. }
  17. /**
  18. * @param {Resolver} resolver the resolver
  19. * @returns {void}
  20. */
  21. apply(resolver) {
  22. const target = resolver.ensureHook(this.target);
  23. resolver
  24. .getHook(this.source)
  25. .tapAsync("NextPlugin", (request, resolveContext, callback) => {
  26. resolver.doResolve(target, request, null, resolveContext, callback);
  27. });
  28. }
  29. };