@opensumi/ide-utils 2.16.6

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