custom-electron-titlebar 3.2.6 → 3.2.10

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 (239) hide show
  1. package/.github/FUNDING.yml +1 -0
  2. package/README.md +15 -24
  3. package/_config.yml +1 -0
  4. package/{lib → build}/browser/browser.d.ts +0 -0
  5. package/{lib → build}/browser/browser.js +0 -0
  6. package/{lib → build}/browser/browser.js.map +0 -0
  7. package/{lib → build}/browser/event.d.ts +0 -0
  8. package/{lib → build}/browser/event.js +2 -1
  9. package/{lib → build}/browser/event.js.map +1 -1
  10. package/{lib → build}/browser/iframe.d.ts +0 -0
  11. package/{lib → build}/browser/iframe.js +0 -0
  12. package/{lib → build}/browser/iframe.js.map +0 -0
  13. package/{lib → build}/browser/keyboardEvent.d.ts +0 -0
  14. package/{lib → build}/browser/keyboardEvent.js +0 -0
  15. package/{lib → build}/browser/keyboardEvent.js.map +0 -0
  16. package/{lib → build}/browser/mouseEvent.d.ts +0 -0
  17. package/{lib → build}/browser/mouseEvent.js +0 -0
  18. package/{lib → build}/browser/mouseEvent.js.map +0 -0
  19. package/{lib → build}/common/arrays.d.ts +0 -0
  20. package/{lib → build}/common/arrays.js +0 -0
  21. package/{lib → build}/common/arrays.js.map +0 -0
  22. package/{lib → build}/common/async.d.ts +0 -0
  23. package/{lib → build}/common/async.js +0 -0
  24. package/{lib → build}/common/async.js.map +0 -0
  25. package/{lib → build}/common/charCode.d.ts +0 -0
  26. package/{lib → build}/common/charCode.js +0 -0
  27. package/{lib → build}/common/charCode.js.map +0 -0
  28. package/{lib → build}/common/color.d.ts +0 -0
  29. package/{lib → build}/common/color.js +0 -0
  30. package/{lib → build}/common/color.js.map +0 -0
  31. package/{lib → build}/common/dom.d.ts +0 -0
  32. package/{lib → build}/common/dom.js +16 -14
  33. package/build/common/dom.js.map +1 -0
  34. package/{lib → build}/common/event.d.ts +0 -0
  35. package/{lib → build}/common/event.js +1 -1
  36. package/build/common/event.js.map +1 -0
  37. package/{lib → build}/common/iterator.d.ts +0 -0
  38. package/{lib → build}/common/iterator.js +0 -0
  39. package/{lib → build}/common/iterator.js.map +0 -0
  40. package/{lib → build}/common/keyCodes.d.ts +0 -0
  41. package/{lib → build}/common/keyCodes.js +0 -0
  42. package/{lib → build}/common/keyCodes.js.map +0 -0
  43. package/{lib → build}/common/lifecycle.d.ts +0 -0
  44. package/{lib → build}/common/lifecycle.js +0 -0
  45. package/{lib → build}/common/lifecycle.js.map +0 -0
  46. package/{lib → build}/common/linkedList.d.ts +0 -0
  47. package/{lib → build}/common/linkedList.js +0 -0
  48. package/{lib → build}/common/linkedList.js.map +0 -0
  49. package/{lib → build}/common/platform.d.ts +0 -0
  50. package/{lib → build}/common/platform.js +0 -0
  51. package/{lib → build}/common/platform.js.map +0 -0
  52. package/{lib → build}/index.d.ts +0 -0
  53. package/{lib → build}/index.js +0 -0
  54. package/{lib → build}/index.js.map +0 -0
  55. package/{lib → build}/menu/menu.d.ts +0 -0
  56. package/{lib → build}/menu/menu.js +38 -38
  57. package/build/menu/menu.js.map +1 -0
  58. package/{lib → build}/menu/menuitem.d.ts +10 -2
  59. package/{lib → build}/menu/menuitem.js +70 -34
  60. package/build/menu/menuitem.js.map +1 -0
  61. package/{lib → build}/menubar.d.ts +0 -0
  62. package/{lib → build}/menubar.js +29 -30
  63. package/build/menubar.js.map +1 -0
  64. package/{lib → build}/themebar.d.ts +0 -0
  65. package/{lib → build}/themebar.js +2 -2
  66. package/build/themebar.js.map +1 -0
  67. package/{lib → build}/titlebar.d.ts +0 -0
  68. package/{lib → build}/titlebar.js +61 -58
  69. package/build/titlebar.js.map +1 -0
  70. package/package.json +13 -7
  71. package/lib/common/dom.js.map +0 -1
  72. package/lib/common/enableNativeMenuCommands.d.ts +0 -1
  73. package/lib/common/enableNativeMenuCommands.js +0 -32
  74. package/lib/common/enableNativeMenuCommands.js.map +0 -1
  75. package/lib/common/event.js.map +0 -1
  76. package/lib/main.d.ts +0 -1
  77. package/lib/main.js +0 -14
  78. package/lib/main.js.map +0 -1
  79. package/lib/menu/menu.js.map +0 -1
  80. package/lib/menu/menuitem.js.map +0 -1
  81. package/lib/menubar.js.map +0 -1
  82. package/lib/themebar.js.map +0 -1
  83. package/lib/titlebar.js.map +0 -1
  84. package/lib/vs/base/browser/browser.js +0 -150
  85. package/lib/vs/base/browser/canIUse.js +0 -58
  86. package/lib/vs/base/browser/codicons.js +0 -37
  87. package/lib/vs/base/browser/contextmenu.js +0 -9
  88. package/lib/vs/base/browser/dnd.js +0 -113
  89. package/lib/vs/base/browser/dom.js +0 -1417
  90. package/lib/vs/base/browser/event.js +0 -36
  91. package/lib/vs/base/browser/fastDomNode.js +0 -265
  92. package/lib/vs/base/browser/formattedTextRenderer.js +0 -248
  93. package/lib/vs/base/browser/globalMouseMoveMonitor.js +0 -137
  94. package/lib/vs/base/browser/history.js +0 -9
  95. package/lib/vs/base/browser/iframe.js +0 -126
  96. package/lib/vs/base/browser/keyboardEvent.js +0 -599
  97. package/lib/vs/base/browser/mouseEvent.js +0 -155
  98. package/lib/vs/base/browser/touch.js +0 -315
  99. package/lib/vs/base/browser/ui/actionbar/actionViewItems.js +0 -397
  100. package/lib/vs/base/browser/ui/actionbar/actionbar.js +0 -583
  101. package/lib/vs/base/browser/ui/checkbox/checkbox.js +0 -251
  102. package/lib/vs/base/browser/ui/codicons/codiconLabel.js +0 -31
  103. package/lib/vs/base/browser/ui/codicons/codiconStyles.js +0 -47
  104. package/lib/vs/base/browser/ui/contextview/contextview.js +0 -367
  105. package/lib/vs/base/browser/ui/dropdown/dropdown.js +0 -256
  106. package/lib/vs/base/browser/ui/dropdown/dropdownActionViewItem.js +0 -120
  107. package/lib/vs/base/browser/ui/keybindingLabel/keybindingLabel.js +0 -118
  108. package/lib/vs/base/browser/ui/list/list.js +0 -54
  109. package/lib/vs/base/browser/ui/list/listPaging.js +0 -322
  110. package/lib/vs/base/browser/ui/list/listView.js +0 -1388
  111. package/lib/vs/base/browser/ui/list/listWidget.js +0 -1709
  112. package/lib/vs/base/browser/ui/list/rangeMap.js +0 -223
  113. package/lib/vs/base/browser/ui/list/rowCache.js +0 -113
  114. package/lib/vs/base/browser/ui/list/splice.js +0 -23
  115. package/lib/vs/base/browser/ui/menu/menu.js +0 -1371
  116. package/lib/vs/base/browser/ui/menu/menubar.js +0 -1139
  117. package/lib/vs/base/browser/ui/scrollbar/abstractScrollbar.js +0 -278
  118. package/lib/vs/base/browser/ui/scrollbar/horizontalScrollbar.js +0 -115
  119. package/lib/vs/base/browser/ui/scrollbar/scrollableElement.js +0 -646
  120. package/lib/vs/base/browser/ui/scrollbar/scrollableElementOptions.js +0 -9
  121. package/lib/vs/base/browser/ui/scrollbar/scrollbarArrow.js +0 -106
  122. package/lib/vs/base/browser/ui/scrollbar/scrollbarState.js +0 -184
  123. package/lib/vs/base/browser/ui/scrollbar/scrollbarVisibilityController.js +0 -116
  124. package/lib/vs/base/browser/ui/scrollbar/verticalScrollbar.js +0 -114
  125. package/lib/vs/base/browser/ui/selectBox/selectBox.js +0 -85
  126. package/lib/vs/base/browser/ui/selectBox/selectBoxCustom.js +0 -985
  127. package/lib/vs/base/browser/ui/selectBox/selectBoxNative.js +0 -188
  128. package/lib/vs/base/browser/ui/toolbar/toolbar.js +0 -206
  129. package/lib/vs/base/browser/ui/widget.js +0 -69
  130. package/lib/vs/base/common/actions.js +0 -224
  131. package/lib/vs/base/common/amd.js +0 -31
  132. package/lib/vs/base/common/arrays.js +0 -641
  133. package/lib/vs/base/common/assert.js +0 -21
  134. package/lib/vs/base/common/async.js +0 -966
  135. package/lib/vs/base/common/buffer.js +0 -250
  136. package/lib/vs/base/common/cache.js +0 -40
  137. package/lib/vs/base/common/cancellation.js +0 -146
  138. package/lib/vs/base/common/charCode.js +0 -9
  139. package/lib/vs/base/common/codicon.js +0 -136
  140. package/lib/vs/base/common/codicons.js +0 -1378
  141. package/lib/vs/base/common/collections.js +0 -133
  142. package/lib/vs/base/common/color.js +0 -716
  143. package/lib/vs/base/common/comparers.js +0 -280
  144. package/lib/vs/base/common/console.js +0 -142
  145. package/lib/vs/base/common/date.js +0 -113
  146. package/lib/vs/base/common/decorators.js +0 -169
  147. package/lib/vs/base/common/errorMessage.js +0 -93
  148. package/lib/vs/base/common/errors.js +0 -213
  149. package/lib/vs/base/common/errorsWithActions.js +0 -28
  150. package/lib/vs/base/common/event.js +0 -873
  151. package/lib/vs/base/common/extpath.js +0 -401
  152. package/lib/vs/base/common/filters.js +0 -948
  153. package/lib/vs/base/common/functional.js +0 -28
  154. package/lib/vs/base/common/fuzzyScorer.js +0 -811
  155. package/lib/vs/base/common/glob.js +0 -696
  156. package/lib/vs/base/common/hash.js +0 -359
  157. package/lib/vs/base/common/history.js +0 -116
  158. package/lib/vs/base/common/htmlContent.js +0 -162
  159. package/lib/vs/base/common/idGenerator.js +0 -25
  160. package/lib/vs/base/common/iterator.js +0 -118
  161. package/lib/vs/base/common/json.js +0 -1624
  162. package/lib/vs/base/common/jsonEdit.js +0 -272
  163. package/lib/vs/base/common/jsonErrorMessages.js +0 -69
  164. package/lib/vs/base/common/jsonFormatter.js +0 -316
  165. package/lib/vs/base/common/jsonSchema.js +0 -9
  166. package/lib/vs/base/common/keyCodes.js +0 -591
  167. package/lib/vs/base/common/keybindingLabels.js +0 -231
  168. package/lib/vs/base/common/keybindingParser.js +0 -142
  169. package/lib/vs/base/common/labels.js +0 -430
  170. package/lib/vs/base/common/lazy.js +0 -71
  171. package/lib/vs/base/common/lifecycle.js +0 -308
  172. package/lib/vs/base/common/linkedList.js +0 -152
  173. package/lib/vs/base/common/linkedText.js +0 -73
  174. package/lib/vs/base/common/map.js +0 -1108
  175. package/lib/vs/base/common/marshalling.js +0 -80
  176. package/lib/vs/base/common/mime.js +0 -321
  177. package/lib/vs/base/common/navigator.js +0 -50
  178. package/lib/vs/base/common/network.js +0 -160
  179. package/lib/vs/base/common/normalization.js +0 -78
  180. package/lib/vs/base/common/numbers.js +0 -55
  181. package/lib/vs/base/common/objects.js +0 -268
  182. package/lib/vs/base/common/paging.js +0 -190
  183. package/lib/vs/base/common/parsers.js +0 -78
  184. package/lib/vs/base/common/path.js +0 -1550
  185. package/lib/vs/base/common/platform.js +0 -245
  186. package/lib/vs/base/common/process.js +0 -52
  187. package/lib/vs/base/common/processes.js +0 -32
  188. package/lib/vs/base/common/range.js +0 -79
  189. package/lib/vs/base/common/resourceTree.js +0 -185
  190. package/lib/vs/base/common/resources.js +0 -421
  191. package/lib/vs/base/common/scanCode.js +0 -1472
  192. package/lib/vs/base/common/scrollable.js +0 -397
  193. package/lib/vs/base/common/search.js +0 -55
  194. package/lib/vs/base/common/sequence.js +0 -64
  195. package/lib/vs/base/common/severity.js +0 -55
  196. package/lib/vs/base/common/skipList.js +0 -234
  197. package/lib/vs/base/common/stopwatch.js +0 -45
  198. package/lib/vs/base/common/stream.js +0 -418
  199. package/lib/vs/base/common/strings.js +0 -1283
  200. package/lib/vs/base/common/styler.js +0 -9
  201. package/lib/vs/base/common/types.js +0 -296
  202. package/lib/vs/base/common/uint.js +0 -46
  203. package/lib/vs/base/common/uri.js +0 -756
  204. package/lib/vs/base/common/uriIpc.js +0 -154
  205. package/lib/vs/base/common/uuid.js +0 -70
  206. package/lib/vs/nls.mock.js +0 -31
  207. package/lib/vs/platform/actions/browser/menuEntryActionViewItem.js +0 -342
  208. package/lib/vs/platform/actions/common/actions.js +0 -456
  209. package/lib/vs/platform/actions/common/menuService.js +0 -194
  210. package/lib/vs/platform/clipboard/browser/clipboardService.js +0 -99
  211. package/lib/vs/platform/clipboard/common/clipboardService.js +0 -14
  212. package/lib/vs/platform/contextkey/common/contextkey.js +0 -1210
  213. package/lib/vs/platform/contextkey/common/contextkeys.js +0 -23
  214. package/lib/vs/platform/contextview/browser/contextView.js +0 -15
  215. package/lib/vs/platform/contextview/browser/contextViewService.js +0 -96
  216. package/lib/vs/platform/environment/common/argv.js +0 -9
  217. package/lib/vs/platform/environment/common/environment.js +0 -15
  218. package/lib/vs/platform/instantiation/common/descriptors.js +0 -25
  219. package/lib/vs/platform/instantiation/common/extensions.js +0 -26
  220. package/lib/vs/platform/instantiation/common/graph.js +0 -93
  221. package/lib/vs/platform/instantiation/common/instantiation.js +0 -84
  222. package/lib/vs/platform/instantiation/common/instantiationService.js +0 -361
  223. package/lib/vs/platform/instantiation/common/serviceCollection.js +0 -39
  224. package/lib/vs/platform/keybinding/common/baseResolvedKeybinding.js +0 -73
  225. package/lib/vs/platform/keybinding/common/keybinding.js +0 -14
  226. package/lib/vs/platform/keybinding/common/keybindingResolver.js +0 -391
  227. package/lib/vs/platform/keybinding/common/keybindingsRegistry.js +0 -229
  228. package/lib/vs/platform/keybinding/common/resolvedKeybindingItem.js +0 -47
  229. package/lib/vs/platform/keybinding/common/usLayoutResolvedKeybinding.js +0 -160
  230. package/lib/vs/platform/layout/browser/layoutService.js +0 -14
  231. package/lib/vs/platform/menubar/common/menubar.js +0 -34
  232. package/lib/vs/platform/registry/common/platform.js +0 -38
  233. package/lib/vs/platform/theme/browser/checkbox.js +0 -32
  234. package/lib/vs/platform/theme/common/colorRegistry.js +0 -1154
  235. package/lib/vs/platform/theme/common/styler.js +0 -290
  236. package/lib/vs/platform/theme/common/theme.js +0 -21
  237. package/lib/vs/platform/theme/common/themeService.js +0 -176
  238. package/lib/vs/platform/theme/common/tokenClassificationRegistry.js +0 -540
  239. package/lib/vs/platform/theme/test/common/testThemeService.js +0 -98
@@ -1,1550 +0,0 @@
1
- "use strict";
2
- /*---------------------------------------------------------------------------------------------
3
- * Copyright (c) Microsoft Corporation. All rights reserved.
4
- * Licensed under the MIT License. See License.txt in the project root for license information.
5
- *--------------------------------------------------------------------------------------------*/
6
-
7
- Object.defineProperty(exports, "__esModule", {
8
- value: true
9
- });
10
- 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 = void 0; // NOTE: VSCode's copy of nodejs path library to be usable in common (non-node) namespace
11
- // Copied from: https://github.com/nodejs/node/blob/v12.8.1/lib/path.js
12
-
13
- /**
14
- * Copyright Joyent, Inc. and other Node contributors.
15
- *
16
- * Permission is hereby granted, free of charge, to any person obtaining a
17
- * copy of this software and associated documentation files (the
18
- * "Software"), to deal in the Software without restriction, including
19
- * without limitation the rights to use, copy, modify, merge, publish,
20
- * distribute, sublicense, and/or sell copies of the Software, and to permit
21
- * persons to whom the Software is furnished to do so, subject to the
22
- * following conditions:
23
- *
24
- * The above copyright notice and this permission notice shall be included
25
- * in all copies or substantial portions of the Software.
26
- *
27
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
28
- * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
29
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
30
- * NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
31
- * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
32
- * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
33
- * USE OR OTHER DEALINGS IN THE SOFTWARE.
34
- */
35
-
36
- const process = require("./process");
37
-
38
- const CHAR_UPPERCASE_A = 65;
39
- /* A */
40
-
41
- const CHAR_LOWERCASE_A = 97;
42
- /* a */
43
-
44
- const CHAR_UPPERCASE_Z = 90;
45
- /* Z */
46
-
47
- const CHAR_LOWERCASE_Z = 122;
48
- /* z */
49
-
50
- const CHAR_DOT = 46;
51
- /* . */
52
-
53
- const CHAR_FORWARD_SLASH = 47;
54
- /* / */
55
-
56
- const CHAR_BACKWARD_SLASH = 92;
57
- /* \ */
58
-
59
- const CHAR_COLON = 58;
60
- /* : */
61
-
62
- const CHAR_QUESTION_MARK = 63;
63
- /* ? */
64
-
65
- class ErrorInvalidArgType extends Error {
66
- constructor(name, expected, actual) {
67
- // determiner: 'must be' or 'must not be'
68
- let determiner;
69
-
70
- if (typeof expected === 'string' && expected.indexOf('not ') === 0) {
71
- determiner = 'must not be';
72
- expected = expected.replace(/^not /, '');
73
- } else {
74
- determiner = 'must be';
75
- }
76
-
77
- const type = name.indexOf('.') !== -1 ? 'property' : 'argument';
78
- let msg = `The "${name}" ${type} ${determiner} of type ${expected}`;
79
- msg += `. Received type ${typeof actual}`;
80
- super(msg);
81
- this.code = 'ERR_INVALID_ARG_TYPE';
82
- }
83
-
84
- }
85
-
86
- function validateString(value, name) {
87
- if (typeof value !== 'string') {
88
- throw new ErrorInvalidArgType(name, 'string', value);
89
- }
90
- }
91
-
92
- function isPathSeparator(code) {
93
- return code === CHAR_FORWARD_SLASH || code === CHAR_BACKWARD_SLASH;
94
- }
95
-
96
- function isPosixPathSeparator(code) {
97
- return code === CHAR_FORWARD_SLASH;
98
- }
99
-
100
- function isWindowsDeviceRoot(code) {
101
- return code >= CHAR_UPPERCASE_A && code <= CHAR_UPPERCASE_Z || code >= CHAR_LOWERCASE_A && code <= CHAR_LOWERCASE_Z;
102
- } // Resolves . and .. elements in a path with directory names
103
-
104
-
105
- function normalizeString(path, allowAboveRoot, separator, isPathSeparator) {
106
- let res = '';
107
- let lastSegmentLength = 0;
108
- let lastSlash = -1;
109
- let dots = 0;
110
- let code = 0;
111
-
112
- for (let i = 0; i <= path.length; ++i) {
113
- if (i < path.length) {
114
- code = path.charCodeAt(i);
115
- } else if (isPathSeparator(code)) {
116
- break;
117
- } else {
118
- code = CHAR_FORWARD_SLASH;
119
- }
120
-
121
- if (isPathSeparator(code)) {
122
- if (lastSlash === i - 1 || dots === 1) {// NOOP
123
- } else if (dots === 2) {
124
- if (res.length < 2 || lastSegmentLength !== 2 || res.charCodeAt(res.length - 1) !== CHAR_DOT || res.charCodeAt(res.length - 2) !== CHAR_DOT) {
125
- if (res.length > 2) {
126
- const lastSlashIndex = res.lastIndexOf(separator);
127
-
128
- if (lastSlashIndex === -1) {
129
- res = '';
130
- lastSegmentLength = 0;
131
- } else {
132
- res = res.slice(0, lastSlashIndex);
133
- lastSegmentLength = res.length - 1 - res.lastIndexOf(separator);
134
- }
135
-
136
- lastSlash = i;
137
- dots = 0;
138
- continue;
139
- } else if (res.length !== 0) {
140
- res = '';
141
- lastSegmentLength = 0;
142
- lastSlash = i;
143
- dots = 0;
144
- continue;
145
- }
146
- }
147
-
148
- if (allowAboveRoot) {
149
- res += res.length > 0 ? `${separator}..` : '..';
150
- lastSegmentLength = 2;
151
- }
152
- } else {
153
- if (res.length > 0) {
154
- res += `${separator}${path.slice(lastSlash + 1, i)}`;
155
- } else {
156
- res = path.slice(lastSlash + 1, i);
157
- }
158
-
159
- lastSegmentLength = i - lastSlash - 1;
160
- }
161
-
162
- lastSlash = i;
163
- dots = 0;
164
- } else if (code === CHAR_DOT && dots !== -1) {
165
- ++dots;
166
- } else {
167
- dots = -1;
168
- }
169
- }
170
-
171
- return res;
172
- }
173
-
174
- function _format(sep, pathObject) {
175
- if (pathObject === null || typeof pathObject !== 'object') {
176
- throw new ErrorInvalidArgType('pathObject', 'Object', pathObject);
177
- }
178
-
179
- const dir = pathObject.dir || pathObject.root;
180
- const base = pathObject.base || `${pathObject.name || ''}${pathObject.ext || ''}`;
181
-
182
- if (!dir) {
183
- return base;
184
- }
185
-
186
- return dir === pathObject.root ? `${dir}${base}` : `${dir}${sep}${base}`;
187
- }
188
-
189
- exports.win32 = {
190
- // path.resolve([from ...], to)
191
- resolve(...pathSegments) {
192
- let resolvedDevice = '';
193
- let resolvedTail = '';
194
- let resolvedAbsolute = false;
195
-
196
- for (let i = pathSegments.length - 1; i >= -1; i--) {
197
- let path;
198
-
199
- if (i >= 0) {
200
- path = pathSegments[i];
201
- validateString(path, 'path'); // Skip empty entries
202
-
203
- if (path.length === 0) {
204
- continue;
205
- }
206
- } else if (resolvedDevice.length === 0) {
207
- path = process.cwd();
208
- } else {
209
- // Windows has the concept of drive-specific current working
210
- // directories. If we've resolved a drive letter but not yet an
211
- // absolute path, get cwd for that drive, or the process cwd if
212
- // the drive cwd is not available. We're sure the device is not
213
- // a UNC path at this points, because UNC paths are always absolute.
214
- path = process.env[`=${resolvedDevice}`] || process.cwd(); // Verify that a cwd was found and that it actually points
215
- // to our drive. If not, default to the drive's root.
216
-
217
- if (path === undefined || path.slice(0, 2).toLowerCase() !== resolvedDevice.toLowerCase() && path.charCodeAt(2) === CHAR_BACKWARD_SLASH) {
218
- path = `${resolvedDevice}\\`;
219
- }
220
- }
221
-
222
- const len = path.length;
223
- let rootEnd = 0;
224
- let device = '';
225
- let isAbsolute = false;
226
- const code = path.charCodeAt(0); // Try to match a root
227
-
228
- if (len === 1) {
229
- if (isPathSeparator(code)) {
230
- // `path` contains just a path separator
231
- rootEnd = 1;
232
- isAbsolute = true;
233
- }
234
- } else if (isPathSeparator(code)) {
235
- // Possible UNC root
236
- // If we started with a separator, we know we at least have an
237
- // absolute path of some kind (UNC or otherwise)
238
- isAbsolute = true;
239
-
240
- if (isPathSeparator(path.charCodeAt(1))) {
241
- // Matched double path separator at beginning
242
- let j = 2;
243
- let last = j; // Match 1 or more non-path separators
244
-
245
- while (j < len && !isPathSeparator(path.charCodeAt(j))) {
246
- j++;
247
- }
248
-
249
- if (j < len && j !== last) {
250
- const firstPart = path.slice(last, j); // Matched!
251
-
252
- last = j; // Match 1 or more path separators
253
-
254
- while (j < len && isPathSeparator(path.charCodeAt(j))) {
255
- j++;
256
- }
257
-
258
- if (j < len && j !== last) {
259
- // Matched!
260
- last = j; // Match 1 or more non-path separators
261
-
262
- while (j < len && !isPathSeparator(path.charCodeAt(j))) {
263
- j++;
264
- }
265
-
266
- if (j === len || j !== last) {
267
- // We matched a UNC root
268
- device = `\\\\${firstPart}\\${path.slice(last, j)}`;
269
- rootEnd = j;
270
- }
271
- }
272
- }
273
- } else {
274
- rootEnd = 1;
275
- }
276
- } else if (isWindowsDeviceRoot(code) && path.charCodeAt(1) === CHAR_COLON) {
277
- // Possible device root
278
- device = path.slice(0, 2);
279
- rootEnd = 2;
280
-
281
- if (len > 2 && isPathSeparator(path.charCodeAt(2))) {
282
- // Treat separator following drive name as an absolute path
283
- // indicator
284
- isAbsolute = true;
285
- rootEnd = 3;
286
- }
287
- }
288
-
289
- if (device.length > 0) {
290
- if (resolvedDevice.length > 0) {
291
- if (device.toLowerCase() !== resolvedDevice.toLowerCase()) {
292
- // This path points to another device so it is not applicable
293
- continue;
294
- }
295
- } else {
296
- resolvedDevice = device;
297
- }
298
- }
299
-
300
- if (resolvedAbsolute) {
301
- if (resolvedDevice.length > 0) {
302
- break;
303
- }
304
- } else {
305
- resolvedTail = `${path.slice(rootEnd)}\\${resolvedTail}`;
306
- resolvedAbsolute = isAbsolute;
307
-
308
- if (isAbsolute && resolvedDevice.length > 0) {
309
- break;
310
- }
311
- }
312
- } // At this point the path should be resolved to a full absolute path,
313
- // but handle relative paths to be safe (might happen when process.cwd()
314
- // fails)
315
- // Normalize the tail path
316
-
317
-
318
- resolvedTail = normalizeString(resolvedTail, !resolvedAbsolute, '\\', isPathSeparator);
319
- return resolvedAbsolute ? `${resolvedDevice}\\${resolvedTail}` : `${resolvedDevice}${resolvedTail}` || '.';
320
- },
321
-
322
- normalize(path) {
323
- validateString(path, 'path');
324
- const len = path.length;
325
-
326
- if (len === 0) {
327
- return '.';
328
- }
329
-
330
- let rootEnd = 0;
331
- let device;
332
- let isAbsolute = false;
333
- const code = path.charCodeAt(0); // Try to match a root
334
-
335
- if (len === 1) {
336
- // `path` contains just a single char, exit early to avoid
337
- // unnecessary work
338
- return isPosixPathSeparator(code) ? '\\' : path;
339
- }
340
-
341
- if (isPathSeparator(code)) {
342
- // Possible UNC root
343
- // If we started with a separator, we know we at least have an absolute
344
- // path of some kind (UNC or otherwise)
345
- isAbsolute = true;
346
-
347
- if (isPathSeparator(path.charCodeAt(1))) {
348
- // Matched double path separator at beginning
349
- let j = 2;
350
- let last = j; // Match 1 or more non-path separators
351
-
352
- while (j < len && !isPathSeparator(path.charCodeAt(j))) {
353
- j++;
354
- }
355
-
356
- if (j < len && j !== last) {
357
- const firstPart = path.slice(last, j); // Matched!
358
-
359
- last = j; // Match 1 or more path separators
360
-
361
- while (j < len && isPathSeparator(path.charCodeAt(j))) {
362
- j++;
363
- }
364
-
365
- if (j < len && j !== last) {
366
- // Matched!
367
- last = j; // Match 1 or more non-path separators
368
-
369
- while (j < len && !isPathSeparator(path.charCodeAt(j))) {
370
- j++;
371
- }
372
-
373
- if (j === len) {
374
- // We matched a UNC root only
375
- // Return the normalized version of the UNC root since there
376
- // is nothing left to process
377
- return `\\\\${firstPart}\\${path.slice(last)}\\`;
378
- }
379
-
380
- if (j !== last) {
381
- // We matched a UNC root with leftovers
382
- device = `\\\\${firstPart}\\${path.slice(last, j)}`;
383
- rootEnd = j;
384
- }
385
- }
386
- }
387
- } else {
388
- rootEnd = 1;
389
- }
390
- } else if (isWindowsDeviceRoot(code) && path.charCodeAt(1) === CHAR_COLON) {
391
- // Possible device root
392
- device = path.slice(0, 2);
393
- rootEnd = 2;
394
-
395
- if (len > 2 && isPathSeparator(path.charCodeAt(2))) {
396
- // Treat separator following drive name as an absolute path
397
- // indicator
398
- isAbsolute = true;
399
- rootEnd = 3;
400
- }
401
- }
402
-
403
- let tail = rootEnd < len ? normalizeString(path.slice(rootEnd), !isAbsolute, '\\', isPathSeparator) : '';
404
-
405
- if (tail.length === 0 && !isAbsolute) {
406
- tail = '.';
407
- }
408
-
409
- if (tail.length > 0 && isPathSeparator(path.charCodeAt(len - 1))) {
410
- tail += '\\';
411
- }
412
-
413
- if (device === undefined) {
414
- return isAbsolute ? `\\${tail}` : tail;
415
- }
416
-
417
- return isAbsolute ? `${device}\\${tail}` : `${device}${tail}`;
418
- },
419
-
420
- isAbsolute(path) {
421
- validateString(path, 'path');
422
- const len = path.length;
423
-
424
- if (len === 0) {
425
- return false;
426
- }
427
-
428
- const code = path.charCodeAt(0);
429
- return isPathSeparator(code) || // Possible device root
430
- len > 2 && isWindowsDeviceRoot(code) && path.charCodeAt(1) === CHAR_COLON && isPathSeparator(path.charCodeAt(2));
431
- },
432
-
433
- join(...paths) {
434
- if (paths.length === 0) {
435
- return '.';
436
- }
437
-
438
- let joined;
439
- let firstPart;
440
-
441
- for (let i = 0; i < paths.length; ++i) {
442
- const arg = paths[i];
443
- validateString(arg, 'path');
444
-
445
- if (arg.length > 0) {
446
- if (joined === undefined) {
447
- joined = firstPart = arg;
448
- } else {
449
- joined += `\\${arg}`;
450
- }
451
- }
452
- }
453
-
454
- if (joined === undefined) {
455
- return '.';
456
- } // Make sure that the joined path doesn't start with two slashes, because
457
- // normalize() will mistake it for an UNC path then.
458
- //
459
- // This step is skipped when it is very clear that the user actually
460
- // intended to point at an UNC path. This is assumed when the first
461
- // non-empty string arguments starts with exactly two slashes followed by
462
- // at least one more non-slash character.
463
- //
464
- // Note that for normalize() to treat a path as an UNC path it needs to
465
- // have at least 2 components, so we don't filter for that here.
466
- // This means that the user can use join to construct UNC paths from
467
- // a server name and a share name; for example:
468
- // path.join('//server', 'share') -> '\\\\server\\share\\')
469
-
470
-
471
- let needsReplace = true;
472
- let slashCount = 0;
473
-
474
- if (typeof firstPart === 'string' && isPathSeparator(firstPart.charCodeAt(0))) {
475
- ++slashCount;
476
- const firstLen = firstPart.length;
477
-
478
- if (firstLen > 1 && isPathSeparator(firstPart.charCodeAt(1))) {
479
- ++slashCount;
480
-
481
- if (firstLen > 2) {
482
- if (isPathSeparator(firstPart.charCodeAt(2))) {
483
- ++slashCount;
484
- } else {
485
- // We matched a UNC path in the first part
486
- needsReplace = false;
487
- }
488
- }
489
- }
490
- }
491
-
492
- if (needsReplace) {
493
- // Find any more consecutive slashes we need to replace
494
- while (slashCount < joined.length && isPathSeparator(joined.charCodeAt(slashCount))) {
495
- slashCount++;
496
- } // Replace the slashes if needed
497
-
498
-
499
- if (slashCount >= 2) {
500
- joined = `\\${joined.slice(slashCount)}`;
501
- }
502
- }
503
-
504
- return exports.win32.normalize(joined);
505
- },
506
-
507
- // It will solve the relative path from `from` to `to`, for instance:
508
- // from = 'C:\\orandea\\test\\aaa'
509
- // to = 'C:\\orandea\\impl\\bbb'
510
- // The output of the function should be: '..\\..\\impl\\bbb'
511
- relative(from, to) {
512
- validateString(from, 'from');
513
- validateString(to, 'to');
514
-
515
- if (from === to) {
516
- return '';
517
- }
518
-
519
- const fromOrig = exports.win32.resolve(from);
520
- const toOrig = exports.win32.resolve(to);
521
-
522
- if (fromOrig === toOrig) {
523
- return '';
524
- }
525
-
526
- from = fromOrig.toLowerCase();
527
- to = toOrig.toLowerCase();
528
-
529
- if (from === to) {
530
- return '';
531
- } // Trim any leading backslashes
532
-
533
-
534
- let fromStart = 0;
535
-
536
- while (fromStart < from.length && from.charCodeAt(fromStart) === CHAR_BACKWARD_SLASH) {
537
- fromStart++;
538
- } // Trim trailing backslashes (applicable to UNC paths only)
539
-
540
-
541
- let fromEnd = from.length;
542
-
543
- while (fromEnd - 1 > fromStart && from.charCodeAt(fromEnd - 1) === CHAR_BACKWARD_SLASH) {
544
- fromEnd--;
545
- }
546
-
547
- const fromLen = fromEnd - fromStart; // Trim any leading backslashes
548
-
549
- let toStart = 0;
550
-
551
- while (toStart < to.length && to.charCodeAt(toStart) === CHAR_BACKWARD_SLASH) {
552
- toStart++;
553
- } // Trim trailing backslashes (applicable to UNC paths only)
554
-
555
-
556
- let toEnd = to.length;
557
-
558
- while (toEnd - 1 > toStart && to.charCodeAt(toEnd - 1) === CHAR_BACKWARD_SLASH) {
559
- toEnd--;
560
- }
561
-
562
- const toLen = toEnd - toStart; // Compare paths to find the longest common path from root
563
-
564
- const length = fromLen < toLen ? fromLen : toLen;
565
- let lastCommonSep = -1;
566
- let i = 0;
567
-
568
- for (; i < length; i++) {
569
- const fromCode = from.charCodeAt(fromStart + i);
570
-
571
- if (fromCode !== to.charCodeAt(toStart + i)) {
572
- break;
573
- } else if (fromCode === CHAR_BACKWARD_SLASH) {
574
- lastCommonSep = i;
575
- }
576
- } // We found a mismatch before the first common path separator was seen, so
577
- // return the original `to`.
578
-
579
-
580
- if (i !== length) {
581
- if (lastCommonSep === -1) {
582
- return toOrig;
583
- }
584
- } else {
585
- if (toLen > length) {
586
- if (to.charCodeAt(toStart + i) === CHAR_BACKWARD_SLASH) {
587
- // We get here if `from` is the exact base path for `to`.
588
- // For example: from='C:\\foo\\bar'; to='C:\\foo\\bar\\baz'
589
- return toOrig.slice(toStart + i + 1);
590
- }
591
-
592
- if (i === 2) {
593
- // We get here if `from` is the device root.
594
- // For example: from='C:\\'; to='C:\\foo'
595
- return toOrig.slice(toStart + i);
596
- }
597
- }
598
-
599
- if (fromLen > length) {
600
- if (from.charCodeAt(fromStart + i) === CHAR_BACKWARD_SLASH) {
601
- // We get here if `to` is the exact base path for `from`.
602
- // For example: from='C:\\foo\\bar'; to='C:\\foo'
603
- lastCommonSep = i;
604
- } else if (i === 2) {
605
- // We get here if `to` is the device root.
606
- // For example: from='C:\\foo\\bar'; to='C:\\'
607
- lastCommonSep = 3;
608
- }
609
- }
610
-
611
- if (lastCommonSep === -1) {
612
- lastCommonSep = 0;
613
- }
614
- }
615
-
616
- let out = ''; // Generate the relative path based on the path difference between `to` and
617
- // `from`
618
-
619
- for (i = fromStart + lastCommonSep + 1; i <= fromEnd; ++i) {
620
- if (i === fromEnd || from.charCodeAt(i) === CHAR_BACKWARD_SLASH) {
621
- out += out.length === 0 ? '..' : '\\..';
622
- }
623
- }
624
-
625
- toStart += lastCommonSep; // Lastly, append the rest of the destination (`to`) path that comes after
626
- // the common path parts
627
-
628
- if (out.length > 0) {
629
- return `${out}${toOrig.slice(toStart, toEnd)}`;
630
- }
631
-
632
- if (toOrig.charCodeAt(toStart) === CHAR_BACKWARD_SLASH) {
633
- ++toStart;
634
- }
635
-
636
- return toOrig.slice(toStart, toEnd);
637
- },
638
-
639
- toNamespacedPath(path) {
640
- // Note: this will *probably* throw somewhere.
641
- if (typeof path !== 'string') {
642
- return path;
643
- }
644
-
645
- if (path.length === 0) {
646
- return '';
647
- }
648
-
649
- const resolvedPath = exports.win32.resolve(path);
650
-
651
- if (resolvedPath.length <= 2) {
652
- return path;
653
- }
654
-
655
- if (resolvedPath.charCodeAt(0) === CHAR_BACKWARD_SLASH) {
656
- // Possible UNC root
657
- if (resolvedPath.charCodeAt(1) === CHAR_BACKWARD_SLASH) {
658
- const code = resolvedPath.charCodeAt(2);
659
-
660
- if (code !== CHAR_QUESTION_MARK && code !== CHAR_DOT) {
661
- // Matched non-long UNC root, convert the path to a long UNC path
662
- return `\\\\?\\UNC\\${resolvedPath.slice(2)}`;
663
- }
664
- }
665
- } else if (isWindowsDeviceRoot(resolvedPath.charCodeAt(0)) && resolvedPath.charCodeAt(1) === CHAR_COLON && resolvedPath.charCodeAt(2) === CHAR_BACKWARD_SLASH) {
666
- // Matched device root, convert the path to a long UNC path
667
- return `\\\\?\\${resolvedPath}`;
668
- }
669
-
670
- return path;
671
- },
672
-
673
- dirname(path) {
674
- validateString(path, 'path');
675
- const len = path.length;
676
-
677
- if (len === 0) {
678
- return '.';
679
- }
680
-
681
- let rootEnd = -1;
682
- let offset = 0;
683
- const code = path.charCodeAt(0);
684
-
685
- if (len === 1) {
686
- // `path` contains just a path separator, exit early to avoid
687
- // unnecessary work or a dot.
688
- return isPathSeparator(code) ? path : '.';
689
- } // Try to match a root
690
-
691
-
692
- if (isPathSeparator(code)) {
693
- // Possible UNC root
694
- rootEnd = offset = 1;
695
-
696
- if (isPathSeparator(path.charCodeAt(1))) {
697
- // Matched double path separator at beginning
698
- let j = 2;
699
- let last = j; // Match 1 or more non-path separators
700
-
701
- while (j < len && !isPathSeparator(path.charCodeAt(j))) {
702
- j++;
703
- }
704
-
705
- if (j < len && j !== last) {
706
- // Matched!
707
- last = j; // Match 1 or more path separators
708
-
709
- while (j < len && isPathSeparator(path.charCodeAt(j))) {
710
- j++;
711
- }
712
-
713
- if (j < len && j !== last) {
714
- // Matched!
715
- last = j; // Match 1 or more non-path separators
716
-
717
- while (j < len && !isPathSeparator(path.charCodeAt(j))) {
718
- j++;
719
- }
720
-
721
- if (j === len) {
722
- // We matched a UNC root only
723
- return path;
724
- }
725
-
726
- if (j !== last) {
727
- // We matched a UNC root with leftovers
728
- // Offset by 1 to include the separator after the UNC root to
729
- // treat it as a "normal root" on top of a (UNC) root
730
- rootEnd = offset = j + 1;
731
- }
732
- }
733
- }
734
- } // Possible device root
735
-
736
- } else if (isWindowsDeviceRoot(code) && path.charCodeAt(1) === CHAR_COLON) {
737
- rootEnd = len > 2 && isPathSeparator(path.charCodeAt(2)) ? 3 : 2;
738
- offset = rootEnd;
739
- }
740
-
741
- let end = -1;
742
- let matchedSlash = true;
743
-
744
- for (let i = len - 1; i >= offset; --i) {
745
- if (isPathSeparator(path.charCodeAt(i))) {
746
- if (!matchedSlash) {
747
- end = i;
748
- break;
749
- }
750
- } else {
751
- // We saw the first non-path separator
752
- matchedSlash = false;
753
- }
754
- }
755
-
756
- if (end === -1) {
757
- if (rootEnd === -1) {
758
- return '.';
759
- }
760
-
761
- end = rootEnd;
762
- }
763
-
764
- return path.slice(0, end);
765
- },
766
-
767
- basename(path, ext) {
768
- if (ext !== undefined) {
769
- validateString(ext, 'ext');
770
- }
771
-
772
- validateString(path, 'path');
773
- let start = 0;
774
- let end = -1;
775
- let matchedSlash = true;
776
- let i; // Check for a drive letter prefix so as not to mistake the following
777
- // path separator as an extra separator at the end of the path that can be
778
- // disregarded
779
-
780
- if (path.length >= 2 && isWindowsDeviceRoot(path.charCodeAt(0)) && path.charCodeAt(1) === CHAR_COLON) {
781
- start = 2;
782
- }
783
-
784
- if (ext !== undefined && ext.length > 0 && ext.length <= path.length) {
785
- if (ext === path) {
786
- return '';
787
- }
788
-
789
- let extIdx = ext.length - 1;
790
- let firstNonSlashEnd = -1;
791
-
792
- for (i = path.length - 1; i >= start; --i) {
793
- const code = path.charCodeAt(i);
794
-
795
- if (isPathSeparator(code)) {
796
- // If we reached a path separator that was not part of a set of path
797
- // separators at the end of the string, stop now
798
- if (!matchedSlash) {
799
- start = i + 1;
800
- break;
801
- }
802
- } else {
803
- if (firstNonSlashEnd === -1) {
804
- // We saw the first non-path separator, remember this index in case
805
- // we need it if the extension ends up not matching
806
- matchedSlash = false;
807
- firstNonSlashEnd = i + 1;
808
- }
809
-
810
- if (extIdx >= 0) {
811
- // Try to match the explicit extension
812
- if (code === ext.charCodeAt(extIdx)) {
813
- if (--extIdx === -1) {
814
- // We matched the extension, so mark this as the end of our path
815
- // component
816
- end = i;
817
- }
818
- } else {
819
- // Extension does not match, so our result is the entire path
820
- // component
821
- extIdx = -1;
822
- end = firstNonSlashEnd;
823
- }
824
- }
825
- }
826
- }
827
-
828
- if (start === end) {
829
- end = firstNonSlashEnd;
830
- } else if (end === -1) {
831
- end = path.length;
832
- }
833
-
834
- return path.slice(start, end);
835
- }
836
-
837
- for (i = path.length - 1; i >= start; --i) {
838
- if (isPathSeparator(path.charCodeAt(i))) {
839
- // If we reached a path separator that was not part of a set of path
840
- // separators at the end of the string, stop now
841
- if (!matchedSlash) {
842
- start = i + 1;
843
- break;
844
- }
845
- } else if (end === -1) {
846
- // We saw the first non-path separator, mark this as the end of our
847
- // path component
848
- matchedSlash = false;
849
- end = i + 1;
850
- }
851
- }
852
-
853
- if (end === -1) {
854
- return '';
855
- }
856
-
857
- return path.slice(start, end);
858
- },
859
-
860
- extname(path) {
861
- validateString(path, 'path');
862
- let start = 0;
863
- let startDot = -1;
864
- let startPart = 0;
865
- let end = -1;
866
- let matchedSlash = true; // Track the state of characters (if any) we see before our first dot and
867
- // after any path separator we find
868
-
869
- let preDotState = 0; // Check for a drive letter prefix so as not to mistake the following
870
- // path separator as an extra separator at the end of the path that can be
871
- // disregarded
872
-
873
- if (path.length >= 2 && path.charCodeAt(1) === CHAR_COLON && isWindowsDeviceRoot(path.charCodeAt(0))) {
874
- start = startPart = 2;
875
- }
876
-
877
- for (let i = path.length - 1; i >= start; --i) {
878
- const code = path.charCodeAt(i);
879
-
880
- if (isPathSeparator(code)) {
881
- // If we reached a path separator that was not part of a set of path
882
- // separators at the end of the string, stop now
883
- if (!matchedSlash) {
884
- startPart = i + 1;
885
- break;
886
- }
887
-
888
- continue;
889
- }
890
-
891
- if (end === -1) {
892
- // We saw the first non-path separator, mark this as the end of our
893
- // extension
894
- matchedSlash = false;
895
- end = i + 1;
896
- }
897
-
898
- if (code === CHAR_DOT) {
899
- // If this is our first dot, mark it as the start of our extension
900
- if (startDot === -1) {
901
- startDot = i;
902
- } else if (preDotState !== 1) {
903
- preDotState = 1;
904
- }
905
- } else if (startDot !== -1) {
906
- // We saw a non-dot and non-path separator before our dot, so we should
907
- // have a good chance at having a non-empty extension
908
- preDotState = -1;
909
- }
910
- }
911
-
912
- if (startDot === -1 || end === -1 || // We saw a non-dot character immediately before the dot
913
- preDotState === 0 || // The (right-most) trimmed path component is exactly '..'
914
- preDotState === 1 && startDot === end - 1 && startDot === startPart + 1) {
915
- return '';
916
- }
917
-
918
- return path.slice(startDot, end);
919
- },
920
-
921
- format: _format.bind(null, '\\'),
922
-
923
- parse(path) {
924
- validateString(path, 'path');
925
- const ret = {
926
- root: '',
927
- dir: '',
928
- base: '',
929
- ext: '',
930
- name: ''
931
- };
932
-
933
- if (path.length === 0) {
934
- return ret;
935
- }
936
-
937
- const len = path.length;
938
- let rootEnd = 0;
939
- let code = path.charCodeAt(0);
940
-
941
- if (len === 1) {
942
- if (isPathSeparator(code)) {
943
- // `path` contains just a path separator, exit early to avoid
944
- // unnecessary work
945
- ret.root = ret.dir = path;
946
- return ret;
947
- }
948
-
949
- ret.base = ret.name = path;
950
- return ret;
951
- } // Try to match a root
952
-
953
-
954
- if (isPathSeparator(code)) {
955
- // Possible UNC root
956
- rootEnd = 1;
957
-
958
- if (isPathSeparator(path.charCodeAt(1))) {
959
- // Matched double path separator at beginning
960
- let j = 2;
961
- let last = j; // Match 1 or more non-path separators
962
-
963
- while (j < len && !isPathSeparator(path.charCodeAt(j))) {
964
- j++;
965
- }
966
-
967
- if (j < len && j !== last) {
968
- // Matched!
969
- last = j; // Match 1 or more path separators
970
-
971
- while (j < len && isPathSeparator(path.charCodeAt(j))) {
972
- j++;
973
- }
974
-
975
- if (j < len && j !== last) {
976
- // Matched!
977
- last = j; // Match 1 or more non-path separators
978
-
979
- while (j < len && !isPathSeparator(path.charCodeAt(j))) {
980
- j++;
981
- }
982
-
983
- if (j === len) {
984
- // We matched a UNC root only
985
- rootEnd = j;
986
- } else if (j !== last) {
987
- // We matched a UNC root with leftovers
988
- rootEnd = j + 1;
989
- }
990
- }
991
- }
992
- }
993
- } else if (isWindowsDeviceRoot(code) && path.charCodeAt(1) === CHAR_COLON) {
994
- // Possible device root
995
- if (len <= 2) {
996
- // `path` contains just a drive root, exit early to avoid
997
- // unnecessary work
998
- ret.root = ret.dir = path;
999
- return ret;
1000
- }
1001
-
1002
- rootEnd = 2;
1003
-
1004
- if (isPathSeparator(path.charCodeAt(2))) {
1005
- if (len === 3) {
1006
- // `path` contains just a drive root, exit early to avoid
1007
- // unnecessary work
1008
- ret.root = ret.dir = path;
1009
- return ret;
1010
- }
1011
-
1012
- rootEnd = 3;
1013
- }
1014
- }
1015
-
1016
- if (rootEnd > 0) {
1017
- ret.root = path.slice(0, rootEnd);
1018
- }
1019
-
1020
- let startDot = -1;
1021
- let startPart = rootEnd;
1022
- let end = -1;
1023
- let matchedSlash = true;
1024
- let i = path.length - 1; // Track the state of characters (if any) we see before our first dot and
1025
- // after any path separator we find
1026
-
1027
- let preDotState = 0; // Get non-dir info
1028
-
1029
- for (; i >= rootEnd; --i) {
1030
- code = path.charCodeAt(i);
1031
-
1032
- if (isPathSeparator(code)) {
1033
- // If we reached a path separator that was not part of a set of path
1034
- // separators at the end of the string, stop now
1035
- if (!matchedSlash) {
1036
- startPart = i + 1;
1037
- break;
1038
- }
1039
-
1040
- continue;
1041
- }
1042
-
1043
- if (end === -1) {
1044
- // We saw the first non-path separator, mark this as the end of our
1045
- // extension
1046
- matchedSlash = false;
1047
- end = i + 1;
1048
- }
1049
-
1050
- if (code === CHAR_DOT) {
1051
- // If this is our first dot, mark it as the start of our extension
1052
- if (startDot === -1) {
1053
- startDot = i;
1054
- } else if (preDotState !== 1) {
1055
- preDotState = 1;
1056
- }
1057
- } else if (startDot !== -1) {
1058
- // We saw a non-dot and non-path separator before our dot, so we should
1059
- // have a good chance at having a non-empty extension
1060
- preDotState = -1;
1061
- }
1062
- }
1063
-
1064
- if (end !== -1) {
1065
- if (startDot === -1 || // We saw a non-dot character immediately before the dot
1066
- preDotState === 0 || // The (right-most) trimmed path component is exactly '..'
1067
- preDotState === 1 && startDot === end - 1 && startDot === startPart + 1) {
1068
- ret.base = ret.name = path.slice(startPart, end);
1069
- } else {
1070
- ret.name = path.slice(startPart, startDot);
1071
- ret.base = path.slice(startPart, end);
1072
- ret.ext = path.slice(startDot, end);
1073
- }
1074
- } // If the directory is the root, use the entire root as the `dir` including
1075
- // the trailing slash if any (`C:\abc` -> `C:\`). Otherwise, strip out the
1076
- // trailing slash (`C:\abc\def` -> `C:\abc`).
1077
-
1078
-
1079
- if (startPart > 0 && startPart !== rootEnd) {
1080
- ret.dir = path.slice(0, startPart - 1);
1081
- } else {
1082
- ret.dir = ret.root;
1083
- }
1084
-
1085
- return ret;
1086
- },
1087
-
1088
- sep: '\\',
1089
- delimiter: ';',
1090
- win32: null,
1091
- posix: null
1092
- };
1093
- exports.posix = {
1094
- // path.resolve([from ...], to)
1095
- resolve(...pathSegments) {
1096
- let resolvedPath = '';
1097
- let resolvedAbsolute = false;
1098
-
1099
- for (let i = pathSegments.length - 1; i >= -1 && !resolvedAbsolute; i--) {
1100
- const path = i >= 0 ? pathSegments[i] : process.cwd();
1101
- validateString(path, 'path'); // Skip empty entries
1102
-
1103
- if (path.length === 0) {
1104
- continue;
1105
- }
1106
-
1107
- resolvedPath = `${path}/${resolvedPath}`;
1108
- resolvedAbsolute = path.charCodeAt(0) === CHAR_FORWARD_SLASH;
1109
- } // At this point the path should be resolved to a full absolute path, but
1110
- // handle relative paths to be safe (might happen when process.cwd() fails)
1111
- // Normalize the path
1112
-
1113
-
1114
- resolvedPath = normalizeString(resolvedPath, !resolvedAbsolute, '/', isPosixPathSeparator);
1115
-
1116
- if (resolvedAbsolute) {
1117
- return `/${resolvedPath}`;
1118
- }
1119
-
1120
- return resolvedPath.length > 0 ? resolvedPath : '.';
1121
- },
1122
-
1123
- normalize(path) {
1124
- validateString(path, 'path');
1125
-
1126
- if (path.length === 0) {
1127
- return '.';
1128
- }
1129
-
1130
- const isAbsolute = path.charCodeAt(0) === CHAR_FORWARD_SLASH;
1131
- const trailingSeparator = path.charCodeAt(path.length - 1) === CHAR_FORWARD_SLASH; // Normalize the path
1132
-
1133
- path = normalizeString(path, !isAbsolute, '/', isPosixPathSeparator);
1134
-
1135
- if (path.length === 0) {
1136
- if (isAbsolute) {
1137
- return '/';
1138
- }
1139
-
1140
- return trailingSeparator ? './' : '.';
1141
- }
1142
-
1143
- if (trailingSeparator) {
1144
- path += '/';
1145
- }
1146
-
1147
- return isAbsolute ? `/${path}` : path;
1148
- },
1149
-
1150
- isAbsolute(path) {
1151
- validateString(path, 'path');
1152
- return path.length > 0 && path.charCodeAt(0) === CHAR_FORWARD_SLASH;
1153
- },
1154
-
1155
- join(...paths) {
1156
- if (paths.length === 0) {
1157
- return '.';
1158
- }
1159
-
1160
- let joined;
1161
-
1162
- for (let i = 0; i < paths.length; ++i) {
1163
- const arg = paths[i];
1164
- validateString(arg, 'path');
1165
-
1166
- if (arg.length > 0) {
1167
- if (joined === undefined) {
1168
- joined = arg;
1169
- } else {
1170
- joined += `/${arg}`;
1171
- }
1172
- }
1173
- }
1174
-
1175
- if (joined === undefined) {
1176
- return '.';
1177
- }
1178
-
1179
- return exports.posix.normalize(joined);
1180
- },
1181
-
1182
- relative(from, to) {
1183
- validateString(from, 'from');
1184
- validateString(to, 'to');
1185
-
1186
- if (from === to) {
1187
- return '';
1188
- } // Trim leading forward slashes.
1189
-
1190
-
1191
- from = exports.posix.resolve(from);
1192
- to = exports.posix.resolve(to);
1193
-
1194
- if (from === to) {
1195
- return '';
1196
- }
1197
-
1198
- const fromStart = 1;
1199
- const fromEnd = from.length;
1200
- const fromLen = fromEnd - fromStart;
1201
- const toStart = 1;
1202
- const toLen = to.length - toStart; // Compare paths to find the longest common path from root
1203
-
1204
- const length = fromLen < toLen ? fromLen : toLen;
1205
- let lastCommonSep = -1;
1206
- let i = 0;
1207
-
1208
- for (; i < length; i++) {
1209
- const fromCode = from.charCodeAt(fromStart + i);
1210
-
1211
- if (fromCode !== to.charCodeAt(toStart + i)) {
1212
- break;
1213
- } else if (fromCode === CHAR_FORWARD_SLASH) {
1214
- lastCommonSep = i;
1215
- }
1216
- }
1217
-
1218
- if (i === length) {
1219
- if (toLen > length) {
1220
- if (to.charCodeAt(toStart + i) === CHAR_FORWARD_SLASH) {
1221
- // We get here if `from` is the exact base path for `to`.
1222
- // For example: from='/foo/bar'; to='/foo/bar/baz'
1223
- return to.slice(toStart + i + 1);
1224
- }
1225
-
1226
- if (i === 0) {
1227
- // We get here if `from` is the root
1228
- // For example: from='/'; to='/foo'
1229
- return to.slice(toStart + i);
1230
- }
1231
- } else if (fromLen > length) {
1232
- if (from.charCodeAt(fromStart + i) === CHAR_FORWARD_SLASH) {
1233
- // We get here if `to` is the exact base path for `from`.
1234
- // For example: from='/foo/bar/baz'; to='/foo/bar'
1235
- lastCommonSep = i;
1236
- } else if (i === 0) {
1237
- // We get here if `to` is the root.
1238
- // For example: from='/foo/bar'; to='/'
1239
- lastCommonSep = 0;
1240
- }
1241
- }
1242
- }
1243
-
1244
- let out = ''; // Generate the relative path based on the path difference between `to`
1245
- // and `from`.
1246
-
1247
- for (i = fromStart + lastCommonSep + 1; i <= fromEnd; ++i) {
1248
- if (i === fromEnd || from.charCodeAt(i) === CHAR_FORWARD_SLASH) {
1249
- out += out.length === 0 ? '..' : '/..';
1250
- }
1251
- } // Lastly, append the rest of the destination (`to`) path that comes after
1252
- // the common path parts.
1253
-
1254
-
1255
- return `${out}${to.slice(toStart + lastCommonSep)}`;
1256
- },
1257
-
1258
- toNamespacedPath(path) {
1259
- // Non-op on posix systems
1260
- return path;
1261
- },
1262
-
1263
- dirname(path) {
1264
- validateString(path, 'path');
1265
-
1266
- if (path.length === 0) {
1267
- return '.';
1268
- }
1269
-
1270
- const hasRoot = path.charCodeAt(0) === CHAR_FORWARD_SLASH;
1271
- let end = -1;
1272
- let matchedSlash = true;
1273
-
1274
- for (let i = path.length - 1; i >= 1; --i) {
1275
- if (path.charCodeAt(i) === CHAR_FORWARD_SLASH) {
1276
- if (!matchedSlash) {
1277
- end = i;
1278
- break;
1279
- }
1280
- } else {
1281
- // We saw the first non-path separator
1282
- matchedSlash = false;
1283
- }
1284
- }
1285
-
1286
- if (end === -1) {
1287
- return hasRoot ? '/' : '.';
1288
- }
1289
-
1290
- if (hasRoot && end === 1) {
1291
- return '//';
1292
- }
1293
-
1294
- return path.slice(0, end);
1295
- },
1296
-
1297
- basename(path, ext) {
1298
- if (ext !== undefined) {
1299
- validateString(ext, 'ext');
1300
- }
1301
-
1302
- validateString(path, 'path');
1303
- let start = 0;
1304
- let end = -1;
1305
- let matchedSlash = true;
1306
- let i;
1307
-
1308
- if (ext !== undefined && ext.length > 0 && ext.length <= path.length) {
1309
- if (ext === path) {
1310
- return '';
1311
- }
1312
-
1313
- let extIdx = ext.length - 1;
1314
- let firstNonSlashEnd = -1;
1315
-
1316
- for (i = path.length - 1; i >= 0; --i) {
1317
- const code = path.charCodeAt(i);
1318
-
1319
- if (code === CHAR_FORWARD_SLASH) {
1320
- // If we reached a path separator that was not part of a set of path
1321
- // separators at the end of the string, stop now
1322
- if (!matchedSlash) {
1323
- start = i + 1;
1324
- break;
1325
- }
1326
- } else {
1327
- if (firstNonSlashEnd === -1) {
1328
- // We saw the first non-path separator, remember this index in case
1329
- // we need it if the extension ends up not matching
1330
- matchedSlash = false;
1331
- firstNonSlashEnd = i + 1;
1332
- }
1333
-
1334
- if (extIdx >= 0) {
1335
- // Try to match the explicit extension
1336
- if (code === ext.charCodeAt(extIdx)) {
1337
- if (--extIdx === -1) {
1338
- // We matched the extension, so mark this as the end of our path
1339
- // component
1340
- end = i;
1341
- }
1342
- } else {
1343
- // Extension does not match, so our result is the entire path
1344
- // component
1345
- extIdx = -1;
1346
- end = firstNonSlashEnd;
1347
- }
1348
- }
1349
- }
1350
- }
1351
-
1352
- if (start === end) {
1353
- end = firstNonSlashEnd;
1354
- } else if (end === -1) {
1355
- end = path.length;
1356
- }
1357
-
1358
- return path.slice(start, end);
1359
- }
1360
-
1361
- for (i = path.length - 1; i >= 0; --i) {
1362
- if (path.charCodeAt(i) === CHAR_FORWARD_SLASH) {
1363
- // If we reached a path separator that was not part of a set of path
1364
- // separators at the end of the string, stop now
1365
- if (!matchedSlash) {
1366
- start = i + 1;
1367
- break;
1368
- }
1369
- } else if (end === -1) {
1370
- // We saw the first non-path separator, mark this as the end of our
1371
- // path component
1372
- matchedSlash = false;
1373
- end = i + 1;
1374
- }
1375
- }
1376
-
1377
- if (end === -1) {
1378
- return '';
1379
- }
1380
-
1381
- return path.slice(start, end);
1382
- },
1383
-
1384
- extname(path) {
1385
- validateString(path, 'path');
1386
- let startDot = -1;
1387
- let startPart = 0;
1388
- let end = -1;
1389
- let matchedSlash = true; // Track the state of characters (if any) we see before our first dot and
1390
- // after any path separator we find
1391
-
1392
- let preDotState = 0;
1393
-
1394
- for (let i = path.length - 1; i >= 0; --i) {
1395
- const code = path.charCodeAt(i);
1396
-
1397
- if (code === CHAR_FORWARD_SLASH) {
1398
- // If we reached a path separator that was not part of a set of path
1399
- // separators at the end of the string, stop now
1400
- if (!matchedSlash) {
1401
- startPart = i + 1;
1402
- break;
1403
- }
1404
-
1405
- continue;
1406
- }
1407
-
1408
- if (end === -1) {
1409
- // We saw the first non-path separator, mark this as the end of our
1410
- // extension
1411
- matchedSlash = false;
1412
- end = i + 1;
1413
- }
1414
-
1415
- if (code === CHAR_DOT) {
1416
- // If this is our first dot, mark it as the start of our extension
1417
- if (startDot === -1) {
1418
- startDot = i;
1419
- } else if (preDotState !== 1) {
1420
- preDotState = 1;
1421
- }
1422
- } else if (startDot !== -1) {
1423
- // We saw a non-dot and non-path separator before our dot, so we should
1424
- // have a good chance at having a non-empty extension
1425
- preDotState = -1;
1426
- }
1427
- }
1428
-
1429
- if (startDot === -1 || end === -1 || // We saw a non-dot character immediately before the dot
1430
- preDotState === 0 || // The (right-most) trimmed path component is exactly '..'
1431
- preDotState === 1 && startDot === end - 1 && startDot === startPart + 1) {
1432
- return '';
1433
- }
1434
-
1435
- return path.slice(startDot, end);
1436
- },
1437
-
1438
- format: _format.bind(null, '/'),
1439
-
1440
- parse(path) {
1441
- validateString(path, 'path');
1442
- const ret = {
1443
- root: '',
1444
- dir: '',
1445
- base: '',
1446
- ext: '',
1447
- name: ''
1448
- };
1449
-
1450
- if (path.length === 0) {
1451
- return ret;
1452
- }
1453
-
1454
- const isAbsolute = path.charCodeAt(0) === CHAR_FORWARD_SLASH;
1455
- let start;
1456
-
1457
- if (isAbsolute) {
1458
- ret.root = '/';
1459
- start = 1;
1460
- } else {
1461
- start = 0;
1462
- }
1463
-
1464
- let startDot = -1;
1465
- let startPart = 0;
1466
- let end = -1;
1467
- let matchedSlash = true;
1468
- let i = path.length - 1; // Track the state of characters (if any) we see before our first dot and
1469
- // after any path separator we find
1470
-
1471
- let preDotState = 0; // Get non-dir info
1472
-
1473
- for (; i >= start; --i) {
1474
- const code = path.charCodeAt(i);
1475
-
1476
- if (code === CHAR_FORWARD_SLASH) {
1477
- // If we reached a path separator that was not part of a set of path
1478
- // separators at the end of the string, stop now
1479
- if (!matchedSlash) {
1480
- startPart = i + 1;
1481
- break;
1482
- }
1483
-
1484
- continue;
1485
- }
1486
-
1487
- if (end === -1) {
1488
- // We saw the first non-path separator, mark this as the end of our
1489
- // extension
1490
- matchedSlash = false;
1491
- end = i + 1;
1492
- }
1493
-
1494
- if (code === CHAR_DOT) {
1495
- // If this is our first dot, mark it as the start of our extension
1496
- if (startDot === -1) {
1497
- startDot = i;
1498
- } else if (preDotState !== 1) {
1499
- preDotState = 1;
1500
- }
1501
- } else if (startDot !== -1) {
1502
- // We saw a non-dot and non-path separator before our dot, so we should
1503
- // have a good chance at having a non-empty extension
1504
- preDotState = -1;
1505
- }
1506
- }
1507
-
1508
- if (end !== -1) {
1509
- const start = startPart === 0 && isAbsolute ? 1 : startPart;
1510
-
1511
- if (startDot === -1 || // We saw a non-dot character immediately before the dot
1512
- preDotState === 0 || // The (right-most) trimmed path component is exactly '..'
1513
- preDotState === 1 && startDot === end - 1 && startDot === startPart + 1) {
1514
- ret.base = ret.name = path.slice(start, end);
1515
- } else {
1516
- ret.name = path.slice(start, startDot);
1517
- ret.base = path.slice(start, end);
1518
- ret.ext = path.slice(startDot, end);
1519
- }
1520
- }
1521
-
1522
- if (startPart > 0) {
1523
- ret.dir = path.slice(0, startPart - 1);
1524
- } else if (isAbsolute) {
1525
- ret.dir = '/';
1526
- }
1527
-
1528
- return ret;
1529
- },
1530
-
1531
- sep: '/',
1532
- delimiter: ':',
1533
- win32: null,
1534
- posix: null
1535
- };
1536
- exports.posix.win32 = exports.win32.win32 = exports.win32;
1537
- exports.posix.posix = exports.win32.posix = exports.posix;
1538
- exports.normalize = process.platform === 'win32' ? exports.win32.normalize : exports.posix.normalize;
1539
- exports.isAbsolute = process.platform === 'win32' ? exports.win32.isAbsolute : exports.posix.isAbsolute;
1540
- exports.join = process.platform === 'win32' ? exports.win32.join : exports.posix.join;
1541
- exports.resolve = process.platform === 'win32' ? exports.win32.resolve : exports.posix.resolve;
1542
- exports.relative = process.platform === 'win32' ? exports.win32.relative : exports.posix.relative;
1543
- exports.dirname = process.platform === 'win32' ? exports.win32.dirname : exports.posix.dirname;
1544
- exports.basename = process.platform === 'win32' ? exports.win32.basename : exports.posix.basename;
1545
- exports.extname = process.platform === 'win32' ? exports.win32.extname : exports.posix.extname;
1546
- exports.format = process.platform === 'win32' ? exports.win32.format : exports.posix.format;
1547
- exports.parse = process.platform === 'win32' ? exports.win32.parse : exports.posix.parse;
1548
- exports.toNamespacedPath = process.platform === 'win32' ? exports.win32.toNamespacedPath : exports.posix.toNamespacedPath;
1549
- exports.sep = process.platform === 'win32' ? exports.win32.sep : exports.posix.sep;
1550
- exports.delimiter = process.platform === 'win32' ? exports.win32.delimiter : exports.posix.delimiter;