getInnerRequest.js 823 B

123456789101112131415161718192021222324252627
  1. /*
  2. MIT License http://www.opensource.org/licenses/mit-license.php
  3. Author Tobias Koppers @sokra
  4. */
  5. "use strict";
  6. module.exports = function getInnerRequest(resolver, request) {
  7. if (
  8. typeof request.__innerRequest === "string" &&
  9. request.__innerRequest_request === request.request &&
  10. request.__innerRequest_relativePath === request.relativePath
  11. )
  12. return request.__innerRequest;
  13. let innerRequest;
  14. if (request.request) {
  15. innerRequest = request.request;
  16. if (/^\.\.?(?:\/|$)/.test(innerRequest) && request.relativePath) {
  17. innerRequest = resolver.join(request.relativePath, innerRequest);
  18. }
  19. } else {
  20. innerRequest = request.relativePath;
  21. }
  22. request.__innerRequest_request = request.request;
  23. request.__innerRequest_relativePath = request.relativePath;
  24. return (request.__innerRequest = innerRequest);
  25. };