ModulesInRootPlugin.js 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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 ModulesInRootPlugin {
  9. /**
  10. * @param {string | ResolveStepHook} source source
  11. * @param {string} path path
  12. * @param {string | ResolveStepHook} target target
  13. */
  14. constructor(source, path, target) {
  15. this.source = source;
  16. this.path = path;
  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("ModulesInRootPlugin", (request, resolveContext, callback) => {
  28. const obj = {
  29. ...request,
  30. path: this.path,
  31. request: "./" + request.request,
  32. module: false
  33. };
  34. resolver.doResolve(
  35. target,
  36. obj,
  37. "looking for modules in " + this.path,
  38. resolveContext,
  39. callback
  40. );
  41. });
  42. }
  43. };