custom-electron-titlebar 3.2.5 → 3.2.9

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