You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

37 lines
890 B

4 years ago
  1. /*
  2. MIT License http://www.opensource.org/licenses/mit-license.php
  3. Author Tobias Koppers @sokra
  4. */
  5. "use strict";
  6. const basename = require("./getPaths").basename;
  7. module.exports = class CloneBasenamePlugin {
  8. constructor(source, target) {
  9. this.source = source;
  10. this.target = target;
  11. }
  12. apply(resolver) {
  13. const target = resolver.ensureHook(this.target);
  14. resolver
  15. .getHook(this.source)
  16. .tapAsync("CloneBasenamePlugin", (request, resolveContext, callback) => {
  17. const filename = basename(request.path);
  18. const filePath = resolver.join(request.path, filename);
  19. const obj = Object.assign({}, request, {
  20. path: filePath,
  21. relativePath:
  22. request.relativePath &&
  23. resolver.join(request.relativePath, filename)
  24. });
  25. resolver.doResolve(
  26. target,
  27. obj,
  28. "using path: " + filePath,
  29. resolveContext,
  30. callback
  31. );
  32. });
  33. }
  34. };