JoinRequestPlugin.js 1.0 KB

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 JoinRequestPlugin {
  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("JoinRequestPlugin", (request, resolveContext, callback) => {
  26. const obj = {
  27. ...request,
  28. path: resolver.join(request.path, request.request),
  29. relativePath:
  30. request.relativePath &&
  31. resolver.join(request.relativePath, request.request),
  32. request: undefined
  33. };
  34. resolver.doResolve(target, obj, null, resolveContext, callback);
  35. });
  36. }
  37. };