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.

36 lines
845 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. module.exports = class ModuleKindPlugin {
  7. constructor(source, target) {
  8. this.source = source;
  9. this.target = target;
  10. }
  11. apply(resolver) {
  12. const target = resolver.ensureHook(this.target);
  13. resolver
  14. .getHook(this.source)
  15. .tapAsync("ModuleKindPlugin", (request, resolveContext, callback) => {
  16. if (!request.module) return callback();
  17. const obj = Object.assign({}, request);
  18. delete obj.module;
  19. resolver.doResolve(
  20. target,
  21. obj,
  22. "resolve as module",
  23. resolveContext,
  24. (err, result) => {
  25. if (err) return callback(err);
  26. // Don't allow other alternatives
  27. if (result === undefined) return callback(null, null);
  28. callback(null, result);
  29. }
  30. );
  31. });
  32. }
  33. };