@opensumi/ide-components 2.12.1-next-079c1930

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (360) hide show
  1. package/README.md +65 -0
  2. package/dist/index.css +1 -0
  3. package/dist/index.js +26330 -0
  4. package/lib/badge/index.d.ts +4 -0
  5. package/lib/badge/index.d.ts.map +1 -0
  6. package/lib/badge/index.js +13 -0
  7. package/lib/badge/index.js.map +1 -0
  8. package/lib/badge/styles.less +17 -0
  9. package/lib/button/index.d.ts +54 -0
  10. package/lib/button/index.d.ts.map +1 -0
  11. package/lib/button/index.js +68 -0
  12. package/lib/button/index.js.map +1 -0
  13. package/lib/button/style.less +251 -0
  14. package/lib/checkbox/index.d.ts +9 -0
  15. package/lib/checkbox/index.d.ts.map +1 -0
  16. package/lib/checkbox/index.js +27 -0
  17. package/lib/checkbox/index.js.map +1 -0
  18. package/lib/checkbox/style.less +80 -0
  19. package/lib/common.d.ts +7 -0
  20. package/lib/common.d.ts.map +1 -0
  21. package/lib/common.js +11 -0
  22. package/lib/common.js.map +1 -0
  23. package/lib/dialog/index.d.ts +26 -0
  24. package/lib/dialog/index.d.ts.map +1 -0
  25. package/lib/dialog/index.js +28 -0
  26. package/lib/dialog/index.js.map +1 -0
  27. package/lib/dialog/styles.less +85 -0
  28. package/lib/dropdown/dropdown.d.ts +48 -0
  29. package/lib/dropdown/dropdown.d.ts.map +1 -0
  30. package/lib/dropdown/dropdown.js +80 -0
  31. package/lib/dropdown/dropdown.js.map +1 -0
  32. package/lib/dropdown/index.d.ts +5 -0
  33. package/lib/dropdown/index.d.ts.map +1 -0
  34. package/lib/dropdown/index.js +8 -0
  35. package/lib/dropdown/index.js.map +1 -0
  36. package/lib/dropdown/style.less +254 -0
  37. package/lib/icon/icon.d.ts +33 -0
  38. package/lib/icon/icon.d.ts.map +1 -0
  39. package/lib/icon/icon.js +71 -0
  40. package/lib/icon/icon.js.map +1 -0
  41. package/lib/icon/iconfont/iconManager.d.ts +187 -0
  42. package/lib/icon/iconfont/iconManager.d.ts.map +1 -0
  43. package/lib/icon/iconfont/iconManager.js +67 -0
  44. package/lib/icon/iconfont/iconManager.js.map +1 -0
  45. package/lib/icon/iconfont/iconMap.d.ts +160 -0
  46. package/lib/icon/iconfont/iconMap.d.ts.map +1 -0
  47. package/lib/icon/iconfont/iconMap.js +165 -0
  48. package/lib/icon/iconfont/iconMap.js.map +1 -0
  49. package/lib/icon/iconfont/iconfont.css +646 -0
  50. package/lib/icon/iconfont/iconfont.eot +0 -0
  51. package/lib/icon/iconfont/iconfont.html +1522 -0
  52. package/lib/icon/iconfont/iconfont.svg +333 -0
  53. package/lib/icon/iconfont/iconfont.ttf +0 -0
  54. package/lib/icon/iconfont/iconfont.woff +0 -0
  55. package/lib/icon/iconfont/iconfont.woff2 +0 -0
  56. package/lib/icon/iconfont-cn.d.ts +15 -0
  57. package/lib/icon/iconfont-cn.d.ts.map +1 -0
  58. package/lib/icon/iconfont-cn.js +78 -0
  59. package/lib/icon/iconfont-cn.js.map +1 -0
  60. package/lib/icon/index.d.ts +4 -0
  61. package/lib/icon/index.d.ts.map +1 -0
  62. package/lib/icon/index.js +9 -0
  63. package/lib/icon/index.js.map +1 -0
  64. package/lib/icon/styles.less +105 -0
  65. package/lib/icon/util.d.ts +29 -0
  66. package/lib/icon/util.d.ts.map +1 -0
  67. package/lib/icon/util.js +53 -0
  68. package/lib/icon/util.js.map +1 -0
  69. package/lib/index.d.ts +20 -0
  70. package/lib/index.d.ts.map +1 -0
  71. package/lib/index.js +23 -0
  72. package/lib/index.js.map +1 -0
  73. package/lib/input/HistoryInputBox.d.ts +38 -0
  74. package/lib/input/HistoryInputBox.d.ts.map +1 -0
  75. package/lib/input/HistoryInputBox.js +114 -0
  76. package/lib/input/HistoryInputBox.js.map +1 -0
  77. package/lib/input/Input.d.ts +43 -0
  78. package/lib/input/Input.d.ts.map +1 -0
  79. package/lib/input/Input.js +124 -0
  80. package/lib/input/Input.js.map +1 -0
  81. package/lib/input/ProxiedInput.d.ts +8 -0
  82. package/lib/input/ProxiedInput.d.ts.map +1 -0
  83. package/lib/input/ProxiedInput.js +67 -0
  84. package/lib/input/ProxiedInput.js.map +1 -0
  85. package/lib/input/TextArea.d.ts +6 -0
  86. package/lib/input/TextArea.d.ts.map +1 -0
  87. package/lib/input/TextArea.js +11 -0
  88. package/lib/input/TextArea.js.map +1 -0
  89. package/lib/input/ValidateInput.d.ts +20 -0
  90. package/lib/input/ValidateInput.d.ts.map +1 -0
  91. package/lib/input/ValidateInput.js +59 -0
  92. package/lib/input/ValidateInput.js.map +1 -0
  93. package/lib/input/index.d.ts +5 -0
  94. package/lib/input/index.d.ts.map +1 -0
  95. package/lib/input/index.js +8 -0
  96. package/lib/input/index.js.map +1 -0
  97. package/lib/input/input.less +83 -0
  98. package/lib/input/validate-input.less +88 -0
  99. package/lib/locale-context-provider.d.ts +16 -0
  100. package/lib/locale-context-provider.d.ts.map +1 -0
  101. package/lib/locale-context-provider.js +26 -0
  102. package/lib/locale-context-provider.js.map +1 -0
  103. package/lib/menu/MenuContext.d.ts +8 -0
  104. package/lib/menu/MenuContext.d.ts.map +1 -0
  105. package/lib/menu/MenuContext.js +8 -0
  106. package/lib/menu/MenuContext.js.map +1 -0
  107. package/lib/menu/MenuItem.d.ts +29 -0
  108. package/lib/menu/MenuItem.d.ts.map +1 -0
  109. package/lib/menu/MenuItem.js +32 -0
  110. package/lib/menu/MenuItem.js.map +1 -0
  111. package/lib/menu/SubMenu.d.ts +30 -0
  112. package/lib/menu/SubMenu.d.ts.map +1 -0
  113. package/lib/menu/SubMenu.js +28 -0
  114. package/lib/menu/SubMenu.js.map +1 -0
  115. package/lib/menu/index.d.ts +64 -0
  116. package/lib/menu/index.d.ts.map +1 -0
  117. package/lib/menu/index.js +203 -0
  118. package/lib/menu/index.js.map +1 -0
  119. package/lib/menu/style.less +513 -0
  120. package/lib/message/index.d.ts +10 -0
  121. package/lib/message/index.d.ts.map +1 -0
  122. package/lib/message/index.js +21 -0
  123. package/lib/message/index.js.map +1 -0
  124. package/lib/message/message.d.ts +42 -0
  125. package/lib/message/message.d.ts.map +1 -0
  126. package/lib/message/message.js +128 -0
  127. package/lib/message/message.js.map +1 -0
  128. package/lib/message/style.less +76 -0
  129. package/lib/modal/Modal.d.ts +127 -0
  130. package/lib/modal/Modal.d.ts.map +1 -0
  131. package/lib/modal/Modal.js +87 -0
  132. package/lib/modal/Modal.js.map +1 -0
  133. package/lib/modal/index.d.ts +5 -0
  134. package/lib/modal/index.d.ts.map +1 -0
  135. package/lib/modal/index.js +8 -0
  136. package/lib/modal/index.js.map +1 -0
  137. package/lib/modal/locale.d.ts +8 -0
  138. package/lib/modal/locale.d.ts.map +1 -0
  139. package/lib/modal/locale.js +23 -0
  140. package/lib/modal/locale.js.map +1 -0
  141. package/lib/modal/style.less +168 -0
  142. package/lib/notification/index.d.ts +8 -0
  143. package/lib/notification/index.d.ts.map +1 -0
  144. package/lib/notification/index.js +80 -0
  145. package/lib/notification/index.js.map +1 -0
  146. package/lib/notification/notification.d.ts +44 -0
  147. package/lib/notification/notification.d.ts.map +1 -0
  148. package/lib/notification/notification.js +156 -0
  149. package/lib/notification/notification.js.map +1 -0
  150. package/lib/notification/notification.less +231 -0
  151. package/lib/overlay/index.d.ts +19 -0
  152. package/lib/overlay/index.d.ts.map +1 -0
  153. package/lib/overlay/index.js +13 -0
  154. package/lib/overlay/index.js.map +1 -0
  155. package/lib/overlay/styles.less +44 -0
  156. package/lib/popover/index.d.ts +28 -0
  157. package/lib/popover/index.d.ts.map +1 -0
  158. package/lib/popover/index.js +127 -0
  159. package/lib/popover/index.js.map +1 -0
  160. package/lib/popover/styles.less +135 -0
  161. package/lib/recycle-list/RecycleList.d.ts +105 -0
  162. package/lib/recycle-list/RecycleList.d.ts.map +1 -0
  163. package/lib/recycle-list/RecycleList.js +253 -0
  164. package/lib/recycle-list/RecycleList.js.map +1 -0
  165. package/lib/recycle-list/index.d.ts +2 -0
  166. package/lib/recycle-list/index.d.ts.map +1 -0
  167. package/lib/recycle-list/index.js +5 -0
  168. package/lib/recycle-list/index.js.map +1 -0
  169. package/lib/recycle-tree/RecycleTree.d.ts +254 -0
  170. package/lib/recycle-tree/RecycleTree.d.ts.map +1 -0
  171. package/lib/recycle-tree/RecycleTree.js +635 -0
  172. package/lib/recycle-tree/RecycleTree.js.map +1 -0
  173. package/lib/recycle-tree/TreeNodeRendererWrap.d.ts +37 -0
  174. package/lib/recycle-tree/TreeNodeRendererWrap.d.ts.map +1 -0
  175. package/lib/recycle-tree/TreeNodeRendererWrap.js +18 -0
  176. package/lib/recycle-tree/TreeNodeRendererWrap.js.map +1 -0
  177. package/lib/recycle-tree/decorators/Adaptive/index.d.ts +10 -0
  178. package/lib/recycle-tree/decorators/Adaptive/index.d.ts.map +1 -0
  179. package/lib/recycle-tree/decorators/Adaptive/index.js +97 -0
  180. package/lib/recycle-tree/decorators/Adaptive/index.js.map +1 -0
  181. package/lib/recycle-tree/decorators/Filter/filter.less +11 -0
  182. package/lib/recycle-tree/decorators/Filter/index.d.ts +26 -0
  183. package/lib/recycle-tree/decorators/Filter/index.d.ts.map +1 -0
  184. package/lib/recycle-tree/decorators/Filter/index.js +53 -0
  185. package/lib/recycle-tree/decorators/Filter/index.js.map +1 -0
  186. package/lib/recycle-tree/decorators/index.d.ts +3 -0
  187. package/lib/recycle-tree/decorators/index.d.ts.map +1 -0
  188. package/lib/recycle-tree/decorators/index.js +6 -0
  189. package/lib/recycle-tree/decorators/index.js.map +1 -0
  190. package/lib/recycle-tree/index.d.ts +7 -0
  191. package/lib/recycle-tree/index.d.ts.map +1 -0
  192. package/lib/recycle-tree/index.js +10 -0
  193. package/lib/recycle-tree/index.js.map +1 -0
  194. package/lib/recycle-tree/prompt/NewPromptHandle.d.ts +12 -0
  195. package/lib/recycle-tree/prompt/NewPromptHandle.d.ts.map +1 -0
  196. package/lib/recycle-tree/prompt/NewPromptHandle.js +21 -0
  197. package/lib/recycle-tree/prompt/NewPromptHandle.js.map +1 -0
  198. package/lib/recycle-tree/prompt/PromptHandle.d.ts +59 -0
  199. package/lib/recycle-tree/prompt/PromptHandle.d.ts.map +1 -0
  200. package/lib/recycle-tree/prompt/PromptHandle.js +200 -0
  201. package/lib/recycle-tree/prompt/PromptHandle.js.map +1 -0
  202. package/lib/recycle-tree/prompt/RenamePromptHandle.d.ts +10 -0
  203. package/lib/recycle-tree/prompt/RenamePromptHandle.d.ts.map +1 -0
  204. package/lib/recycle-tree/prompt/RenamePromptHandle.js +21 -0
  205. package/lib/recycle-tree/prompt/RenamePromptHandle.js.map +1 -0
  206. package/lib/recycle-tree/prompt/index.d.ts +4 -0
  207. package/lib/recycle-tree/prompt/index.d.ts.map +1 -0
  208. package/lib/recycle-tree/prompt/index.js +7 -0
  209. package/lib/recycle-tree/prompt/index.js.map +1 -0
  210. package/lib/recycle-tree/tree/Tree.d.ts +20 -0
  211. package/lib/recycle-tree/tree/Tree.d.ts.map +1 -0
  212. package/lib/recycle-tree/tree/Tree.js +43 -0
  213. package/lib/recycle-tree/tree/Tree.js.map +1 -0
  214. package/lib/recycle-tree/tree/TreeNode.d.ts +222 -0
  215. package/lib/recycle-tree/tree/TreeNode.d.ts.map +1 -0
  216. package/lib/recycle-tree/tree/TreeNode.js +1099 -0
  217. package/lib/recycle-tree/tree/TreeNode.js.map +1 -0
  218. package/lib/recycle-tree/tree/decoration/CompositeDecoration.d.ts +60 -0
  219. package/lib/recycle-tree/tree/decoration/CompositeDecoration.d.ts.map +1 -0
  220. package/lib/recycle-tree/tree/decoration/CompositeDecoration.js +328 -0
  221. package/lib/recycle-tree/tree/decoration/CompositeDecoration.js.map +1 -0
  222. package/lib/recycle-tree/tree/decoration/Decoration.d.ts +79 -0
  223. package/lib/recycle-tree/tree/decoration/Decoration.d.ts.map +1 -0
  224. package/lib/recycle-tree/tree/decoration/Decoration.js +183 -0
  225. package/lib/recycle-tree/tree/decoration/Decoration.js.map +1 -0
  226. package/lib/recycle-tree/tree/decoration/DecorationManager.d.ts +34 -0
  227. package/lib/recycle-tree/tree/decoration/DecorationManager.d.ts.map +1 -0
  228. package/lib/recycle-tree/tree/decoration/DecorationManager.js +166 -0
  229. package/lib/recycle-tree/tree/decoration/DecorationManager.js.map +1 -0
  230. package/lib/recycle-tree/tree/decoration/index.d.ts +4 -0
  231. package/lib/recycle-tree/tree/decoration/index.d.ts.map +1 -0
  232. package/lib/recycle-tree/tree/decoration/index.js +7 -0
  233. package/lib/recycle-tree/tree/decoration/index.js.map +1 -0
  234. package/lib/recycle-tree/tree/index.d.ts +5 -0
  235. package/lib/recycle-tree/tree/index.d.ts.map +1 -0
  236. package/lib/recycle-tree/tree/index.js +8 -0
  237. package/lib/recycle-tree/tree/index.js.map +1 -0
  238. package/lib/recycle-tree/tree/model/TreeModel.d.ts +50 -0
  239. package/lib/recycle-tree/tree/model/TreeModel.d.ts.map +1 -0
  240. package/lib/recycle-tree/tree/model/TreeModel.js +81 -0
  241. package/lib/recycle-tree/tree/model/TreeModel.js.map +1 -0
  242. package/lib/recycle-tree/tree/model/index.d.ts +2 -0
  243. package/lib/recycle-tree/tree/model/index.d.ts.map +1 -0
  244. package/lib/recycle-tree/tree/model/index.js +5 -0
  245. package/lib/recycle-tree/tree/model/index.js.map +1 -0
  246. package/lib/recycle-tree/tree/model/treeState/TreeStateManager.d.ts +65 -0
  247. package/lib/recycle-tree/tree/model/treeState/TreeStateManager.d.ts.map +1 -0
  248. package/lib/recycle-tree/tree/model/treeState/TreeStateManager.js +191 -0
  249. package/lib/recycle-tree/tree/model/treeState/TreeStateManager.js.map +1 -0
  250. package/lib/recycle-tree/tree/model/treeState/TreeStateWatcher.d.ts +15 -0
  251. package/lib/recycle-tree/tree/model/treeState/TreeStateWatcher.d.ts.map +1 -0
  252. package/lib/recycle-tree/tree/model/treeState/TreeStateWatcher.js +104 -0
  253. package/lib/recycle-tree/tree/model/treeState/TreeStateWatcher.js.map +1 -0
  254. package/lib/recycle-tree/tree/model/treeState/index.d.ts +4 -0
  255. package/lib/recycle-tree/tree/model/treeState/index.d.ts.map +1 -0
  256. package/lib/recycle-tree/tree/model/treeState/index.js +8 -0
  257. package/lib/recycle-tree/tree/model/treeState/index.js.map +1 -0
  258. package/lib/recycle-tree/tree/model/treeState/types.d.ts +21 -0
  259. package/lib/recycle-tree/tree/model/treeState/types.d.ts.map +1 -0
  260. package/lib/recycle-tree/tree/model/treeState/types.js +18 -0
  261. package/lib/recycle-tree/tree/model/treeState/types.js.map +1 -0
  262. package/lib/recycle-tree/types/index.d.ts +4 -0
  263. package/lib/recycle-tree/types/index.d.ts.map +1 -0
  264. package/lib/recycle-tree/types/index.js +7 -0
  265. package/lib/recycle-tree/types/index.js.map +1 -0
  266. package/lib/recycle-tree/types/tree-node.d.ts +70 -0
  267. package/lib/recycle-tree/types/tree-node.d.ts.map +1 -0
  268. package/lib/recycle-tree/types/tree-node.js +11 -0
  269. package/lib/recycle-tree/types/tree-node.js.map +1 -0
  270. package/lib/recycle-tree/types/tree.d.ts +8 -0
  271. package/lib/recycle-tree/types/tree.d.ts.map +1 -0
  272. package/lib/recycle-tree/types/tree.js +3 -0
  273. package/lib/recycle-tree/types/tree.js.map +1 -0
  274. package/lib/recycle-tree/types/watcher.d.ts +114 -0
  275. package/lib/recycle-tree/types/watcher.d.ts.map +1 -0
  276. package/lib/recycle-tree/types/watcher.js +46 -0
  277. package/lib/recycle-tree/types/watcher.js.map +1 -0
  278. package/lib/scrollbars/index.d.ts +14 -0
  279. package/lib/scrollbars/index.d.ts.map +1 -0
  280. package/lib/scrollbars/index.js +52 -0
  281. package/lib/scrollbars/index.js.map +1 -0
  282. package/lib/scrollbars/styles.less +46 -0
  283. package/lib/select/index.d.ts +119 -0
  284. package/lib/select/index.d.ts.map +1 -0
  285. package/lib/select/index.js +327 -0
  286. package/lib/select/index.js.map +1 -0
  287. package/lib/select/style.less +224 -0
  288. package/lib/style/base.less +542 -0
  289. package/lib/style/index.less +14 -0
  290. package/lib/style/mixins.less +135 -0
  291. package/lib/style/motion/fade.less +31 -0
  292. package/lib/style/motion/move.less +120 -0
  293. package/lib/style/motion/other.less +45 -0
  294. package/lib/style/motion/slide.less +120 -0
  295. package/lib/style/motion/swing.less +34 -0
  296. package/lib/style/motion/zoom.less +162 -0
  297. package/lib/style/variable.less +204 -0
  298. package/lib/tabs/index.d.ts +12 -0
  299. package/lib/tabs/index.d.ts.map +1 -0
  300. package/lib/tabs/index.js +24 -0
  301. package/lib/tabs/index.js.map +1 -0
  302. package/lib/tabs/style.less +34 -0
  303. package/lib/tooltip/index.d.ts +7 -0
  304. package/lib/tooltip/index.d.ts.map +1 -0
  305. package/lib/tooltip/index.js +58 -0
  306. package/lib/tooltip/index.js.map +1 -0
  307. package/lib/tooltip/style.less +41 -0
  308. package/lib/utils/deprecated.d.ts +3 -0
  309. package/lib/utils/deprecated.d.ts.map +1 -0
  310. package/lib/utils/deprecated.js +18 -0
  311. package/lib/utils/deprecated.js.map +1 -0
  312. package/lib/utils/disposable.d.ts +37 -0
  313. package/lib/utils/disposable.d.ts.map +1 -0
  314. package/lib/utils/disposable.js +140 -0
  315. package/lib/utils/disposable.js.map +1 -0
  316. package/lib/utils/event.d.ts +189 -0
  317. package/lib/utils/event.d.ts.map +1 -0
  318. package/lib/utils/event.js +569 -0
  319. package/lib/utils/event.js.map +1 -0
  320. package/lib/utils/index.d.ts +10 -0
  321. package/lib/utils/index.d.ts.map +1 -0
  322. package/lib/utils/index.js +13 -0
  323. package/lib/utils/index.js.map +1 -0
  324. package/lib/utils/iterator.d.ts +14 -0
  325. package/lib/utils/iterator.d.ts.map +1 -0
  326. package/lib/utils/iterator.js +9 -0
  327. package/lib/utils/iterator.js.map +1 -0
  328. package/lib/utils/linkedList.d.ts +18 -0
  329. package/lib/utils/linkedList.d.ts.map +1 -0
  330. package/lib/utils/linkedList.js +139 -0
  331. package/lib/utils/linkedList.js.map +1 -0
  332. package/lib/utils/motion.d.ts +24 -0
  333. package/lib/utils/motion.d.ts.map +1 -0
  334. package/lib/utils/motion.js +17 -0
  335. package/lib/utils/motion.js.map +1 -0
  336. package/lib/utils/os.d.ts +4 -0
  337. package/lib/utils/os.d.ts.map +1 -0
  338. package/lib/utils/os.js +22 -0
  339. package/lib/utils/os.js.map +1 -0
  340. package/lib/utils/path.d.ts +92 -0
  341. package/lib/utils/path.d.ts.map +1 -0
  342. package/lib/utils/path.js +1712 -0
  343. package/lib/utils/path.js.map +1 -0
  344. package/lib/utils/process.d.ts +6 -0
  345. package/lib/utils/process.d.ts.map +1 -0
  346. package/lib/utils/process.js +17 -0
  347. package/lib/utils/process.js.map +1 -0
  348. package/lib/utils/raf.d.ts +10 -0
  349. package/lib/utils/raf.d.ts.map +1 -0
  350. package/lib/utils/raf.js +33 -0
  351. package/lib/utils/raf.js.map +1 -0
  352. package/lib/utils/type.d.ts +4 -0
  353. package/lib/utils/type.d.ts.map +1 -0
  354. package/lib/utils/type.js +9 -0
  355. package/lib/utils/type.js.map +1 -0
  356. package/lib/utils/warning.d.ts +8 -0
  357. package/lib/utils/warning.d.ts.map +1 -0
  358. package/lib/utils/warning.js +40 -0
  359. package/lib/utils/warning.js.map +1 -0
  360. package/package.json +36 -0
@@ -0,0 +1,1712 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.delimiter = exports.sep = exports.toNamespacedPath = exports.parse = exports.format = exports.extname = exports.basename = exports.dirname = exports.relative = exports.resolve = exports.join = exports.isAbsolute = exports.normalize = exports.posix = exports.win32 = exports.Path = void 0;
4
+ // Modify from @opensumi/ide-core-common/src/path.ts
5
+ const process_1 = require("./process");
6
+ const os_1 = require("./os");
7
+ const SystemPathSeparatorRegex = os_1.isWindows ? /\\/g : /\//g;
8
+ /**
9
+ * On POSIX:
10
+ * ┌──────────────────────┬────────────┐
11
+ * │ dir │ base │
12
+ * ├──────┬ ├──────┬─────┤
13
+ * │ root │ │ name │ ext │
14
+ * " / home/user/dir / file .txt "
15
+ * └──────┴───────────────┴──────┴─────┘
16
+ *
17
+ * On Windows:
18
+ * ┌──────────────────────┬────────────┐
19
+ * │ dir │ base │
20
+ * ├──────┬ ├──────┬─────┤
21
+ * │ root │ │ name │ ext │
22
+ * " /c: / home/user/dir / file .txt "
23
+ * └──────┴───────────────┴──────┴─────┘
24
+ */
25
+ class Path {
26
+ /**
27
+ * The raw should be normalized, meaning that only '/' is allowed as a path separator.
28
+ */
29
+ constructor(raw) {
30
+ raw = raw.replace(SystemPathSeparatorRegex, Path.separator);
31
+ this.raw = Path.normalizeDrive(raw);
32
+ const firstIndex = raw.indexOf(Path.separator);
33
+ const lastIndex = raw.lastIndexOf(Path.separator);
34
+ this.isAbsolute = firstIndex === 0;
35
+ this.base = lastIndex === -1 ? raw : raw.substr(lastIndex + 1);
36
+ this.isRoot = this.isAbsolute && firstIndex === lastIndex && (!this.base || Path.isDrive(this.base));
37
+ this.root = this.computeRoot();
38
+ const extIndex = this.base.lastIndexOf('.');
39
+ // 处理无后缀文件或者 dot 打头的无后缀文件
40
+ // file like 'a/b/c/test'
41
+ if (extIndex === -1) {
42
+ this.name = this.base;
43
+ this.ext = '';
44
+ }
45
+ else if (extIndex === 0) {
46
+ // dot file like `a/b/c/.eslintrc`
47
+ this.name = this.base;
48
+ this.ext = '';
49
+ }
50
+ else {
51
+ this.name = this.base.substr(0, extIndex);
52
+ this.ext = this.base.substr(extIndex);
53
+ }
54
+ }
55
+ static isDrive(segment) {
56
+ return segment.endsWith(':');
57
+ }
58
+ static splitPath(path) {
59
+ return path.split(Path.separator).filter((path) => !!path);
60
+ }
61
+ static isRelative(path) {
62
+ return !path.startsWith(Path.separator);
63
+ }
64
+ static pathDepth(path) {
65
+ return path.split(Path.separator).length;
66
+ }
67
+ /**
68
+ * vscode-uri always normalizes drive letters to lower case:
69
+ * https://github.com/Microsoft/vscode-uri/blob/b1d3221579f97f28a839b6f996d76fc45e9964d8/src/index.ts#L1025
70
+ * Theia path should be adjusted to this.
71
+ */
72
+ static normalizeDrive(path) {
73
+ // lower-case windows drive letters in /C:/fff or C:/fff
74
+ if (path.length >= 3 && path.charCodeAt(0) === 47 /* '/' */ && path.charCodeAt(2) === 58 /* ':' */) {
75
+ const code = path.charCodeAt(1);
76
+ if (code >= 65 /* A */ && code <= 90 /* Z */) {
77
+ path = `/${String.fromCharCode(code + 32)}:${path.substr(3)}`; // "/c:".length === 3
78
+ }
79
+ }
80
+ else if (path.length >= 2 && path.charCodeAt(1) === 58 /* ':' */) {
81
+ const code = path.charCodeAt(0);
82
+ if (code >= 65 /* A */ && code <= 90 /* Z */) {
83
+ path = `${String.fromCharCode(code + 32)}:${path.substr(2)}`; // "/c:".length === 3
84
+ }
85
+ }
86
+ return path;
87
+ }
88
+ computeRoot() {
89
+ // '/' -> '/'
90
+ // '/c:' -> '/c:'
91
+ if (this.isRoot) {
92
+ return this;
93
+ }
94
+ // 'foo/bar' -> `undefined`
95
+ if (!this.isAbsolute) {
96
+ return undefined;
97
+ }
98
+ const index = this.raw.indexOf(Path.separator, Path.separator.length);
99
+ if (index === -1) {
100
+ // '/foo/bar' -> '/'
101
+ return new Path(Path.separator);
102
+ }
103
+ // '/c:/foo/bar' -> '/c:'
104
+ // '/foo/bar' -> '/'
105
+ return new Path(this.raw.substr(0, index)).root;
106
+ }
107
+ get dir() {
108
+ if (this._dir === undefined) {
109
+ this._dir = this.computeDir();
110
+ }
111
+ return this._dir;
112
+ }
113
+ computeDir() {
114
+ if (this.isRoot) {
115
+ return this;
116
+ }
117
+ const lastIndex = this.raw.lastIndexOf(Path.separator);
118
+ if (lastIndex === -1) {
119
+ return this;
120
+ }
121
+ if (this.isAbsolute) {
122
+ const firstIndex = this.raw.indexOf(Path.separator);
123
+ if (firstIndex === lastIndex) {
124
+ return new Path(this.raw.substr(0, firstIndex + 1));
125
+ }
126
+ }
127
+ return new Path(this.raw.substr(0, lastIndex));
128
+ }
129
+ join(...paths) {
130
+ const code = this.raw.charCodeAt(0);
131
+ const isWindows = isWindowsDeviceRoot(code);
132
+ /**
133
+ * 只针对 IDE 后端运行在 Windows 的情况
134
+ * join('C:\\path\\to\\file', 'path/to/other') === 'C:\\path\\to\\file\\path\\to\\other'
135
+ */
136
+ if (isWindows) {
137
+ return new Path(exports.win32.join(this.raw, ...paths));
138
+ }
139
+ const relativePath = paths.filter((s) => !!s).join(Path.separator);
140
+ if (!relativePath) {
141
+ return this;
142
+ }
143
+ if (this.raw.endsWith(Path.separator)) {
144
+ return new Path(this.raw + relativePath);
145
+ }
146
+ return new Path(this.raw + Path.separator + relativePath);
147
+ }
148
+ toString() {
149
+ return this.raw;
150
+ }
151
+ relative(path) {
152
+ if (this.raw === path.raw) {
153
+ return new Path('');
154
+ }
155
+ if (!this.raw || !path.raw) {
156
+ return undefined;
157
+ }
158
+ const raw = this.base ? this.raw + Path.separator : this.raw;
159
+ if (!path.raw.startsWith(raw)) {
160
+ return undefined;
161
+ }
162
+ const relativePath = path.raw.substr(raw.length);
163
+ return new Path(relativePath);
164
+ }
165
+ isEqualOrParent(path) {
166
+ return !!this.relative(path);
167
+ }
168
+ isEqual(path) {
169
+ return this.raw === path.raw;
170
+ }
171
+ relativity(path) {
172
+ const relative = this.relative(path);
173
+ if (relative) {
174
+ const relativeStr = relative.toString();
175
+ if (relativeStr === '') {
176
+ return 0;
177
+ }
178
+ return relativeStr.split(Path.separator).length;
179
+ }
180
+ return -1;
181
+ }
182
+ }
183
+ exports.Path = Path;
184
+ Path.separator = '/';
185
+ const CHAR_UPPERCASE_A = 65; /* A */
186
+ const CHAR_LOWERCASE_A = 97; /* a */
187
+ const CHAR_UPPERCASE_Z = 90; /* Z */
188
+ const CHAR_LOWERCASE_Z = 122; /* z */
189
+ const CHAR_DOT = 46; /* . */
190
+ const CHAR_FORWARD_SLASH = 47; /* / */
191
+ const CHAR_BACKWARD_SLASH = 92; /* \ */
192
+ const CHAR_COLON = 58; /* : */
193
+ const CHAR_QUESTION_MARK = 63; /* ? */
194
+ class ErrorInvalidArgType extends Error {
195
+ constructor(name, expected, actual) {
196
+ // determiner: 'must be' or 'must not be'
197
+ let determiner;
198
+ if (typeof expected === 'string' && expected.indexOf('not ') === 0) {
199
+ determiner = 'must not be';
200
+ expected = expected.replace(/^not /, '');
201
+ }
202
+ else {
203
+ determiner = 'must be';
204
+ }
205
+ const type = name.indexOf('.') !== -1 ? 'property' : 'argument';
206
+ let msg = `The "${name}" ${type} ${determiner} of type ${expected}`;
207
+ msg += `. Received type ${typeof actual}`;
208
+ super(msg);
209
+ }
210
+ }
211
+ function validateString(value, name) {
212
+ if (typeof value !== 'string') {
213
+ throw new ErrorInvalidArgType(name, 'string', value);
214
+ }
215
+ }
216
+ function isPathSeparator(code) {
217
+ return code === CHAR_FORWARD_SLASH || code === CHAR_BACKWARD_SLASH;
218
+ }
219
+ function isPosixPathSeparator(code) {
220
+ return code === CHAR_FORWARD_SLASH;
221
+ }
222
+ function isWindowsDeviceRoot(code) {
223
+ return code >= CHAR_UPPERCASE_A && code <= CHAR_UPPERCASE_Z ||
224
+ code >= CHAR_LOWERCASE_A && code <= CHAR_LOWERCASE_Z;
225
+ }
226
+ // Resolves . and .. elements in a path with directory names
227
+ function normalizeString(path, allowAboveRoot, separator, isPathSeparator) {
228
+ let res = '';
229
+ let lastSegmentLength = 0;
230
+ let lastSlash = -1;
231
+ let dots = 0;
232
+ let code;
233
+ for (let i = 0; i <= path.length; ++i) {
234
+ if (i < path.length) {
235
+ code = path.charCodeAt(i);
236
+ }
237
+ else if (isPathSeparator(code)) {
238
+ break;
239
+ }
240
+ else {
241
+ code = CHAR_FORWARD_SLASH;
242
+ }
243
+ if (isPathSeparator(code)) {
244
+ if (lastSlash === i - 1 || dots === 1) {
245
+ // NOOP
246
+ }
247
+ else if (lastSlash !== i - 1 && dots === 2) {
248
+ if (res.length < 2 || lastSegmentLength !== 2 ||
249
+ res.charCodeAt(res.length - 1) !== CHAR_DOT ||
250
+ res.charCodeAt(res.length - 2) !== CHAR_DOT) {
251
+ if (res.length > 2) {
252
+ const lastSlashIndex = res.lastIndexOf(separator);
253
+ if (lastSlashIndex === -1) {
254
+ res = '';
255
+ lastSegmentLength = 0;
256
+ }
257
+ else {
258
+ res = res.slice(0, lastSlashIndex);
259
+ lastSegmentLength = res.length - 1 - res.lastIndexOf(separator);
260
+ }
261
+ lastSlash = i;
262
+ dots = 0;
263
+ continue;
264
+ }
265
+ else if (res.length === 2 || res.length === 1) {
266
+ res = '';
267
+ lastSegmentLength = 0;
268
+ lastSlash = i;
269
+ dots = 0;
270
+ continue;
271
+ }
272
+ }
273
+ if (allowAboveRoot) {
274
+ if (res.length > 0) {
275
+ res += `${separator}..`;
276
+ }
277
+ else {
278
+ res = '..';
279
+ }
280
+ lastSegmentLength = 2;
281
+ }
282
+ }
283
+ else {
284
+ if (res.length > 0) {
285
+ res += separator + path.slice(lastSlash + 1, i);
286
+ }
287
+ else {
288
+ res = path.slice(lastSlash + 1, i);
289
+ }
290
+ lastSegmentLength = i - lastSlash - 1;
291
+ }
292
+ lastSlash = i;
293
+ dots = 0;
294
+ }
295
+ else if (code === CHAR_DOT && dots !== -1) {
296
+ ++dots;
297
+ }
298
+ else {
299
+ dots = -1;
300
+ }
301
+ }
302
+ return res;
303
+ }
304
+ function _format(sep, pathObject) {
305
+ const dir = pathObject.dir || pathObject.root;
306
+ const base = pathObject.base ||
307
+ ((pathObject.name || '') + (pathObject.ext || ''));
308
+ if (!dir) {
309
+ return base;
310
+ }
311
+ if (dir === pathObject.root) {
312
+ return dir + base;
313
+ }
314
+ return dir + sep + base;
315
+ }
316
+ exports.win32 = {
317
+ // path.resolve([from ...], to)
318
+ resolve(...pathSegments) {
319
+ let resolvedDevice = '';
320
+ let resolvedTail = '';
321
+ let resolvedAbsolute = false;
322
+ for (let i = pathSegments.length - 1; i >= -1; i--) {
323
+ let path;
324
+ if (i >= 0) {
325
+ path = pathSegments[i];
326
+ }
327
+ else if (!resolvedDevice) {
328
+ path = process_1.Process.cwd();
329
+ }
330
+ else {
331
+ // Windows has the concept of drive-specific current working
332
+ // directories. If we've resolved a drive letter but not yet an
333
+ // absolute path, get cwd for that drive, or the process cwd if
334
+ // the drive cwd is not available. We're sure the device is not
335
+ // a UNC path at this points, because UNC paths are always absolute.
336
+ path = process_1.Process.env['=' + resolvedDevice] || process_1.Process.cwd();
337
+ // Verify that a cwd was found and that it actually points
338
+ // to our drive. If not, default to the drive's root.
339
+ if (path === undefined ||
340
+ path.slice(0, 3).toLowerCase() !==
341
+ resolvedDevice.toLowerCase() + '\\') {
342
+ path = resolvedDevice + '\\';
343
+ }
344
+ }
345
+ validateString(path, 'path');
346
+ // Skip empty entries
347
+ if (path.length === 0) {
348
+ continue;
349
+ }
350
+ const len = path.length;
351
+ let rootEnd = 0;
352
+ let device = '';
353
+ let isAbsolute = false;
354
+ const code = path.charCodeAt(0);
355
+ // Try to match a root
356
+ if (len > 1) {
357
+ if (isPathSeparator(code)) {
358
+ // Possible UNC root
359
+ // If we started with a separator, we know we at least have an
360
+ // absolute path of some kind (UNC or otherwise)
361
+ isAbsolute = true;
362
+ if (isPathSeparator(path.charCodeAt(1))) {
363
+ // Matched double path separator at beginning
364
+ let j = 2;
365
+ let last = j;
366
+ // Match 1 or more non-path separators
367
+ for (; j < len; ++j) {
368
+ if (isPathSeparator(path.charCodeAt(j))) {
369
+ break;
370
+ }
371
+ }
372
+ if (j < len && j !== last) {
373
+ const firstPart = path.slice(last, j);
374
+ // Matched!
375
+ last = j;
376
+ // Match 1 or more path separators
377
+ for (; j < len; ++j) {
378
+ if (!isPathSeparator(path.charCodeAt(j))) {
379
+ break;
380
+ }
381
+ }
382
+ if (j < len && j !== last) {
383
+ // Matched!
384
+ last = j;
385
+ // Match 1 or more non-path separators
386
+ for (; j < len; ++j) {
387
+ if (isPathSeparator(path.charCodeAt(j))) {
388
+ break;
389
+ }
390
+ }
391
+ if (j === len) {
392
+ // We matched a UNC root only
393
+ device = '\\\\' + firstPart + '\\' + path.slice(last);
394
+ rootEnd = j;
395
+ }
396
+ else if (j !== last) {
397
+ // We matched a UNC root with leftovers
398
+ device = '\\\\' + firstPart + '\\' + path.slice(last, j);
399
+ rootEnd = j;
400
+ }
401
+ }
402
+ }
403
+ }
404
+ else {
405
+ rootEnd = 1;
406
+ }
407
+ }
408
+ else if (isWindowsDeviceRoot(code)) {
409
+ // Possible device root
410
+ if (path.charCodeAt(1) === CHAR_COLON) {
411
+ device = path.slice(0, 2);
412
+ rootEnd = 2;
413
+ if (len > 2) {
414
+ if (isPathSeparator(path.charCodeAt(2))) {
415
+ // Treat separator following drive name as an absolute path
416
+ // indicator
417
+ isAbsolute = true;
418
+ rootEnd = 3;
419
+ }
420
+ }
421
+ }
422
+ }
423
+ }
424
+ else if (isPathSeparator(code)) {
425
+ // `path` contains just a path separator
426
+ rootEnd = 1;
427
+ isAbsolute = true;
428
+ }
429
+ if (device.length > 0 &&
430
+ resolvedDevice.length > 0 &&
431
+ device.toLowerCase() !== resolvedDevice.toLowerCase()) {
432
+ // This path points to another device so it is not applicable
433
+ continue;
434
+ }
435
+ if (resolvedDevice.length === 0 && device.length > 0) {
436
+ resolvedDevice = device;
437
+ }
438
+ if (!resolvedAbsolute) {
439
+ resolvedTail = path.slice(rootEnd) + '\\' + resolvedTail;
440
+ resolvedAbsolute = isAbsolute;
441
+ }
442
+ if (resolvedDevice.length > 0 && resolvedAbsolute) {
443
+ break;
444
+ }
445
+ }
446
+ // At this point the path should be resolved to a full absolute path,
447
+ // but handle relative paths to be safe (might happen when Process.cwd()
448
+ // fails)
449
+ // Normalize the tail path
450
+ resolvedTail = normalizeString(resolvedTail, !resolvedAbsolute, '\\', isPathSeparator);
451
+ return (resolvedDevice + (resolvedAbsolute ? '\\' : '') + resolvedTail) ||
452
+ '.';
453
+ },
454
+ normalize(path) {
455
+ validateString(path, 'path');
456
+ const len = path.length;
457
+ if (len === 0) {
458
+ return '.';
459
+ }
460
+ let rootEnd = 0;
461
+ let device;
462
+ let isAbsolute = false;
463
+ const code = path.charCodeAt(0);
464
+ // Try to match a root
465
+ if (len > 1) {
466
+ if (isPathSeparator(code)) {
467
+ // Possible UNC root
468
+ // If we started with a separator, we know we at least have an absolute
469
+ // path of some kind (UNC or otherwise)
470
+ isAbsolute = true;
471
+ if (isPathSeparator(path.charCodeAt(1))) {
472
+ // Matched double path separator at beginning
473
+ let j = 2;
474
+ let last = j;
475
+ // Match 1 or more non-path separators
476
+ for (; j < len; ++j) {
477
+ if (isPathSeparator(path.charCodeAt(j))) {
478
+ break;
479
+ }
480
+ }
481
+ if (j < len && j !== last) {
482
+ const firstPart = path.slice(last, j);
483
+ // Matched!
484
+ last = j;
485
+ // Match 1 or more path separators
486
+ for (; j < len; ++j) {
487
+ if (!isPathSeparator(path.charCodeAt(j))) {
488
+ break;
489
+ }
490
+ }
491
+ if (j < len && j !== last) {
492
+ // Matched!
493
+ last = j;
494
+ // Match 1 or more non-path separators
495
+ for (; j < len; ++j) {
496
+ if (isPathSeparator(path.charCodeAt(j))) {
497
+ break;
498
+ }
499
+ }
500
+ if (j === len) {
501
+ // We matched a UNC root only
502
+ // Return the normalized version of the UNC root since there
503
+ // is nothing left to process
504
+ return '\\\\' + firstPart + '\\' + path.slice(last) + '\\';
505
+ }
506
+ else if (j !== last) {
507
+ // We matched a UNC root with leftovers
508
+ device = '\\\\' + firstPart + '\\' + path.slice(last, j);
509
+ rootEnd = j;
510
+ }
511
+ }
512
+ }
513
+ }
514
+ else {
515
+ rootEnd = 1;
516
+ }
517
+ }
518
+ else if (isWindowsDeviceRoot(code)) {
519
+ // Possible device root
520
+ if (path.charCodeAt(1) === CHAR_COLON) {
521
+ device = path.slice(0, 2);
522
+ rootEnd = 2;
523
+ if (len > 2) {
524
+ if (isPathSeparator(path.charCodeAt(2))) {
525
+ // Treat separator following drive name as an absolute path
526
+ // indicator
527
+ isAbsolute = true;
528
+ rootEnd = 3;
529
+ }
530
+ }
531
+ }
532
+ }
533
+ }
534
+ else if (isPathSeparator(code)) {
535
+ // `path` contains just a path separator, exit early to avoid unnecessary
536
+ // work
537
+ return '\\';
538
+ }
539
+ let tail;
540
+ if (rootEnd < len) {
541
+ tail = normalizeString(path.slice(rootEnd), !isAbsolute, '\\', isPathSeparator);
542
+ }
543
+ else {
544
+ tail = '';
545
+ }
546
+ if (tail.length === 0 && !isAbsolute) {
547
+ tail = '.';
548
+ }
549
+ if (tail.length > 0 && isPathSeparator(path.charCodeAt(len - 1))) {
550
+ tail += '\\';
551
+ }
552
+ if (device === undefined) {
553
+ if (isAbsolute) {
554
+ if (tail.length > 0) {
555
+ return '\\' + tail;
556
+ }
557
+ else {
558
+ return '\\';
559
+ }
560
+ }
561
+ else if (tail.length > 0) {
562
+ return tail;
563
+ }
564
+ else {
565
+ return '';
566
+ }
567
+ }
568
+ else if (isAbsolute) {
569
+ if (tail.length > 0) {
570
+ return device + '\\' + tail;
571
+ }
572
+ else {
573
+ return device + '\\';
574
+ }
575
+ }
576
+ else if (tail.length > 0) {
577
+ return device + tail;
578
+ }
579
+ else {
580
+ return device;
581
+ }
582
+ },
583
+ isAbsolute(path) {
584
+ validateString(path, 'path');
585
+ const len = path.length;
586
+ if (len === 0) {
587
+ return false;
588
+ }
589
+ const code = path.charCodeAt(0);
590
+ if (isPathSeparator(code)) {
591
+ return true;
592
+ }
593
+ else if (isWindowsDeviceRoot(code)) {
594
+ // Possible device root
595
+ if (len > 2 && path.charCodeAt(1) === CHAR_COLON) {
596
+ if (isPathSeparator(path.charCodeAt(2))) {
597
+ return true;
598
+ }
599
+ }
600
+ }
601
+ return false;
602
+ },
603
+ join(...paths) {
604
+ if (paths.length === 0) {
605
+ return '.';
606
+ }
607
+ let joined;
608
+ let firstPart;
609
+ // tslint:disable-next-line:prefer-for-of
610
+ for (let i = 0; i < paths.length; ++i) {
611
+ const arg = paths[i];
612
+ validateString(arg, 'path');
613
+ if (arg.length > 0) {
614
+ if (joined === undefined) {
615
+ joined = firstPart = arg;
616
+ }
617
+ else {
618
+ joined += '\\' + arg;
619
+ }
620
+ }
621
+ }
622
+ if (joined === undefined) {
623
+ return '.';
624
+ }
625
+ // Make sure that the joined path doesn't start with two slashes, because
626
+ // normalize() will mistake it for an UNC path then.
627
+ //
628
+ // This step is skipped when it is very clear that the user actually
629
+ // intended to point at an UNC path. This is assumed when the first
630
+ // non-empty string arguments starts with exactly two slashes followed by
631
+ // at least one more non-slash character.
632
+ //
633
+ // Note that for normalize() to treat a path as an UNC path it needs to
634
+ // have at least 2 components, so we don't filter for that here.
635
+ // This means that the user can use join to construct UNC paths from
636
+ // a server name and a share name; for example:
637
+ // path.join('//server', 'share') -> '\\\\server\\share\\')
638
+ let needsReplace = true;
639
+ let slashCount = 0;
640
+ if (typeof firstPart === 'string' && isPathSeparator(firstPart.charCodeAt(0))) {
641
+ ++slashCount;
642
+ const firstLen = firstPart.length;
643
+ if (firstLen > 1) {
644
+ if (isPathSeparator(firstPart.charCodeAt(1))) {
645
+ ++slashCount;
646
+ if (firstLen > 2) {
647
+ if (isPathSeparator(firstPart.charCodeAt(2))) {
648
+ ++slashCount;
649
+ }
650
+ else {
651
+ // We matched a UNC path in the first part
652
+ needsReplace = false;
653
+ }
654
+ }
655
+ }
656
+ }
657
+ }
658
+ if (needsReplace) {
659
+ // Find any more consecutive slashes we need to replace
660
+ for (; slashCount < joined.length; ++slashCount) {
661
+ if (!isPathSeparator(joined.charCodeAt(slashCount))) {
662
+ break;
663
+ }
664
+ }
665
+ // Replace the slashes if needed
666
+ if (slashCount >= 2) {
667
+ joined = '\\' + joined.slice(slashCount);
668
+ }
669
+ }
670
+ return exports.win32.normalize(joined);
671
+ },
672
+ // It will solve the relative path from `from` to `to`, for instance:
673
+ // from = 'C:\\orandea\\test\\aaa'
674
+ // to = 'C:\\orandea\\impl\\bbb'
675
+ // The output of the function should be: '..\\..\\impl\\bbb'
676
+ relative(from, to) {
677
+ validateString(from, 'from');
678
+ validateString(to, 'to');
679
+ if (from === to) {
680
+ return '';
681
+ }
682
+ const fromOrig = exports.win32.resolve(from);
683
+ const toOrig = exports.win32.resolve(to);
684
+ if (fromOrig === toOrig) {
685
+ return '';
686
+ }
687
+ from = fromOrig.toLowerCase();
688
+ to = toOrig.toLowerCase();
689
+ if (from === to) {
690
+ return '';
691
+ }
692
+ // Trim any leading backslashes
693
+ let fromStart = 0;
694
+ for (; fromStart < from.length; ++fromStart) {
695
+ if (from.charCodeAt(fromStart) !== CHAR_BACKWARD_SLASH) {
696
+ break;
697
+ }
698
+ }
699
+ // Trim trailing backslashes (applicable to UNC paths only)
700
+ let fromEnd = from.length;
701
+ for (; fromEnd - 1 > fromStart; --fromEnd) {
702
+ if (from.charCodeAt(fromEnd - 1) !== CHAR_BACKWARD_SLASH) {
703
+ break;
704
+ }
705
+ }
706
+ const fromLen = (fromEnd - fromStart);
707
+ // Trim any leading backslashes
708
+ let toStart = 0;
709
+ for (; toStart < to.length; ++toStart) {
710
+ if (to.charCodeAt(toStart) !== CHAR_BACKWARD_SLASH) {
711
+ break;
712
+ }
713
+ }
714
+ // Trim trailing backslashes (applicable to UNC paths only)
715
+ let toEnd = to.length;
716
+ for (; toEnd - 1 > toStart; --toEnd) {
717
+ if (to.charCodeAt(toEnd - 1) !== CHAR_BACKWARD_SLASH) {
718
+ break;
719
+ }
720
+ }
721
+ const toLen = (toEnd - toStart);
722
+ // Compare paths to find the longest common path from root
723
+ const length = (fromLen < toLen ? fromLen : toLen);
724
+ let lastCommonSep = -1;
725
+ let i = 0;
726
+ for (; i <= length; ++i) {
727
+ if (i === length) {
728
+ if (toLen > length) {
729
+ if (to.charCodeAt(toStart + i) === CHAR_BACKWARD_SLASH) {
730
+ // We get here if `from` is the exact base path for `to`.
731
+ // For example: from='C:\\foo\\bar'; to='C:\\foo\\bar\\baz'
732
+ return toOrig.slice(toStart + i + 1);
733
+ }
734
+ else if (i === 2) {
735
+ // We get here if `from` is the device root.
736
+ // For example: from='C:\\'; to='C:\\foo'
737
+ return toOrig.slice(toStart + i);
738
+ }
739
+ }
740
+ if (fromLen > length) {
741
+ if (from.charCodeAt(fromStart + i) === CHAR_BACKWARD_SLASH) {
742
+ // We get here if `to` is the exact base path for `from`.
743
+ // For example: from='C:\\foo\\bar'; to='C:\\foo'
744
+ lastCommonSep = i;
745
+ }
746
+ else if (i === 2) {
747
+ // We get here if `to` is the device root.
748
+ // For example: from='C:\\foo\\bar'; to='C:\\'
749
+ lastCommonSep = 3;
750
+ }
751
+ }
752
+ break;
753
+ }
754
+ const fromCode = from.charCodeAt(fromStart + i);
755
+ const toCode = to.charCodeAt(toStart + i);
756
+ if (fromCode !== toCode) {
757
+ break;
758
+ }
759
+ else if (fromCode === CHAR_BACKWARD_SLASH) {
760
+ lastCommonSep = i;
761
+ }
762
+ }
763
+ // We found a mismatch before the first common path separator was seen, so
764
+ // return the original `to`.
765
+ if (i !== length && lastCommonSep === -1) {
766
+ return toOrig;
767
+ }
768
+ let out = '';
769
+ if (lastCommonSep === -1) {
770
+ lastCommonSep = 0;
771
+ }
772
+ // Generate the relative path based on the path difference between `to` and
773
+ // `from`
774
+ for (i = fromStart + lastCommonSep + 1; i <= fromEnd; ++i) {
775
+ if (i === fromEnd || from.charCodeAt(i) === CHAR_BACKWARD_SLASH) {
776
+ if (out.length === 0) {
777
+ out += '..';
778
+ }
779
+ else {
780
+ out += '\\..';
781
+ }
782
+ }
783
+ }
784
+ // Lastly, append the rest of the destination (`to`) path that comes after
785
+ // the common path parts
786
+ if (out.length > 0) {
787
+ return out + toOrig.slice(toStart + lastCommonSep, toEnd);
788
+ }
789
+ else {
790
+ toStart += lastCommonSep;
791
+ if (toOrig.charCodeAt(toStart) === CHAR_BACKWARD_SLASH) {
792
+ ++toStart;
793
+ }
794
+ return toOrig.slice(toStart, toEnd);
795
+ }
796
+ },
797
+ toNamespacedPath(path) {
798
+ // Note: this will *probably* throw somewhere.
799
+ if (typeof path !== 'string') {
800
+ return path;
801
+ }
802
+ if (path.length === 0) {
803
+ return '';
804
+ }
805
+ const resolvedPath = exports.win32.resolve(path);
806
+ if (resolvedPath.length >= 3) {
807
+ if (resolvedPath.charCodeAt(0) === CHAR_BACKWARD_SLASH) {
808
+ // Possible UNC root
809
+ if (resolvedPath.charCodeAt(1) === CHAR_BACKWARD_SLASH) {
810
+ const code = resolvedPath.charCodeAt(2);
811
+ if (code !== CHAR_QUESTION_MARK && code !== CHAR_DOT) {
812
+ // Matched non-long UNC root, convert the path to a long UNC path
813
+ return '\\\\?\\UNC\\' + resolvedPath.slice(2);
814
+ }
815
+ }
816
+ }
817
+ else if (isWindowsDeviceRoot(resolvedPath.charCodeAt(0))) {
818
+ // Possible device root
819
+ if (resolvedPath.charCodeAt(1) === CHAR_COLON &&
820
+ resolvedPath.charCodeAt(2) === CHAR_BACKWARD_SLASH) {
821
+ // Matched device root, convert the path to a long UNC path
822
+ return '\\\\?\\' + resolvedPath;
823
+ }
824
+ }
825
+ }
826
+ return path;
827
+ },
828
+ dirname(path) {
829
+ validateString(path, 'path');
830
+ const len = path.length;
831
+ if (len === 0) {
832
+ return '.';
833
+ }
834
+ let rootEnd = -1;
835
+ let end = -1;
836
+ let matchedSlash = true;
837
+ let offset = 0;
838
+ const code = path.charCodeAt(0);
839
+ // Try to match a root
840
+ if (len > 1) {
841
+ if (isPathSeparator(code)) {
842
+ // Possible UNC root
843
+ rootEnd = offset = 1;
844
+ if (isPathSeparator(path.charCodeAt(1))) {
845
+ // Matched double path separator at beginning
846
+ let j = 2;
847
+ let last = j;
848
+ // Match 1 or more non-path separators
849
+ for (; j < len; ++j) {
850
+ if (isPathSeparator(path.charCodeAt(j))) {
851
+ break;
852
+ }
853
+ }
854
+ if (j < len && j !== last) {
855
+ // Matched!
856
+ last = j;
857
+ // Match 1 or more path separators
858
+ for (; j < len; ++j) {
859
+ if (!isPathSeparator(path.charCodeAt(j))) {
860
+ break;
861
+ }
862
+ }
863
+ if (j < len && j !== last) {
864
+ // Matched!
865
+ last = j;
866
+ // Match 1 or more non-path separators
867
+ for (; j < len; ++j) {
868
+ if (isPathSeparator(path.charCodeAt(j))) {
869
+ break;
870
+ }
871
+ }
872
+ if (j === len) {
873
+ // We matched a UNC root only
874
+ return path;
875
+ }
876
+ if (j !== last) {
877
+ // We matched a UNC root with leftovers
878
+ // Offset by 1 to include the separator after the UNC root to
879
+ // treat it as a "normal root" on top of a (UNC) root
880
+ rootEnd = offset = j + 1;
881
+ }
882
+ }
883
+ }
884
+ }
885
+ }
886
+ else if (isWindowsDeviceRoot(code)) {
887
+ // Possible device root
888
+ if (path.charCodeAt(1) === CHAR_COLON) {
889
+ rootEnd = offset = 2;
890
+ if (len > 2) {
891
+ if (isPathSeparator(path.charCodeAt(2))) {
892
+ rootEnd = offset = 3;
893
+ }
894
+ }
895
+ }
896
+ }
897
+ }
898
+ else if (isPathSeparator(code)) {
899
+ // `path` contains just a path separator, exit early to avoid
900
+ // unnecessary work
901
+ return path;
902
+ }
903
+ for (let i = len - 1; i >= offset; --i) {
904
+ if (isPathSeparator(path.charCodeAt(i))) {
905
+ if (!matchedSlash) {
906
+ end = i;
907
+ break;
908
+ }
909
+ }
910
+ else {
911
+ // We saw the first non-path separator
912
+ matchedSlash = false;
913
+ }
914
+ }
915
+ if (end === -1) {
916
+ if (rootEnd === -1) {
917
+ return '.';
918
+ }
919
+ else {
920
+ end = rootEnd;
921
+ }
922
+ }
923
+ return path.slice(0, end);
924
+ },
925
+ basename(path, ext) {
926
+ if (ext !== undefined) {
927
+ validateString(ext, 'ext');
928
+ }
929
+ validateString(path, 'path');
930
+ let start = 0;
931
+ let end = -1;
932
+ let matchedSlash = true;
933
+ let i;
934
+ // Check for a drive letter prefix so as not to mistake the following
935
+ // path separator as an extra separator at the end of the path that can be
936
+ // disregarded
937
+ if (path.length >= 2) {
938
+ const drive = path.charCodeAt(0);
939
+ if (isWindowsDeviceRoot(drive)) {
940
+ if (path.charCodeAt(1) === CHAR_COLON) {
941
+ start = 2;
942
+ }
943
+ }
944
+ }
945
+ if (ext !== undefined && ext.length > 0 && ext.length <= path.length) {
946
+ if (ext.length === path.length && ext === path) {
947
+ return '';
948
+ }
949
+ let extIdx = ext.length - 1;
950
+ let firstNonSlashEnd = -1;
951
+ for (i = path.length - 1; i >= start; --i) {
952
+ const code = path.charCodeAt(i);
953
+ if (isPathSeparator(code)) {
954
+ // If we reached a path separator that was not part of a set of path
955
+ // separators at the end of the string, stop now
956
+ if (!matchedSlash) {
957
+ start = i + 1;
958
+ break;
959
+ }
960
+ }
961
+ else {
962
+ if (firstNonSlashEnd === -1) {
963
+ // We saw the first non-path separator, remember this index in case
964
+ // we need it if the extension ends up not matching
965
+ matchedSlash = false;
966
+ firstNonSlashEnd = i + 1;
967
+ }
968
+ if (extIdx >= 0) {
969
+ // Try to match the explicit extension
970
+ if (code === ext.charCodeAt(extIdx)) {
971
+ if (--extIdx === -1) {
972
+ // We matched the extension, so mark this as the end of our path
973
+ // component
974
+ end = i;
975
+ }
976
+ }
977
+ else {
978
+ // Extension does not match, so our result is the entire path
979
+ // component
980
+ extIdx = -1;
981
+ end = firstNonSlashEnd;
982
+ }
983
+ }
984
+ }
985
+ }
986
+ if (start === end) {
987
+ end = firstNonSlashEnd;
988
+ }
989
+ else if (end === -1) {
990
+ end = path.length;
991
+ }
992
+ return path.slice(start, end);
993
+ }
994
+ else {
995
+ for (i = path.length - 1; i >= start; --i) {
996
+ if (isPathSeparator(path.charCodeAt(i))) {
997
+ // If we reached a path separator that was not part of a set of path
998
+ // separators at the end of the string, stop now
999
+ if (!matchedSlash) {
1000
+ start = i + 1;
1001
+ break;
1002
+ }
1003
+ }
1004
+ else if (end === -1) {
1005
+ // We saw the first non-path separator, mark this as the end of our
1006
+ // path component
1007
+ matchedSlash = false;
1008
+ end = i + 1;
1009
+ }
1010
+ }
1011
+ if (end === -1) {
1012
+ return '';
1013
+ }
1014
+ return path.slice(start, end);
1015
+ }
1016
+ },
1017
+ extname(path) {
1018
+ validateString(path, 'path');
1019
+ let start = 0;
1020
+ let startDot = -1;
1021
+ let startPart = 0;
1022
+ let end = -1;
1023
+ let matchedSlash = true;
1024
+ // Track the state of characters (if any) we see before our first dot and
1025
+ // after any path separator we find
1026
+ let preDotState = 0;
1027
+ // Check for a drive letter prefix so as not to mistake the following
1028
+ // path separator as an extra separator at the end of the path that can be
1029
+ // disregarded
1030
+ if (path.length >= 2 &&
1031
+ path.charCodeAt(1) === CHAR_COLON &&
1032
+ isWindowsDeviceRoot(path.charCodeAt(0))) {
1033
+ start = startPart = 2;
1034
+ }
1035
+ for (let i = path.length - 1; i >= start; --i) {
1036
+ const code = path.charCodeAt(i);
1037
+ if (isPathSeparator(code)) {
1038
+ // If we reached a path separator that was not part of a set of path
1039
+ // separators at the end of the string, stop now
1040
+ if (!matchedSlash) {
1041
+ startPart = i + 1;
1042
+ break;
1043
+ }
1044
+ continue;
1045
+ }
1046
+ if (end === -1) {
1047
+ // We saw the first non-path separator, mark this as the end of our
1048
+ // extension
1049
+ matchedSlash = false;
1050
+ end = i + 1;
1051
+ }
1052
+ if (code === CHAR_DOT) {
1053
+ // If this is our first dot, mark it as the start of our extension
1054
+ if (startDot === -1) {
1055
+ startDot = i;
1056
+ }
1057
+ else if (preDotState !== 1) {
1058
+ preDotState = 1;
1059
+ }
1060
+ }
1061
+ else if (startDot !== -1) {
1062
+ // We saw a non-dot and non-path separator before our dot, so we should
1063
+ // have a good chance at having a non-empty extension
1064
+ preDotState = -1;
1065
+ }
1066
+ }
1067
+ if (startDot === -1 ||
1068
+ end === -1 ||
1069
+ // We saw a non-dot character immediately before the dot
1070
+ preDotState === 0 ||
1071
+ // The (right-most) trimmed path component is exactly '..'
1072
+ (preDotState === 1 &&
1073
+ startDot === end - 1 &&
1074
+ startDot === startPart + 1)) {
1075
+ return '';
1076
+ }
1077
+ return path.slice(startDot, end);
1078
+ },
1079
+ format(pathObject) {
1080
+ if (pathObject === null || typeof pathObject !== 'object') {
1081
+ throw new ErrorInvalidArgType('pathObject', 'Object', pathObject);
1082
+ }
1083
+ return _format('\\', pathObject);
1084
+ },
1085
+ parse(path) {
1086
+ validateString(path, 'path');
1087
+ const ret = { root: '', dir: '', base: '', ext: '', name: '' };
1088
+ if (path.length === 0) {
1089
+ return ret;
1090
+ }
1091
+ const len = path.length;
1092
+ let rootEnd = 0;
1093
+ let code = path.charCodeAt(0);
1094
+ // Try to match a root
1095
+ if (len > 1) {
1096
+ if (isPathSeparator(code)) {
1097
+ // Possible UNC root
1098
+ rootEnd = 1;
1099
+ if (isPathSeparator(path.charCodeAt(1))) {
1100
+ // Matched double path separator at beginning
1101
+ let j = 2;
1102
+ let last = j;
1103
+ // Match 1 or more non-path separators
1104
+ for (; j < len; ++j) {
1105
+ if (isPathSeparator(path.charCodeAt(j))) {
1106
+ break;
1107
+ }
1108
+ }
1109
+ if (j < len && j !== last) {
1110
+ // Matched!
1111
+ last = j;
1112
+ // Match 1 or more path separators
1113
+ for (; j < len; ++j) {
1114
+ if (!isPathSeparator(path.charCodeAt(j))) {
1115
+ break;
1116
+ }
1117
+ }
1118
+ if (j < len && j !== last) {
1119
+ // Matched!
1120
+ last = j;
1121
+ // Match 1 or more non-path separators
1122
+ for (; j < len; ++j) {
1123
+ if (isPathSeparator(path.charCodeAt(j))) {
1124
+ break;
1125
+ }
1126
+ }
1127
+ if (j === len) {
1128
+ // We matched a UNC root only
1129
+ rootEnd = j;
1130
+ }
1131
+ else if (j !== last) {
1132
+ // We matched a UNC root with leftovers
1133
+ rootEnd = j + 1;
1134
+ }
1135
+ }
1136
+ }
1137
+ }
1138
+ }
1139
+ else if (isWindowsDeviceRoot(code)) {
1140
+ // Possible device root
1141
+ if (path.charCodeAt(1) === CHAR_COLON) {
1142
+ rootEnd = 2;
1143
+ if (len > 2) {
1144
+ if (isPathSeparator(path.charCodeAt(2))) {
1145
+ if (len === 3) {
1146
+ // `path` contains just a drive root, exit early to avoid
1147
+ // unnecessary work
1148
+ ret.root = ret.dir = path;
1149
+ return ret;
1150
+ }
1151
+ rootEnd = 3;
1152
+ }
1153
+ }
1154
+ else {
1155
+ // `path` contains just a drive root, exit early to avoid
1156
+ // unnecessary work
1157
+ ret.root = ret.dir = path;
1158
+ return ret;
1159
+ }
1160
+ }
1161
+ }
1162
+ }
1163
+ else if (isPathSeparator(code)) {
1164
+ // `path` contains just a path separator, exit early to avoid
1165
+ // unnecessary work
1166
+ ret.root = ret.dir = path;
1167
+ return ret;
1168
+ }
1169
+ if (rootEnd > 0) {
1170
+ ret.root = path.slice(0, rootEnd);
1171
+ }
1172
+ let startDot = -1;
1173
+ let startPart = rootEnd;
1174
+ let end = -1;
1175
+ let matchedSlash = true;
1176
+ let i = path.length - 1;
1177
+ // Track the state of characters (if any) we see before our first dot and
1178
+ // after any path separator we find
1179
+ let preDotState = 0;
1180
+ // Get non-dir info
1181
+ for (; i >= rootEnd; --i) {
1182
+ code = path.charCodeAt(i);
1183
+ if (isPathSeparator(code)) {
1184
+ // If we reached a path separator that was not part of a set of path
1185
+ // separators at the end of the string, stop now
1186
+ if (!matchedSlash) {
1187
+ startPart = i + 1;
1188
+ break;
1189
+ }
1190
+ continue;
1191
+ }
1192
+ if (end === -1) {
1193
+ // We saw the first non-path separator, mark this as the end of our
1194
+ // extension
1195
+ matchedSlash = false;
1196
+ end = i + 1;
1197
+ }
1198
+ if (code === CHAR_DOT) {
1199
+ // If this is our first dot, mark it as the start of our extension
1200
+ if (startDot === -1) {
1201
+ startDot = i;
1202
+ }
1203
+ else if (preDotState !== 1) {
1204
+ preDotState = 1;
1205
+ }
1206
+ }
1207
+ else if (startDot !== -1) {
1208
+ // We saw a non-dot and non-path separator before our dot, so we should
1209
+ // have a good chance at having a non-empty extension
1210
+ preDotState = -1;
1211
+ }
1212
+ }
1213
+ if (startDot === -1 ||
1214
+ end === -1 ||
1215
+ // We saw a non-dot character immediately before the dot
1216
+ preDotState === 0 ||
1217
+ // The (right-most) trimmed path component is exactly '..'
1218
+ (preDotState === 1 &&
1219
+ startDot === end - 1 &&
1220
+ startDot === startPart + 1)) {
1221
+ if (end !== -1) {
1222
+ ret.base = ret.name = path.slice(startPart, end);
1223
+ }
1224
+ }
1225
+ else {
1226
+ ret.name = path.slice(startPart, startDot);
1227
+ ret.base = path.slice(startPart, end);
1228
+ ret.ext = path.slice(startDot, end);
1229
+ }
1230
+ // If the directory is the root, use the entire root as the `dir` including
1231
+ // the trailing slash if any (`C:\abc` -> `C:\`). Otherwise, strip out the
1232
+ // trailing slash (`C:\abc\def` -> `C:\abc`).
1233
+ if (startPart > 0 && startPart !== rootEnd) {
1234
+ ret.dir = path.slice(0, startPart - 1);
1235
+ }
1236
+ else {
1237
+ ret.dir = ret.root;
1238
+ }
1239
+ return ret;
1240
+ },
1241
+ sep: '\\',
1242
+ delimiter: ';',
1243
+ win32: null,
1244
+ posix: null,
1245
+ };
1246
+ exports.posix = {
1247
+ // path.resolve([from ...], to)
1248
+ resolve(...pathSegments) {
1249
+ let resolvedPath = '';
1250
+ let resolvedAbsolute = false;
1251
+ for (let i = pathSegments.length - 1; i >= -1 && !resolvedAbsolute; i--) {
1252
+ let path;
1253
+ if (i >= 0) {
1254
+ path = pathSegments[i];
1255
+ }
1256
+ else {
1257
+ path = process_1.Process.cwd();
1258
+ }
1259
+ validateString(path, 'path');
1260
+ // Skip empty entries
1261
+ if (path.length === 0) {
1262
+ continue;
1263
+ }
1264
+ resolvedPath = path + '/' + resolvedPath;
1265
+ resolvedAbsolute = path.charCodeAt(0) === CHAR_FORWARD_SLASH;
1266
+ }
1267
+ // At this point the path should be resolved to a full absolute path, but
1268
+ // handle relative paths to be safe (might happen when Process.cwd() fails)
1269
+ // Normalize the path
1270
+ resolvedPath = normalizeString(resolvedPath, !resolvedAbsolute, '/', isPosixPathSeparator);
1271
+ if (resolvedAbsolute) {
1272
+ if (resolvedPath.length > 0) {
1273
+ return '/' + resolvedPath;
1274
+ }
1275
+ else {
1276
+ return '/';
1277
+ }
1278
+ }
1279
+ else if (resolvedPath.length > 0) {
1280
+ return resolvedPath;
1281
+ }
1282
+ else {
1283
+ return '.';
1284
+ }
1285
+ },
1286
+ normalize(path) {
1287
+ validateString(path, 'path');
1288
+ if (path.length === 0) {
1289
+ return '.';
1290
+ }
1291
+ const isAbsolute = path.charCodeAt(0) === CHAR_FORWARD_SLASH;
1292
+ const trailingSeparator = path.charCodeAt(path.length - 1) === CHAR_FORWARD_SLASH;
1293
+ // Normalize the path
1294
+ path = normalizeString(path, !isAbsolute, '/', isPosixPathSeparator);
1295
+ if (path.length === 0 && !isAbsolute) {
1296
+ path = '.';
1297
+ }
1298
+ if (path.length > 0 && trailingSeparator) {
1299
+ path += '/';
1300
+ }
1301
+ if (isAbsolute) {
1302
+ return '/' + path;
1303
+ }
1304
+ return path;
1305
+ },
1306
+ isAbsolute(path) {
1307
+ validateString(path, 'path');
1308
+ return path.length > 0 && path.charCodeAt(0) === CHAR_FORWARD_SLASH;
1309
+ },
1310
+ join(...paths) {
1311
+ if (paths.length === 0) {
1312
+ return '.';
1313
+ }
1314
+ let joined;
1315
+ for (let i = 0; i < paths.length; ++i) {
1316
+ const arg = arguments[i];
1317
+ validateString(arg, 'path');
1318
+ if (arg.length > 0) {
1319
+ if (joined === undefined) {
1320
+ joined = arg;
1321
+ }
1322
+ else {
1323
+ joined += '/' + arg;
1324
+ }
1325
+ }
1326
+ }
1327
+ if (joined === undefined) {
1328
+ return '.';
1329
+ }
1330
+ return exports.posix.normalize(joined);
1331
+ },
1332
+ relative(from, to) {
1333
+ validateString(from, 'from');
1334
+ validateString(to, 'to');
1335
+ if (from === to) {
1336
+ return '';
1337
+ }
1338
+ from = exports.posix.resolve(from);
1339
+ to = exports.posix.resolve(to);
1340
+ if (from === to) {
1341
+ return '';
1342
+ }
1343
+ // Trim any leading backslashes
1344
+ let fromStart = 1;
1345
+ for (; fromStart < from.length; ++fromStart) {
1346
+ if (from.charCodeAt(fromStart) !== CHAR_FORWARD_SLASH) {
1347
+ break;
1348
+ }
1349
+ }
1350
+ const fromEnd = from.length;
1351
+ const fromLen = (fromEnd - fromStart);
1352
+ // Trim any leading backslashes
1353
+ let toStart = 1;
1354
+ for (; toStart < to.length; ++toStart) {
1355
+ if (to.charCodeAt(toStart) !== CHAR_FORWARD_SLASH) {
1356
+ break;
1357
+ }
1358
+ }
1359
+ const toEnd = to.length;
1360
+ const toLen = (toEnd - toStart);
1361
+ // Compare paths to find the longest common path from root
1362
+ const length = (fromLen < toLen ? fromLen : toLen);
1363
+ let lastCommonSep = -1;
1364
+ let i = 0;
1365
+ for (; i <= length; ++i) {
1366
+ if (i === length) {
1367
+ if (toLen > length) {
1368
+ if (to.charCodeAt(toStart + i) === CHAR_FORWARD_SLASH) {
1369
+ // We get here if `from` is the exact base path for `to`.
1370
+ // For example: from='/foo/bar'; to='/foo/bar/baz'
1371
+ return to.slice(toStart + i + 1);
1372
+ }
1373
+ else if (i === 0) {
1374
+ // We get here if `from` is the root
1375
+ // For example: from='/'; to='/foo'
1376
+ return to.slice(toStart + i);
1377
+ }
1378
+ }
1379
+ else if (fromLen > length) {
1380
+ if (from.charCodeAt(fromStart + i) === CHAR_FORWARD_SLASH) {
1381
+ // We get here if `to` is the exact base path for `from`.
1382
+ // For example: from='/foo/bar/baz'; to='/foo/bar'
1383
+ lastCommonSep = i;
1384
+ }
1385
+ else if (i === 0) {
1386
+ // We get here if `to` is the root.
1387
+ // For example: from='/foo'; to='/'
1388
+ lastCommonSep = 0;
1389
+ }
1390
+ }
1391
+ break;
1392
+ }
1393
+ const fromCode = from.charCodeAt(fromStart + i);
1394
+ const toCode = to.charCodeAt(toStart + i);
1395
+ if (fromCode !== toCode) {
1396
+ break;
1397
+ }
1398
+ else if (fromCode === CHAR_FORWARD_SLASH) {
1399
+ lastCommonSep = i;
1400
+ }
1401
+ }
1402
+ let out = '';
1403
+ // Generate the relative path based on the path difference between `to`
1404
+ // and `from`
1405
+ for (i = fromStart + lastCommonSep + 1; i <= fromEnd; ++i) {
1406
+ if (i === fromEnd || from.charCodeAt(i) === CHAR_FORWARD_SLASH) {
1407
+ if (out.length === 0) {
1408
+ out += '..';
1409
+ }
1410
+ else {
1411
+ out += '/..';
1412
+ }
1413
+ }
1414
+ }
1415
+ // Lastly, append the rest of the destination (`to`) path that comes after
1416
+ // the common path parts
1417
+ if (out.length > 0) {
1418
+ return out + to.slice(toStart + lastCommonSep);
1419
+ }
1420
+ else {
1421
+ toStart += lastCommonSep;
1422
+ if (to.charCodeAt(toStart) === CHAR_FORWARD_SLASH) {
1423
+ ++toStart;
1424
+ }
1425
+ return to.slice(toStart);
1426
+ }
1427
+ },
1428
+ toNamespacedPath(path) {
1429
+ // Non-op on posix systems
1430
+ return path;
1431
+ },
1432
+ dirname(path) {
1433
+ validateString(path, 'path');
1434
+ if (path.length === 0) {
1435
+ return '.';
1436
+ }
1437
+ const hasRoot = path.charCodeAt(0) === CHAR_FORWARD_SLASH;
1438
+ let end = -1;
1439
+ let matchedSlash = true;
1440
+ for (let i = path.length - 1; i >= 1; --i) {
1441
+ if (path.charCodeAt(i) === CHAR_FORWARD_SLASH) {
1442
+ if (!matchedSlash) {
1443
+ end = i;
1444
+ break;
1445
+ }
1446
+ }
1447
+ else {
1448
+ // We saw the first non-path separator
1449
+ matchedSlash = false;
1450
+ }
1451
+ }
1452
+ if (end === -1) {
1453
+ return hasRoot ? '/' : '.';
1454
+ }
1455
+ if (hasRoot && end === 1) {
1456
+ return '//';
1457
+ }
1458
+ return path.slice(0, end);
1459
+ },
1460
+ basename(path, ext) {
1461
+ if (ext !== undefined) {
1462
+ validateString(ext, 'ext');
1463
+ }
1464
+ validateString(path, 'path');
1465
+ let start = 0;
1466
+ let end = -1;
1467
+ let matchedSlash = true;
1468
+ let i;
1469
+ if (ext !== undefined && ext.length > 0 && ext.length <= path.length) {
1470
+ if (ext.length === path.length && ext === path) {
1471
+ return '';
1472
+ }
1473
+ let extIdx = ext.length - 1;
1474
+ let firstNonSlashEnd = -1;
1475
+ for (i = path.length - 1; i >= 0; --i) {
1476
+ const code = path.charCodeAt(i);
1477
+ if (code === CHAR_FORWARD_SLASH) {
1478
+ // If we reached a path separator that was not part of a set of path
1479
+ // separators at the end of the string, stop now
1480
+ if (!matchedSlash) {
1481
+ start = i + 1;
1482
+ break;
1483
+ }
1484
+ }
1485
+ else {
1486
+ if (firstNonSlashEnd === -1) {
1487
+ // We saw the first non-path separator, remember this index in case
1488
+ // we need it if the extension ends up not matching
1489
+ matchedSlash = false;
1490
+ firstNonSlashEnd = i + 1;
1491
+ }
1492
+ if (extIdx >= 0) {
1493
+ // Try to match the explicit extension
1494
+ if (code === ext.charCodeAt(extIdx)) {
1495
+ if (--extIdx === -1) {
1496
+ // We matched the extension, so mark this as the end of our path
1497
+ // component
1498
+ end = i;
1499
+ }
1500
+ }
1501
+ else {
1502
+ // Extension does not match, so our result is the entire path
1503
+ // component
1504
+ extIdx = -1;
1505
+ end = firstNonSlashEnd;
1506
+ }
1507
+ }
1508
+ }
1509
+ }
1510
+ if (start === end) {
1511
+ end = firstNonSlashEnd;
1512
+ }
1513
+ else if (end === -1) {
1514
+ end = path.length;
1515
+ }
1516
+ return path.slice(start, end);
1517
+ }
1518
+ else {
1519
+ for (i = path.length - 1; i >= 0; --i) {
1520
+ if (path.charCodeAt(i) === CHAR_FORWARD_SLASH) {
1521
+ // If we reached a path separator that was not part of a set of path
1522
+ // separators at the end of the string, stop now
1523
+ if (!matchedSlash) {
1524
+ start = i + 1;
1525
+ break;
1526
+ }
1527
+ }
1528
+ else if (end === -1) {
1529
+ // We saw the first non-path separator, mark this as the end of our
1530
+ // path component
1531
+ matchedSlash = false;
1532
+ end = i + 1;
1533
+ }
1534
+ }
1535
+ if (end === -1) {
1536
+ return '';
1537
+ }
1538
+ return path.slice(start, end);
1539
+ }
1540
+ },
1541
+ extname(path) {
1542
+ validateString(path, 'path');
1543
+ let startDot = -1;
1544
+ let startPart = 0;
1545
+ let end = -1;
1546
+ let matchedSlash = true;
1547
+ // Track the state of characters (if any) we see before our first dot and
1548
+ // after any path separator we find
1549
+ let preDotState = 0;
1550
+ for (let i = path.length - 1; i >= 0; --i) {
1551
+ const code = path.charCodeAt(i);
1552
+ if (code === CHAR_FORWARD_SLASH) {
1553
+ // If we reached a path separator that was not part of a set of path
1554
+ // separators at the end of the string, stop now
1555
+ if (!matchedSlash) {
1556
+ startPart = i + 1;
1557
+ break;
1558
+ }
1559
+ continue;
1560
+ }
1561
+ if (end === -1) {
1562
+ // We saw the first non-path separator, mark this as the end of our
1563
+ // extension
1564
+ matchedSlash = false;
1565
+ end = i + 1;
1566
+ }
1567
+ if (code === CHAR_DOT) {
1568
+ // If this is our first dot, mark it as the start of our extension
1569
+ if (startDot === -1) {
1570
+ startDot = i;
1571
+ }
1572
+ else if (preDotState !== 1) {
1573
+ preDotState = 1;
1574
+ }
1575
+ }
1576
+ else if (startDot !== -1) {
1577
+ // We saw a non-dot and non-path separator before our dot, so we should
1578
+ // have a good chance at having a non-empty extension
1579
+ preDotState = -1;
1580
+ }
1581
+ }
1582
+ if (startDot === -1 ||
1583
+ end === -1 ||
1584
+ // We saw a non-dot character immediately before the dot
1585
+ preDotState === 0 ||
1586
+ // The (right-most) trimmed path component is exactly '..'
1587
+ (preDotState === 1 &&
1588
+ startDot === end - 1 &&
1589
+ startDot === startPart + 1)) {
1590
+ return '';
1591
+ }
1592
+ return path.slice(startDot, end);
1593
+ },
1594
+ format(pathObject) {
1595
+ if (pathObject === null || typeof pathObject !== 'object') {
1596
+ throw new ErrorInvalidArgType('pathObject', 'Object', pathObject);
1597
+ }
1598
+ return _format('/', pathObject);
1599
+ },
1600
+ parse(path) {
1601
+ validateString(path, 'path');
1602
+ const ret = { root: '', dir: '', base: '', ext: '', name: '' };
1603
+ if (path.length === 0) {
1604
+ return ret;
1605
+ }
1606
+ const isAbsolute = path.charCodeAt(0) === CHAR_FORWARD_SLASH;
1607
+ let start;
1608
+ if (isAbsolute) {
1609
+ ret.root = '/';
1610
+ start = 1;
1611
+ }
1612
+ else {
1613
+ start = 0;
1614
+ }
1615
+ let startDot = -1;
1616
+ let startPart = 0;
1617
+ let end = -1;
1618
+ let matchedSlash = true;
1619
+ let i = path.length - 1;
1620
+ // Track the state of characters (if any) we see before our first dot and
1621
+ // after any path separator we find
1622
+ let preDotState = 0;
1623
+ // Get non-dir info
1624
+ for (; i >= start; --i) {
1625
+ const code = path.charCodeAt(i);
1626
+ if (code === CHAR_FORWARD_SLASH) {
1627
+ // If we reached a path separator that was not part of a set of path
1628
+ // separators at the end of the string, stop now
1629
+ if (!matchedSlash) {
1630
+ startPart = i + 1;
1631
+ break;
1632
+ }
1633
+ continue;
1634
+ }
1635
+ if (end === -1) {
1636
+ // We saw the first non-path separator, mark this as the end of our
1637
+ // extension
1638
+ matchedSlash = false;
1639
+ end = i + 1;
1640
+ }
1641
+ if (code === CHAR_DOT) {
1642
+ // If this is our first dot, mark it as the start of our extension
1643
+ if (startDot === -1) {
1644
+ startDot = i;
1645
+ }
1646
+ else if (preDotState !== 1) {
1647
+ preDotState = 1;
1648
+ }
1649
+ }
1650
+ else if (startDot !== -1) {
1651
+ // We saw a non-dot and non-path separator before our dot, so we should
1652
+ // have a good chance at having a non-empty extension
1653
+ preDotState = -1;
1654
+ }
1655
+ }
1656
+ if (startDot === -1 ||
1657
+ end === -1 ||
1658
+ // We saw a non-dot character immediately before the dot
1659
+ preDotState === 0 ||
1660
+ // The (right-most) trimmed path component is exactly '..'
1661
+ (preDotState === 1 &&
1662
+ startDot === end - 1 &&
1663
+ startDot === startPart + 1)) {
1664
+ if (end !== -1) {
1665
+ if (startPart === 0 && isAbsolute) {
1666
+ ret.base = ret.name = path.slice(1, end);
1667
+ }
1668
+ else {
1669
+ ret.base = ret.name = path.slice(startPart, end);
1670
+ }
1671
+ }
1672
+ }
1673
+ else {
1674
+ if (startPart === 0 && isAbsolute) {
1675
+ ret.name = path.slice(1, startDot);
1676
+ ret.base = path.slice(1, end);
1677
+ }
1678
+ else {
1679
+ ret.name = path.slice(startPart, startDot);
1680
+ ret.base = path.slice(startPart, end);
1681
+ }
1682
+ ret.ext = path.slice(startDot, end);
1683
+ }
1684
+ if (startPart > 0) {
1685
+ ret.dir = path.slice(0, startPart - 1);
1686
+ }
1687
+ else if (isAbsolute) {
1688
+ ret.dir = '/';
1689
+ }
1690
+ return ret;
1691
+ },
1692
+ sep: '/',
1693
+ delimiter: ':',
1694
+ win32: null,
1695
+ posix: null,
1696
+ };
1697
+ exports.posix.win32 = exports.win32.win32 = exports.win32;
1698
+ exports.posix.posix = exports.win32.posix = exports.posix;
1699
+ exports.normalize = (process_1.Process.platform === 'win32' ? exports.win32.normalize : exports.posix.normalize);
1700
+ exports.isAbsolute = (process_1.Process.platform === 'win32' ? exports.win32.isAbsolute : exports.posix.isAbsolute);
1701
+ exports.join = (process_1.Process.platform === 'win32' ? exports.win32.join : exports.posix.join);
1702
+ exports.resolve = (process_1.Process.platform === 'win32' ? exports.win32.resolve : exports.posix.resolve);
1703
+ exports.relative = (process_1.Process.platform === 'win32' ? exports.win32.relative : exports.posix.relative);
1704
+ exports.dirname = (process_1.Process.platform === 'win32' ? exports.win32.dirname : exports.posix.dirname);
1705
+ exports.basename = (process_1.Process.platform === 'win32' ? exports.win32.basename : exports.posix.basename);
1706
+ exports.extname = (process_1.Process.platform === 'win32' ? exports.win32.extname : exports.posix.extname);
1707
+ exports.format = (process_1.Process.platform === 'win32' ? exports.win32.format : exports.posix.format);
1708
+ exports.parse = (process_1.Process.platform === 'win32' ? exports.win32.parse : exports.posix.parse);
1709
+ exports.toNamespacedPath = (process_1.Process.platform === 'win32' ? exports.win32.toNamespacedPath : exports.posix.toNamespacedPath);
1710
+ exports.sep = (process_1.Process.platform === 'win32' ? exports.win32.sep : exports.posix.sep);
1711
+ exports.delimiter = (process_1.Process.platform === 'win32' ? exports.win32.delimiter : exports.posix.delimiter);
1712
+ //# sourceMappingURL=path.js.map