ParsePlugin.js 882 B

12345678910111213141516171819202122232425262728293031
  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 ParsePlugin {
  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("ParsePlugin", (request, resolveContext, callback) => {
  16. const parsed = resolver.parse(request.request);
  17. const obj = Object.assign({}, request, parsed);
  18. if (request.query && !parsed.query) {
  19. obj.query = request.query;
  20. }
  21. if (parsed && resolveContext.log) {
  22. if (parsed.module) resolveContext.log("Parsed request is a module");
  23. if (parsed.directory)
  24. resolveContext.log("Parsed request is a directory");
  25. }
  26. resolver.doResolve(target, obj, null, resolveContext, callback);
  27. });
  28. }
  29. };