526bfd9a4628d92530b3ca0058c223f90a90da63299f0793de5b7d5b5477ba6f2842415c6b18f3a20ba3ec274d8ab2c29eb7b5d09b457b19c460d86e8089ee 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. 'use strict';
  2. Object.defineProperty(exports, '__esModule', { value: true });
  3. const path = require('path');
  4. function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
  5. const path__default = /*#__PURE__*/_interopDefaultLegacy(path);
  6. function normalizeWindowsPath(input = "") {
  7. if (!input.includes("\\")) {
  8. return input;
  9. }
  10. return input.replace(/\\/g, "/");
  11. }
  12. const _UNC_REGEX = /^[/][/]/;
  13. const _UNC_DRIVE_REGEX = /^[/][/]([.]{1,2}[/])?([a-zA-Z]):[/]/;
  14. const _IS_ABSOLUTE_RE = /^\/|^\\|^[a-zA-Z]:[/\\]/;
  15. const sep = "/";
  16. const delimiter = ":";
  17. const normalize = function(path2) {
  18. if (path2.length === 0) {
  19. return ".";
  20. }
  21. path2 = normalizeWindowsPath(path2);
  22. const isUNCPath = path2.match(_UNC_REGEX);
  23. const hasUNCDrive = isUNCPath && path2.match(_UNC_DRIVE_REGEX);
  24. const isPathAbsolute = isAbsolute(path2);
  25. const trailingSeparator = path2[path2.length - 1] === "/";
  26. path2 = normalizeString(path2, !isPathAbsolute);
  27. if (path2.length === 0) {
  28. if (isPathAbsolute) {
  29. return "/";
  30. }
  31. return trailingSeparator ? "./" : ".";
  32. }
  33. if (trailingSeparator) {
  34. path2 += "/";
  35. }
  36. if (isUNCPath) {
  37. if (hasUNCDrive) {
  38. return `//./${path2}`;
  39. }
  40. return `//${path2}`;
  41. }
  42. return isPathAbsolute && !isAbsolute(path2) ? `/${path2}` : path2;
  43. };
  44. const join = function(...args) {
  45. if (args.length === 0) {
  46. return ".";
  47. }
  48. let joined;
  49. for (let i = 0; i < args.length; ++i) {
  50. const arg = args[i];
  51. if (arg.length > 0) {
  52. if (joined === void 0) {
  53. joined = arg;
  54. } else {
  55. joined += `/${arg}`;
  56. }
  57. }
  58. }
  59. if (joined === void 0) {
  60. return ".";
  61. }
  62. return normalize(joined);
  63. };
  64. const resolve = function(...args) {
  65. args = args.map((arg) => normalizeWindowsPath(arg));
  66. let resolvedPath = "";
  67. let resolvedAbsolute = false;
  68. for (let i = args.length - 1; i >= -1 && !resolvedAbsolute; i--) {
  69. const path2 = i >= 0 ? args[i] : process.cwd();
  70. if (path2.length === 0) {
  71. continue;
  72. }
  73. resolvedPath = `${path2}/${resolvedPath}`;
  74. resolvedAbsolute = isAbsolute(path2);
  75. }
  76. resolvedPath = normalizeString(resolvedPath, !resolvedAbsolute);
  77. if (resolvedAbsolute && !isAbsolute(resolvedPath)) {
  78. return `/${resolvedPath}`;
  79. }
  80. return resolvedPath.length > 0 ? resolvedPath : ".";
  81. };
  82. function normalizeString(path2, allowAboveRoot) {
  83. let res = "";
  84. let lastSegmentLength = 0;
  85. let lastSlash = -1;
  86. let dots = 0;
  87. let char = null;
  88. for (let i = 0; i <= path2.length; ++i) {
  89. if (i < path2.length) {
  90. char = path2[i];
  91. } else if (char === "/") {
  92. break;
  93. } else {
  94. char = "/";
  95. }
  96. if (char === "/") {
  97. if (lastSlash === i - 1 || dots === 1) ; else if (dots === 2) {
  98. if (res.length < 2 || lastSegmentLength !== 2 || res[res.length - 1] !== "." || res[res.length - 2] !== ".") {
  99. if (res.length > 2) {
  100. const lastSlashIndex = res.lastIndexOf("/");
  101. if (lastSlashIndex === -1) {
  102. res = "";
  103. lastSegmentLength = 0;
  104. } else {
  105. res = res.slice(0, lastSlashIndex);
  106. lastSegmentLength = res.length - 1 - res.lastIndexOf("/");
  107. }
  108. lastSlash = i;
  109. dots = 0;
  110. continue;
  111. } else if (res.length !== 0) {
  112. res = "";
  113. lastSegmentLength = 0;
  114. lastSlash = i;
  115. dots = 0;
  116. continue;
  117. }
  118. }
  119. if (allowAboveRoot) {
  120. res += res.length > 0 ? "/.." : "..";
  121. lastSegmentLength = 2;
  122. }
  123. } else {
  124. if (res.length > 0) {
  125. res += `/${path2.slice(lastSlash + 1, i)}`;
  126. } else {
  127. res = path2.slice(lastSlash + 1, i);
  128. }
  129. lastSegmentLength = i - lastSlash - 1;
  130. }
  131. lastSlash = i;
  132. dots = 0;
  133. } else if (char === "." && dots !== -1) {
  134. ++dots;
  135. } else {
  136. dots = -1;
  137. }
  138. }
  139. return res;
  140. }
  141. const isAbsolute = function(p) {
  142. return _IS_ABSOLUTE_RE.test(p);
  143. };
  144. const toNamespacedPath = function(p) {
  145. return normalizeWindowsPath(p);
  146. };
  147. const extname = function(p) {
  148. return path__default["default"].posix.extname(normalizeWindowsPath(p));
  149. };
  150. const relative = function(from, to) {
  151. return path__default["default"].posix.relative(normalizeWindowsPath(from), normalizeWindowsPath(to));
  152. };
  153. const dirname = function(p) {
  154. return path__default["default"].posix.dirname(normalizeWindowsPath(p));
  155. };
  156. const format = function(p) {
  157. return normalizeWindowsPath(path__default["default"].posix.format(p));
  158. };
  159. const basename = function(p, ext) {
  160. return path__default["default"].posix.basename(normalizeWindowsPath(p), ext);
  161. };
  162. const parse = function(p) {
  163. return path__default["default"].posix.parse(normalizeWindowsPath(p));
  164. };
  165. const _path = /*#__PURE__*/Object.freeze({
  166. __proto__: null,
  167. sep: sep,
  168. delimiter: delimiter,
  169. normalize: normalize,
  170. join: join,
  171. resolve: resolve,
  172. normalizeString: normalizeString,
  173. isAbsolute: isAbsolute,
  174. toNamespacedPath: toNamespacedPath,
  175. extname: extname,
  176. relative: relative,
  177. dirname: dirname,
  178. format: format,
  179. basename: basename,
  180. parse: parse
  181. });
  182. const index = {
  183. ..._path
  184. };
  185. exports.basename = basename;
  186. exports["default"] = index;
  187. exports.delimiter = delimiter;
  188. exports.dirname = dirname;
  189. exports.extname = extname;
  190. exports.format = format;
  191. exports.isAbsolute = isAbsolute;
  192. exports.join = join;
  193. exports.normalize = normalize;
  194. exports.normalizeString = normalizeString;
  195. exports.parse = parse;
  196. exports.relative = relative;
  197. exports.resolve = resolve;
  198. exports.sep = sep;
  199. exports.toNamespacedPath = toNamespacedPath;