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.

44 lines
1.6 KiB

4 years ago
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. const url_1 = require("url");
  4. function urlToRequire(url) {
  5. const returnValue = `"${url}"`;
  6. // same logic as in transform-require.js
  7. const firstChar = url.charAt(0);
  8. if (firstChar === '.' || firstChar === '~' || firstChar === '@') {
  9. if (firstChar === '~') {
  10. const secondChar = url.charAt(1);
  11. url = url.slice(secondChar === '/' ? 2 : 1);
  12. }
  13. const uriParts = parseUriParts(url);
  14. if (!uriParts.hash) {
  15. return `require("${url}")`;
  16. }
  17. else {
  18. // support uri fragment case by excluding it from
  19. // the require and instead appending it as string;
  20. // assuming that the path part is sufficient according to
  21. // the above caseing(t.i. no protocol-auth-host parts expected)
  22. return `require("${uriParts.path}") + "${uriParts.hash}"`;
  23. }
  24. }
  25. return returnValue;
  26. }
  27. exports.urlToRequire = urlToRequire;
  28. /**
  29. * vuejs/component-compiler-utils#22 Support uri fragment in transformed require
  30. * @param urlString an url as a string
  31. */
  32. function parseUriParts(urlString) {
  33. // initialize return value
  34. const returnValue = url_1.parse('');
  35. if (urlString) {
  36. // A TypeError is thrown if urlString is not a string
  37. // @see https://nodejs.org/api/url.html#url_url_parse_urlstring_parsequerystring_slashesdenotehost
  38. if ('string' === typeof urlString) {
  39. // check is an uri
  40. return url_1.parse(urlString); // take apart the uri
  41. }
  42. }
  43. return returnValue;
  44. }