ParsePlugin.js 790 B

123456789101112131415161718192021222324252627
  1. /*
  2. MIT License http://www.opensource.org/licenses/mit-license.php
  3. Author Tobias Koppers @sokra
  4. */
  5. function ParsePlugin(source, target) {
  6. this.source = source;
  7. this.target = target;
  8. }
  9. module.exports = ParsePlugin;
  10. ParsePlugin.prototype.apply = function(resolver) {
  11. var target = this.target;
  12. resolver.plugin(this.source, function(request, callback) {
  13. var parsed = resolver.parse(request.request);
  14. var obj = Object.assign({}, request, parsed);
  15. if(request.query && !parsed.query) {
  16. obj.query = request.query;
  17. }
  18. if(parsed && callback.log) {
  19. if(parsed.module)
  20. callback.log("Parsed request is a module");
  21. if(parsed.directory)
  22. callback.log("Parsed request is a directory");
  23. }
  24. resolver.doResolve(target, obj, null, callback);
  25. });
  26. };