@serveryyswys/node.operit 0.0.0-stage → 0.1.2

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 (123) hide show
  1. package/BUILTINS.json +233 -0
  2. package/DESIGN.md +513 -0
  3. package/LICENSE +674 -0
  4. package/README.md +301 -2
  5. package/dist/assert/strict.d.ts +2 -0
  6. package/dist/assert/strict.js +7 -0
  7. package/dist/assert.d.ts +3 -0
  8. package/dist/assert.js +483 -0
  9. package/dist/buffer.d.ts +60 -0
  10. package/dist/buffer.js +524 -0
  11. package/dist/child_process.d.ts +56 -0
  12. package/dist/child_process.js +371 -0
  13. package/dist/constants.d.ts +2 -0
  14. package/dist/constants.js +19 -0
  15. package/dist/crypto.d.ts +76 -0
  16. package/dist/crypto.js +312 -0
  17. package/dist/dns/promises.d.ts +34 -0
  18. package/dist/dns/promises.js +190 -0
  19. package/dist/dns.d.ts +88 -0
  20. package/dist/dns.js +259 -0
  21. package/dist/events.d.ts +40 -0
  22. package/dist/events.js +237 -0
  23. package/dist/fs/promises.d.ts +159 -0
  24. package/dist/fs/promises.js +129 -0
  25. package/dist/fs.d.ts +221 -0
  26. package/dist/fs.js +944 -0
  27. package/dist/http.d.ts +92 -0
  28. package/dist/http.js +319 -0
  29. package/dist/https.d.ts +296 -0
  30. package/dist/https.js +50 -0
  31. package/dist/index.d.ts +2422 -0
  32. package/dist/index.js +57 -0
  33. package/dist/lib/bridge.d.ts +60 -0
  34. package/dist/lib/bridge.js +205 -0
  35. package/dist/lib/bytes.d.ts +20 -0
  36. package/dist/lib/bytes.js +239 -0
  37. package/dist/lib/child-process-types.d.ts +45 -0
  38. package/dist/lib/child-process-types.js +2 -0
  39. package/dist/lib/cwd.d.ts +2 -0
  40. package/dist/lib/cwd.js +32 -0
  41. package/dist/lib/deep-equal.d.ts +3 -0
  42. package/dist/lib/deep-equal.js +223 -0
  43. package/dist/lib/deflate.d.ts +2 -0
  44. package/dist/lib/deflate.js +234 -0
  45. package/dist/lib/dns-driver.d.ts +14 -0
  46. package/dist/lib/dns-driver.js +85 -0
  47. package/dist/lib/dns-types.d.ts +22 -0
  48. package/dist/lib/dns-types.js +2 -0
  49. package/dist/lib/errors.d.ts +48 -0
  50. package/dist/lib/errors.js +424 -0
  51. package/dist/lib/fs-driver.d.ts +70 -0
  52. package/dist/lib/fs-driver.js +364 -0
  53. package/dist/lib/fs-env.d.ts +30 -0
  54. package/dist/lib/fs-env.js +157 -0
  55. package/dist/lib/fs-types.d.ts +19 -0
  56. package/dist/lib/fs-types.js +2 -0
  57. package/dist/lib/hashes.d.ts +27 -0
  58. package/dist/lib/hashes.js +432 -0
  59. package/dist/lib/http-driver.d.ts +30 -0
  60. package/dist/lib/http-driver.js +72 -0
  61. package/dist/lib/http-types.d.ts +18 -0
  62. package/dist/lib/http-types.js +2 -0
  63. package/dist/lib/inflate.d.ts +6 -0
  64. package/dist/lib/inflate.js +284 -0
  65. package/dist/lib/path-types.d.ts +37 -0
  66. package/dist/lib/path-types.js +2 -0
  67. package/dist/lib/paths.d.ts +8 -0
  68. package/dist/lib/paths.js +106 -0
  69. package/dist/lib/perf-hooks-types.d.ts +18 -0
  70. package/dist/lib/perf-hooks-types.js +2 -0
  71. package/dist/lib/process-driver.d.ts +31 -0
  72. package/dist/lib/process-driver.js +102 -0
  73. package/dist/lib/punycode.d.ts +8 -0
  74. package/dist/lib/punycode.js +179 -0
  75. package/dist/lib/stream-types.d.ts +29 -0
  76. package/dist/lib/stream-types.js +2 -0
  77. package/dist/lib/timers-types.d.ts +18 -0
  78. package/dist/lib/timers-types.js +2 -0
  79. package/dist/lib/url-search-params.d.ts +26 -0
  80. package/dist/lib/url-search-params.js +281 -0
  81. package/dist/lib/url-types.d.ts +44 -0
  82. package/dist/lib/url-types.js +2 -0
  83. package/dist/lib/url-whatwg.d.ts +78 -0
  84. package/dist/lib/url-whatwg.js +857 -0
  85. package/dist/lib/zlib-types.d.ts +12 -0
  86. package/dist/lib/zlib-types.js +2 -0
  87. package/dist/module.d.ts +8 -0
  88. package/dist/module.js +72 -0
  89. package/dist/os.d.ts +80 -0
  90. package/dist/os.js +247 -0
  91. package/dist/path/posix.d.ts +2 -0
  92. package/dist/path/posix.js +7 -0
  93. package/dist/path/win32.d.ts +2 -0
  94. package/dist/path/win32.js +10 -0
  95. package/dist/path.d.ts +3 -0
  96. package/dist/path.js +1222 -0
  97. package/dist/perf_hooks.d.ts +36 -0
  98. package/dist/perf_hooks.js +144 -0
  99. package/dist/process.d.ts +69 -0
  100. package/dist/process.js +230 -0
  101. package/dist/querystring.d.ts +15 -0
  102. package/dist/querystring.js +209 -0
  103. package/dist/stream/promises.d.ts +5 -0
  104. package/dist/stream/promises.js +10 -0
  105. package/dist/stream.d.ts +84 -0
  106. package/dist/stream.js +875 -0
  107. package/dist/string_decoder.d.ts +15 -0
  108. package/dist/string_decoder.js +237 -0
  109. package/dist/timers/promises.d.ts +19 -0
  110. package/dist/timers/promises.js +74 -0
  111. package/dist/timers.d.ts +21 -0
  112. package/dist/timers.js +41 -0
  113. package/dist/tty.d.ts +9 -0
  114. package/dist/tty.js +25 -0
  115. package/dist/unsupported.d.ts +12 -0
  116. package/dist/unsupported.js +17 -0
  117. package/dist/url.d.ts +28 -0
  118. package/dist/url.js +486 -0
  119. package/dist/util.d.ts +74 -0
  120. package/dist/util.js +515 -0
  121. package/dist/zlib.d.ts +88 -0
  122. package/dist/zlib.js +371 -0
  123. package/package.json +29 -4
package/dist/path.js ADDED
@@ -0,0 +1,1222 @@
1
+ 'use strict';
2
+ /**
3
+ * Node path 模块的移植,posix 与 win32 两套都在。
4
+ *
5
+ * 与 Node 的差异(有意为之,只此一处):
6
+ * 默认导出的是 posix 版,因为 Operit 的平台是 android / linux;
7
+ * Node 的默认导出按宿主平台选择,这里没有可选择的余地。
8
+ * path.posix / path.win32 的行为与 Node 一致,并由 test/path.test.js 对拍。
9
+ *
10
+ * win32 的 resolve 在 Node 里会查询 "=<盘符>" 形式的环境变量取盘符级 cwd,
11
+ * QuickJS 没有 process.env,这里统一退回 lib/cwd 提供的 cwd。
12
+ */
13
+ const cwd_1 = require("./lib/cwd");
14
+ const CHAR_UPPERCASE_A = 65;
15
+ const CHAR_UPPERCASE_Z = 90;
16
+ const CHAR_LOWERCASE_A = 97;
17
+ const CHAR_LOWERCASE_Z = 122;
18
+ const CHAR_DOT = 46;
19
+ const CHAR_FORWARD_SLASH = 47;
20
+ const CHAR_BACKWARD_SLASH = 92;
21
+ const CHAR_COLON = 58;
22
+ function describeValue(value) {
23
+ if (typeof value === 'string') {
24
+ return "'" + value + "'";
25
+ }
26
+ if (value === null) {
27
+ return 'null';
28
+ }
29
+ if (value === undefined) {
30
+ return 'undefined';
31
+ }
32
+ if (typeof value === 'object') {
33
+ return '{}';
34
+ }
35
+ return String(value);
36
+ }
37
+ function assertPath(value) {
38
+ if (typeof value !== 'string') {
39
+ throw new TypeError('Path must be a string. Received ' + describeValue(value));
40
+ }
41
+ }
42
+ function isPosixSeparator(code) {
43
+ return code === CHAR_FORWARD_SLASH;
44
+ }
45
+ function isWindowsSeparator(code) {
46
+ return code === CHAR_FORWARD_SLASH || code === CHAR_BACKWARD_SLASH;
47
+ }
48
+ function isWindowsDeviceRoot(code) {
49
+ return (code >= CHAR_UPPERCASE_A && code <= CHAR_UPPERCASE_Z) ||
50
+ (code >= CHAR_LOWERCASE_A && code <= CHAR_LOWERCASE_Z);
51
+ }
52
+ /** Node normalizeString 的移植;separator 与 isSeparator 决定平台。 */
53
+ function normalizeString(path, allowAboveRoot, separator, isSeparator) {
54
+ let res = '';
55
+ let lastSegmentLength = 0;
56
+ let lastSlash = -1;
57
+ let dots = 0;
58
+ let code = 0;
59
+ for (let i = 0; i <= path.length; i += 1) {
60
+ if (i < path.length) {
61
+ code = path.charCodeAt(i);
62
+ }
63
+ else if (isSeparator(code)) {
64
+ break;
65
+ }
66
+ else {
67
+ code = CHAR_FORWARD_SLASH;
68
+ }
69
+ if (isSeparator(code)) {
70
+ if (lastSlash === i - 1 || dots === 1) {
71
+ // 连续分隔符或单个点,跳过
72
+ }
73
+ else if (dots === 2) {
74
+ if (res.length < 2 ||
75
+ lastSegmentLength !== 2 ||
76
+ res.charCodeAt(res.length - 1) !== CHAR_DOT ||
77
+ res.charCodeAt(res.length - 2) !== CHAR_DOT) {
78
+ if (res.length > 2) {
79
+ const lastSlashIndex = res.lastIndexOf(separator);
80
+ if (lastSlashIndex === -1) {
81
+ res = '';
82
+ lastSegmentLength = 0;
83
+ }
84
+ else {
85
+ res = res.slice(0, lastSlashIndex);
86
+ lastSegmentLength = res.length - 1 - res.lastIndexOf(separator);
87
+ }
88
+ lastSlash = i;
89
+ dots = 0;
90
+ continue;
91
+ }
92
+ else if (res.length !== 0) {
93
+ res = '';
94
+ lastSegmentLength = 0;
95
+ lastSlash = i;
96
+ dots = 0;
97
+ continue;
98
+ }
99
+ }
100
+ if (allowAboveRoot) {
101
+ res += res.length > 0 ? separator + '..' : '..';
102
+ lastSegmentLength = 2;
103
+ }
104
+ }
105
+ else {
106
+ if (res.length > 0) {
107
+ res += separator + path.slice(lastSlash + 1, i);
108
+ }
109
+ else {
110
+ res = path.slice(lastSlash + 1, i);
111
+ }
112
+ lastSegmentLength = i - lastSlash - 1;
113
+ }
114
+ lastSlash = i;
115
+ dots = 0;
116
+ }
117
+ else if (code === CHAR_DOT && dots !== -1) {
118
+ dots += 1;
119
+ }
120
+ else {
121
+ dots = -1;
122
+ }
123
+ }
124
+ return res;
125
+ }
126
+ // ---------------------------------------------------------------- posix
127
+ function posixNormalize(path) {
128
+ assertPath(path);
129
+ if (path.length === 0) {
130
+ return '.';
131
+ }
132
+ const isAbsolute = path.charCodeAt(0) === CHAR_FORWARD_SLASH;
133
+ const trailingSeparator = path.charCodeAt(path.length - 1) === CHAR_FORWARD_SLASH;
134
+ let normalized = normalizeString(path, !isAbsolute, '/', isPosixSeparator);
135
+ if (normalized.length === 0) {
136
+ if (isAbsolute) {
137
+ return '/';
138
+ }
139
+ return trailingSeparator ? './' : '.';
140
+ }
141
+ if (trailingSeparator) {
142
+ normalized += '/';
143
+ }
144
+ return isAbsolute ? '/' + normalized : normalized;
145
+ }
146
+ function posixIsAbsolute(path) {
147
+ assertPath(path);
148
+ return path.length > 0 && path.charCodeAt(0) === CHAR_FORWARD_SLASH;
149
+ }
150
+ function posixJoin(...paths) {
151
+ if (paths.length === 0) {
152
+ return '.';
153
+ }
154
+ let joined;
155
+ for (let i = 0; i < paths.length; i += 1) {
156
+ const arg = paths[i];
157
+ assertPath(arg);
158
+ if (arg.length > 0) {
159
+ joined = joined === undefined ? arg : joined + '/' + arg;
160
+ }
161
+ }
162
+ if (joined === undefined) {
163
+ return '.';
164
+ }
165
+ return posixNormalize(joined);
166
+ }
167
+ function posixResolve(...paths) {
168
+ let resolvedPath = '';
169
+ let resolvedAbsolute = false;
170
+ for (let i = paths.length - 1; i >= -1 && !resolvedAbsolute; i -= 1) {
171
+ const path = i >= 0 ? paths[i] : (0, cwd_1.get)();
172
+ assertPath(path);
173
+ if (path.length === 0) {
174
+ continue;
175
+ }
176
+ resolvedPath = path + '/' + resolvedPath;
177
+ resolvedAbsolute = path.charCodeAt(0) === CHAR_FORWARD_SLASH;
178
+ }
179
+ resolvedPath = normalizeString(resolvedPath, !resolvedAbsolute, '/', isPosixSeparator);
180
+ if (resolvedAbsolute) {
181
+ return resolvedPath.length > 0 ? '/' + resolvedPath : '/';
182
+ }
183
+ return resolvedPath.length > 0 ? resolvedPath : '.';
184
+ }
185
+ function posixRelative(from, to) {
186
+ assertPath(from);
187
+ assertPath(to);
188
+ if (from === to) {
189
+ return '';
190
+ }
191
+ const fromOrig = posixResolve(from);
192
+ const toOrig = posixResolve(to);
193
+ if (fromOrig === toOrig) {
194
+ return '';
195
+ }
196
+ const fromResolved = fromOrig;
197
+ const toResolved = toOrig;
198
+ let fromStart = 1;
199
+ for (; fromStart < fromResolved.length; fromStart += 1) {
200
+ if (fromResolved.charCodeAt(fromStart) !== CHAR_FORWARD_SLASH) {
201
+ break;
202
+ }
203
+ }
204
+ const fromEnd = fromResolved.length;
205
+ const fromLen = fromEnd - fromStart;
206
+ let toStart = 1;
207
+ for (; toStart < toResolved.length; toStart += 1) {
208
+ if (toResolved.charCodeAt(toStart) !== CHAR_FORWARD_SLASH) {
209
+ break;
210
+ }
211
+ }
212
+ const toEnd = toResolved.length;
213
+ const toLen = toEnd - toStart;
214
+ const length = fromLen < toLen ? fromLen : toLen;
215
+ let lastCommonSep = -1;
216
+ let i = 0;
217
+ for (; i <= length; i += 1) {
218
+ if (i === length) {
219
+ if (toLen > length) {
220
+ if (toResolved.charCodeAt(toStart + i) === CHAR_FORWARD_SLASH) {
221
+ return toResolved.slice(toStart + i + 1);
222
+ }
223
+ if (i === 0) {
224
+ return toResolved.slice(toStart + i);
225
+ }
226
+ }
227
+ else if (fromLen > length) {
228
+ if (fromResolved.charCodeAt(fromStart + i) === CHAR_FORWARD_SLASH) {
229
+ lastCommonSep = i;
230
+ }
231
+ else if (i === 0) {
232
+ lastCommonSep = 0;
233
+ }
234
+ }
235
+ break;
236
+ }
237
+ const fromCode = fromResolved.charCodeAt(fromStart + i);
238
+ const toCode = toResolved.charCodeAt(toStart + i);
239
+ if (fromCode !== toCode) {
240
+ break;
241
+ }
242
+ else if (fromCode === CHAR_FORWARD_SLASH) {
243
+ lastCommonSep = i;
244
+ }
245
+ }
246
+ let out = '';
247
+ for (i = fromStart + lastCommonSep + 1; i <= fromEnd; i += 1) {
248
+ if (i === fromEnd || fromResolved.charCodeAt(i) === CHAR_FORWARD_SLASH) {
249
+ out += out.length === 0 ? '..' : '/..';
250
+ }
251
+ }
252
+ return out + toResolved.slice(toStart + lastCommonSep);
253
+ }
254
+ function posixDirname(path) {
255
+ assertPath(path);
256
+ if (path.length === 0) {
257
+ return '.';
258
+ }
259
+ const hasRoot = path.charCodeAt(0) === CHAR_FORWARD_SLASH;
260
+ let end = -1;
261
+ let matchedSlash = true;
262
+ for (let i = path.length - 1; i >= 1; i -= 1) {
263
+ if (path.charCodeAt(i) === CHAR_FORWARD_SLASH) {
264
+ if (!matchedSlash) {
265
+ end = i;
266
+ break;
267
+ }
268
+ }
269
+ else {
270
+ matchedSlash = false;
271
+ }
272
+ }
273
+ if (end === -1) {
274
+ return hasRoot ? '/' : '.';
275
+ }
276
+ if (hasRoot && end === 1) {
277
+ return '//';
278
+ }
279
+ return path.slice(0, end);
280
+ }
281
+ function posixBasename(path, ext) {
282
+ if (ext !== undefined && typeof ext !== 'string') {
283
+ throw new TypeError('"ext" argument must be a string');
284
+ }
285
+ assertPath(path);
286
+ let start = 0;
287
+ let end = -1;
288
+ let matchedSlash = true;
289
+ let i;
290
+ if (ext !== undefined && ext.length > 0 && ext.length <= path.length) {
291
+ if (ext.length === path.length && ext === path) {
292
+ return '';
293
+ }
294
+ let extIdx = ext.length - 1;
295
+ let firstNonSlashEnd = -1;
296
+ for (i = path.length - 1; i >= 0; i -= 1) {
297
+ const code = path.charCodeAt(i);
298
+ if (code === CHAR_FORWARD_SLASH) {
299
+ if (!matchedSlash) {
300
+ start = i + 1;
301
+ break;
302
+ }
303
+ }
304
+ else {
305
+ if (firstNonSlashEnd === -1) {
306
+ matchedSlash = false;
307
+ firstNonSlashEnd = i + 1;
308
+ }
309
+ if (extIdx >= 0) {
310
+ if (code === ext.charCodeAt(extIdx)) {
311
+ extIdx -= 1;
312
+ if (extIdx === -1) {
313
+ end = i;
314
+ }
315
+ }
316
+ else {
317
+ extIdx = -1;
318
+ end = firstNonSlashEnd;
319
+ }
320
+ }
321
+ }
322
+ }
323
+ if (start === end) {
324
+ end = firstNonSlashEnd;
325
+ }
326
+ else if (end === -1) {
327
+ end = path.length;
328
+ }
329
+ return path.slice(start, end);
330
+ }
331
+ for (i = path.length - 1; i >= 0; i -= 1) {
332
+ if (path.charCodeAt(i) === CHAR_FORWARD_SLASH) {
333
+ if (!matchedSlash) {
334
+ start = i + 1;
335
+ break;
336
+ }
337
+ }
338
+ else if (end === -1) {
339
+ matchedSlash = false;
340
+ end = i + 1;
341
+ }
342
+ }
343
+ if (end === -1) {
344
+ return '';
345
+ }
346
+ return path.slice(start, end);
347
+ }
348
+ function posixExtname(path) {
349
+ assertPath(path);
350
+ let startDot = -1;
351
+ let startPart = 0;
352
+ let end = -1;
353
+ let matchedSlash = true;
354
+ let preDotState = 0;
355
+ for (let i = path.length - 1; i >= 0; i -= 1) {
356
+ const code = path.charCodeAt(i);
357
+ if (code === CHAR_FORWARD_SLASH) {
358
+ if (!matchedSlash) {
359
+ startPart = i + 1;
360
+ break;
361
+ }
362
+ continue;
363
+ }
364
+ if (end === -1) {
365
+ matchedSlash = false;
366
+ end = i + 1;
367
+ }
368
+ if (code === CHAR_DOT) {
369
+ if (startDot === -1) {
370
+ startDot = i;
371
+ }
372
+ else if (preDotState !== 1) {
373
+ preDotState = 1;
374
+ }
375
+ }
376
+ else if (startDot !== -1) {
377
+ preDotState = -1;
378
+ }
379
+ }
380
+ if (startDot === -1 ||
381
+ end === -1 ||
382
+ preDotState === 0 ||
383
+ (preDotState === 1 && startDot === end - 1 && startDot === startPart + 1)) {
384
+ return '';
385
+ }
386
+ return path.slice(startDot, end);
387
+ }
388
+ function posixFormat(pathObject) {
389
+ if (pathObject === null || typeof pathObject !== 'object') {
390
+ throw new TypeError('The "pathObject" argument must be of type object. Received type ' + typeof pathObject);
391
+ }
392
+ const dir = pathObject.dir ?? pathObject.root;
393
+ const base = pathObject.base ?? (pathObject.name ?? '') + (pathObject.ext ?? '');
394
+ if (dir === undefined || dir.length === 0) {
395
+ return base;
396
+ }
397
+ if (dir === pathObject.root) {
398
+ return dir + base;
399
+ }
400
+ return dir + '/' + base;
401
+ }
402
+ function posixParse(path) {
403
+ assertPath(path);
404
+ const ret = { root: '', dir: '', base: '', ext: '', name: '' };
405
+ if (path.length === 0) {
406
+ return ret;
407
+ }
408
+ const isAbsolute = path.charCodeAt(0) === CHAR_FORWARD_SLASH;
409
+ const start = isAbsolute ? 1 : 0;
410
+ let startDot = -1;
411
+ let startPart = 0;
412
+ let end = -1;
413
+ let matchedSlash = true;
414
+ let i = path.length - 1;
415
+ let preDotState = 0;
416
+ if (isAbsolute) {
417
+ ret.root = '/';
418
+ }
419
+ for (; i >= start; i -= 1) {
420
+ const code = path.charCodeAt(i);
421
+ if (code === CHAR_FORWARD_SLASH) {
422
+ if (!matchedSlash) {
423
+ startPart = i + 1;
424
+ break;
425
+ }
426
+ continue;
427
+ }
428
+ if (end === -1) {
429
+ matchedSlash = false;
430
+ end = i + 1;
431
+ }
432
+ if (code === CHAR_DOT) {
433
+ if (startDot === -1) {
434
+ startDot = i;
435
+ }
436
+ else if (preDotState !== 1) {
437
+ preDotState = 1;
438
+ }
439
+ }
440
+ else if (startDot !== -1) {
441
+ preDotState = -1;
442
+ }
443
+ }
444
+ if (end !== -1) {
445
+ const sliceStart = startPart === 0 && isAbsolute ? 1 : startPart;
446
+ if (startDot === -1 ||
447
+ preDotState === 0 ||
448
+ (preDotState === 1 && startDot === end - 1 && startDot === startPart + 1)) {
449
+ ret.base = path.slice(sliceStart, end);
450
+ ret.name = ret.base;
451
+ }
452
+ else {
453
+ ret.name = path.slice(sliceStart, startDot);
454
+ ret.base = path.slice(sliceStart, end);
455
+ ret.ext = path.slice(startDot, end);
456
+ }
457
+ }
458
+ if (startPart > 0) {
459
+ ret.dir = path.slice(0, startPart - 1);
460
+ }
461
+ else if (isAbsolute) {
462
+ ret.dir = '/';
463
+ }
464
+ return ret;
465
+ }
466
+ function posixToNamespacedPath(path) {
467
+ return path;
468
+ }
469
+ // ---------------------------------------------------------------- win32
470
+ function win32Normalize(path) {
471
+ assertPath(path);
472
+ const len = path.length;
473
+ if (len === 0) {
474
+ return '.';
475
+ }
476
+ if (len === 1) {
477
+ return isWindowsSeparator(path.charCodeAt(0)) ? '\\' : path;
478
+ }
479
+ let rootEnd = 0;
480
+ let device;
481
+ let isAbsolute = false;
482
+ const code = path.charCodeAt(0);
483
+ if (isWindowsSeparator(code)) {
484
+ isAbsolute = true;
485
+ if (isWindowsSeparator(path.charCodeAt(1))) {
486
+ let j = 2;
487
+ let last = j;
488
+ while (j < len && !isWindowsSeparator(path.charCodeAt(j))) {
489
+ j += 1;
490
+ }
491
+ if (j < len && j !== last) {
492
+ const firstPart = path.slice(last, j);
493
+ last = j;
494
+ while (j < len && isWindowsSeparator(path.charCodeAt(j))) {
495
+ j += 1;
496
+ }
497
+ if (j < len && j !== last) {
498
+ last = j;
499
+ while (j < len && !isWindowsSeparator(path.charCodeAt(j))) {
500
+ j += 1;
501
+ }
502
+ if (j === len) {
503
+ device = '\\\\' + firstPart + '\\' + path.slice(last);
504
+ rootEnd = j;
505
+ }
506
+ else if (j !== last) {
507
+ device = '\\\\' + firstPart + '\\' + path.slice(last, j);
508
+ rootEnd = j;
509
+ }
510
+ }
511
+ }
512
+ }
513
+ else {
514
+ rootEnd = 1;
515
+ }
516
+ }
517
+ else if (isWindowsDeviceRoot(code) && path.charCodeAt(1) === CHAR_COLON) {
518
+ device = path.slice(0, 2);
519
+ rootEnd = 2;
520
+ if (len > 2 && isWindowsSeparator(path.charCodeAt(2))) {
521
+ isAbsolute = true;
522
+ rootEnd = 3;
523
+ }
524
+ }
525
+ let tail;
526
+ if (rootEnd < len) {
527
+ tail = normalizeString(path.slice(rootEnd), !isAbsolute, '\\', isWindowsSeparator);
528
+ }
529
+ else {
530
+ tail = '';
531
+ }
532
+ if (tail.length === 0 && !isAbsolute) {
533
+ tail = '.';
534
+ }
535
+ if (tail.length > 0 && isWindowsSeparator(path.charCodeAt(len - 1))) {
536
+ tail += '\\';
537
+ }
538
+ if (device === undefined) {
539
+ if (isAbsolute) {
540
+ return '\\' + tail;
541
+ }
542
+ // Windows 会把"以冒号结尾"或"冒号后紧跟分隔符"的相对路径当成盘符相对路径,
543
+ // 这里补 .\ 前缀消除歧义。1:2 这类不含歧义的相对路径不补。
544
+ return hasAmbiguousDriveColon(tail) ? '.\\' + tail : tail;
545
+ }
546
+ if (isAbsolute) {
547
+ // \\.\ 是设备命名空间,空尾时补分隔符会改变语义,保持原样。
548
+ if (tail.length === 0 && isDeviceNamespace(device)) {
549
+ return device;
550
+ }
551
+ return device + '\\' + tail;
552
+ }
553
+ return device + tail;
554
+ }
555
+ /** 判断归一化后的相对路径里有没有会被误读成盘符的冒号。 */
556
+ function hasAmbiguousDriveColon(value) {
557
+ for (let i = 0; i < value.length; i += 1) {
558
+ if (value.charCodeAt(i) !== CHAR_COLON) {
559
+ continue;
560
+ }
561
+ if (i === value.length - 1) {
562
+ return true;
563
+ }
564
+ const next = value.charCodeAt(i + 1);
565
+ if (next === CHAR_FORWARD_SLASH || next === CHAR_BACKWARD_SLASH) {
566
+ return true;
567
+ }
568
+ }
569
+ return false;
570
+ }
571
+ /** 判断是否为 \\.\ 开头的设备命名空间路径。 */
572
+ function isDeviceNamespace(value) {
573
+ return value.length >= 4 &&
574
+ value.charCodeAt(0) === CHAR_BACKWARD_SLASH &&
575
+ value.charCodeAt(1) === CHAR_BACKWARD_SLASH &&
576
+ value.charCodeAt(2) === CHAR_DOT &&
577
+ value.charCodeAt(3) === CHAR_BACKWARD_SLASH;
578
+ }
579
+ function win32IsAbsolute(path) {
580
+ assertPath(path);
581
+ const len = path.length;
582
+ if (len === 0) {
583
+ return false;
584
+ }
585
+ const code = path.charCodeAt(0);
586
+ if (isWindowsSeparator(code)) {
587
+ return true;
588
+ }
589
+ return isWindowsDeviceRoot(code) && len > 2 &&
590
+ path.charCodeAt(1) === CHAR_COLON &&
591
+ isWindowsSeparator(path.charCodeAt(2));
592
+ }
593
+ function win32Join(...paths) {
594
+ if (paths.length === 0) {
595
+ return '.';
596
+ }
597
+ let joined;
598
+ let firstPart = '';
599
+ for (let i = 0; i < paths.length; i += 1) {
600
+ const arg = paths[i];
601
+ assertPath(arg);
602
+ if (arg.length > 0) {
603
+ if (joined === undefined) {
604
+ joined = firstPart = arg;
605
+ }
606
+ else {
607
+ joined += '\\' + arg;
608
+ }
609
+ }
610
+ }
611
+ if (joined === undefined) {
612
+ return '.';
613
+ }
614
+ let needsReplace = true;
615
+ let slashCount = 0;
616
+ if (isWindowsDeviceRoot(firstPart.charCodeAt(0)) && firstPart.charCodeAt(1) === CHAR_COLON) {
617
+ if (isWindowsSeparator(firstPart.charCodeAt(2))) {
618
+ slashCount += 1;
619
+ if (isWindowsSeparator(firstPart.charCodeAt(3))) {
620
+ slashCount += 1;
621
+ }
622
+ }
623
+ }
624
+ else if (isWindowsSeparator(firstPart.charCodeAt(0))) {
625
+ slashCount += 1;
626
+ }
627
+ if (slashCount >= 2 || firstPart.slice(0, 2) === '\\\\') {
628
+ needsReplace = false;
629
+ }
630
+ if (needsReplace) {
631
+ while (slashCount < joined.length && isWindowsSeparator(joined.charCodeAt(slashCount))) {
632
+ slashCount += 1;
633
+ }
634
+ if (slashCount >= 2) {
635
+ joined = '\\' + joined.slice(slashCount);
636
+ }
637
+ }
638
+ return win32Normalize(joined);
639
+ }
640
+ /**
641
+ * 根相对路径(形如 \\server\\share)本身不带盘符,Windows 语义是继承当前盘符。
642
+ * Node 取 process.cwd() 的盘符,QuickJS 没有 process.env,同样取 cwd。
643
+ * 无盘符可用时返回空串,由调用方退回纯根相对形式。
644
+ */
645
+ function win32InheritDrive() {
646
+ const cwd = (0, cwd_1.get)();
647
+ if (cwd.length >= 2 && cwd.charCodeAt(1) === CHAR_COLON) {
648
+ return cwd.slice(0, 2);
649
+ }
650
+ return '';
651
+ }
652
+ function win32Resolve(...paths) {
653
+ let resolvedDevice = '';
654
+ let resolvedTail = '';
655
+ let resolvedAbsolute = false;
656
+ for (let i = paths.length - 1; i >= -1 && !resolvedAbsolute; i -= 1) {
657
+ const path = i >= 0 ? paths[i] : (0, cwd_1.get)();
658
+ assertPath(path);
659
+ if (path.length === 0) {
660
+ continue;
661
+ }
662
+ const len = path.length;
663
+ let rootEnd = 0;
664
+ let device;
665
+ const code = path.charCodeAt(0);
666
+ if (len > 1) {
667
+ if (isWindowsSeparator(code)) {
668
+ rootEnd = 1;
669
+ if (isWindowsSeparator(path.charCodeAt(1))) {
670
+ let j = 2;
671
+ let last = j;
672
+ while (j < len && !isWindowsSeparator(path.charCodeAt(j))) {
673
+ j += 1;
674
+ }
675
+ if (j < len && j !== last) {
676
+ const firstPart = path.slice(last, j);
677
+ last = j;
678
+ while (j < len && isWindowsSeparator(path.charCodeAt(j))) {
679
+ j += 1;
680
+ }
681
+ if (j < len && j !== last) {
682
+ last = j;
683
+ while (j < len && !isWindowsSeparator(path.charCodeAt(j))) {
684
+ j += 1;
685
+ }
686
+ if (j === len) {
687
+ device = '\\\\' + firstPart + '\\' + path.slice(last);
688
+ rootEnd = j;
689
+ }
690
+ else if (j !== last) {
691
+ device = '\\\\' + firstPart + '\\' + path.slice(last, j);
692
+ rootEnd = j;
693
+ }
694
+ }
695
+ }
696
+ }
697
+ }
698
+ else if (isWindowsDeviceRoot(code) && path.charCodeAt(1) === CHAR_COLON) {
699
+ device = path.slice(0, 2);
700
+ rootEnd = 2;
701
+ if (len > 2 && isWindowsSeparator(path.charCodeAt(2))) {
702
+ rootEnd = 3;
703
+ }
704
+ }
705
+ }
706
+ else if (isWindowsSeparator(code)) {
707
+ rootEnd = 1;
708
+ }
709
+ if (device !== undefined && device.toLowerCase() !== resolvedDevice.toLowerCase()) {
710
+ resolvedDevice = device;
711
+ }
712
+ if (!resolvedAbsolute) {
713
+ resolvedTail = path.slice(rootEnd) + '\\' + resolvedTail;
714
+ resolvedAbsolute = rootEnd > 0;
715
+ }
716
+ }
717
+ resolvedTail = normalizeString(resolvedTail, !resolvedAbsolute, '\\', isWindowsSeparator);
718
+ if (resolvedAbsolute) {
719
+ if (resolvedDevice.length > 0) {
720
+ return resolvedDevice + '\\' + resolvedTail;
721
+ }
722
+ const inheritedDrive = win32InheritDrive();
723
+ if (inheritedDrive.length > 0) {
724
+ return inheritedDrive + '\\' + resolvedTail;
725
+ }
726
+ return '\\' + resolvedTail;
727
+ }
728
+ if (resolvedDevice.length > 0) {
729
+ return resolvedDevice + (resolvedTail.length > 0 ? '\\' + resolvedTail : '\\');
730
+ }
731
+ return resolvedTail.length > 0 ? resolvedTail : '.';
732
+ }
733
+ function win32Relative(from, to) {
734
+ assertPath(from);
735
+ assertPath(to);
736
+ if (from === to) {
737
+ return '';
738
+ }
739
+ const fromOrig = win32Resolve(from);
740
+ const toOrig = win32Resolve(to);
741
+ if (fromOrig === toOrig) {
742
+ return '';
743
+ }
744
+ const fromLower = fromOrig.toLowerCase();
745
+ const toLower = toOrig.toLowerCase();
746
+ if (fromLower === toLower) {
747
+ return '';
748
+ }
749
+ let fromStart = 0;
750
+ for (; fromStart < fromLower.length; fromStart += 1) {
751
+ if (fromLower.charCodeAt(fromStart) !== CHAR_BACKWARD_SLASH) {
752
+ break;
753
+ }
754
+ }
755
+ const fromEnd = fromLower.length;
756
+ const fromLen = fromEnd - fromStart;
757
+ let toStart = 0;
758
+ for (; toStart < toLower.length; toStart += 1) {
759
+ if (toLower.charCodeAt(toStart) !== CHAR_BACKWARD_SLASH) {
760
+ break;
761
+ }
762
+ }
763
+ const toEnd = toLower.length;
764
+ const toLen = toEnd - toStart;
765
+ const length = fromLen < toLen ? fromLen : toLen;
766
+ let lastCommonSep = -1;
767
+ let i = 0;
768
+ for (; i <= length; i += 1) {
769
+ if (i === length) {
770
+ if (toLen > length) {
771
+ if (toLower.charCodeAt(toStart + i) === CHAR_BACKWARD_SLASH) {
772
+ return toOrig.slice(toStart + i + 1);
773
+ }
774
+ if (i === 2) {
775
+ return toOrig.slice(toStart + i);
776
+ }
777
+ }
778
+ else if (fromLen > length) {
779
+ if (fromLower.charCodeAt(fromStart + i) === CHAR_BACKWARD_SLASH) {
780
+ lastCommonSep = i;
781
+ }
782
+ else if (i === 2) {
783
+ lastCommonSep = 3;
784
+ }
785
+ }
786
+ break;
787
+ }
788
+ const fromCode = fromLower.charCodeAt(fromStart + i);
789
+ const toCode = toLower.charCodeAt(toStart + i);
790
+ if (fromCode !== toCode) {
791
+ break;
792
+ }
793
+ else if (fromCode === CHAR_BACKWARD_SLASH) {
794
+ lastCommonSep = i;
795
+ }
796
+ }
797
+ if (lastCommonSep === -1) {
798
+ lastCommonSep = 0;
799
+ }
800
+ let out = '';
801
+ for (i = fromStart + lastCommonSep + 1; i <= fromEnd; i += 1) {
802
+ if (i === fromEnd || fromLower.charCodeAt(i) === CHAR_BACKWARD_SLASH) {
803
+ out += out.length === 0 ? '..' : '\\..';
804
+ }
805
+ }
806
+ toStart += lastCommonSep;
807
+ if (out.length > 0) {
808
+ return out + toOrig.slice(toStart, toEnd);
809
+ }
810
+ if (toStart === 2) {
811
+ return toOrig.slice(2);
812
+ }
813
+ return toOrig.slice(toStart, toEnd);
814
+ }
815
+ function win32Dirname(path) {
816
+ assertPath(path);
817
+ const len = path.length;
818
+ if (len === 0) {
819
+ return '.';
820
+ }
821
+ let rootEnd = -1;
822
+ let end = -1;
823
+ let matchedSlash = true;
824
+ let offset = 0;
825
+ const code = path.charCodeAt(0);
826
+ if (len > 1) {
827
+ if (isWindowsSeparator(code)) {
828
+ rootEnd = offset = 1;
829
+ if (isWindowsSeparator(path.charCodeAt(1))) {
830
+ let j = 2;
831
+ let last = j;
832
+ while (j < len && !isWindowsSeparator(path.charCodeAt(j))) {
833
+ j += 1;
834
+ }
835
+ if (j < len && j !== last) {
836
+ last = j;
837
+ while (j < len && isWindowsSeparator(path.charCodeAt(j))) {
838
+ j += 1;
839
+ }
840
+ if (j < len && j !== last) {
841
+ last = j;
842
+ while (j < len && !isWindowsSeparator(path.charCodeAt(j))) {
843
+ j += 1;
844
+ }
845
+ if (j === len || j !== last) {
846
+ rootEnd = j;
847
+ }
848
+ }
849
+ }
850
+ }
851
+ }
852
+ else if (isWindowsDeviceRoot(code) && path.charCodeAt(1) === CHAR_COLON) {
853
+ rootEnd = 2;
854
+ offset = 2;
855
+ if (len > 2 && isWindowsSeparator(path.charCodeAt(2))) {
856
+ if (len === 3) {
857
+ return path;
858
+ }
859
+ rootEnd = 3;
860
+ offset = 3;
861
+ }
862
+ }
863
+ }
864
+ else if (isWindowsSeparator(code)) {
865
+ rootEnd = offset = 1;
866
+ }
867
+ for (let i = len - 1; i >= offset; i -= 1) {
868
+ if (isWindowsSeparator(path.charCodeAt(i))) {
869
+ if (!matchedSlash) {
870
+ end = i;
871
+ break;
872
+ }
873
+ }
874
+ else {
875
+ matchedSlash = false;
876
+ }
877
+ }
878
+ if (end === -1) {
879
+ return rootEnd === -1 ? '.' : path.slice(0, rootEnd);
880
+ }
881
+ if (rootEnd === -1) {
882
+ return path.slice(0, end);
883
+ }
884
+ if (end === rootEnd && rootEnd >= 1 && isWindowsSeparator(path.charCodeAt(rootEnd - 1))) {
885
+ if (rootEnd === 1) {
886
+ return '\\';
887
+ }
888
+ return path.slice(0, rootEnd);
889
+ }
890
+ return path.slice(0, end);
891
+ }
892
+ /** win32 路径的根长度:0 表示无根(相对路径)。 */
893
+ function win32RootEnd(path) {
894
+ const len = path.length;
895
+ if (len === 0) {
896
+ return 0;
897
+ }
898
+ const first = path.charCodeAt(0);
899
+ if (isWindowsSeparator(first)) {
900
+ if (len > 1 && isWindowsSeparator(path.charCodeAt(1))) {
901
+ let j = 2;
902
+ let last = j;
903
+ while (j < len && !isWindowsSeparator(path.charCodeAt(j))) {
904
+ j += 1;
905
+ }
906
+ if (j < len && j !== last) {
907
+ last = j;
908
+ while (j < len && isWindowsSeparator(path.charCodeAt(j))) {
909
+ j += 1;
910
+ }
911
+ if (j < len && j !== last) {
912
+ last = j;
913
+ while (j < len && !isWindowsSeparator(path.charCodeAt(j))) {
914
+ j += 1;
915
+ }
916
+ return j;
917
+ }
918
+ }
919
+ return 0;
920
+ }
921
+ return 1;
922
+ }
923
+ if (isWindowsDeviceRoot(first) && len > 1 && path.charCodeAt(1) === CHAR_COLON) {
924
+ if (len > 2 && isWindowsSeparator(path.charCodeAt(2))) {
925
+ return 3;
926
+ }
927
+ return 2;
928
+ }
929
+ return 0;
930
+ }
931
+ function win32Basename(path, ext) {
932
+ if (ext !== undefined && typeof ext !== 'string') {
933
+ throw new TypeError('"ext" argument must be a string');
934
+ }
935
+ assertPath(path);
936
+ // 根本身没有 basename(Node: basename('C:') === '')
937
+ const rootEnd = win32RootEnd(path);
938
+ let start = 0;
939
+ let end = -1;
940
+ let matchedSlash = true;
941
+ let i;
942
+ if (ext !== undefined && ext.length > 0 && ext.length <= path.length) {
943
+ if (ext.length === path.length && ext === path) {
944
+ return '';
945
+ }
946
+ let extIdx = ext.length - 1;
947
+ let firstNonSlashEnd = -1;
948
+ for (i = path.length - 1; i >= 0; i -= 1) {
949
+ const code = path.charCodeAt(i);
950
+ if (isWindowsSeparator(code)) {
951
+ if (!matchedSlash) {
952
+ start = i + 1;
953
+ break;
954
+ }
955
+ }
956
+ else {
957
+ if (firstNonSlashEnd === -1) {
958
+ matchedSlash = false;
959
+ firstNonSlashEnd = i + 1;
960
+ }
961
+ if (extIdx >= 0) {
962
+ if (code === ext.charCodeAt(extIdx)) {
963
+ extIdx -= 1;
964
+ if (extIdx === -1) {
965
+ end = i;
966
+ }
967
+ }
968
+ else {
969
+ extIdx = -1;
970
+ end = firstNonSlashEnd;
971
+ }
972
+ }
973
+ }
974
+ }
975
+ if (start === end) {
976
+ end = firstNonSlashEnd;
977
+ }
978
+ else if (end === -1) {
979
+ end = path.length;
980
+ }
981
+ return path.slice(start < rootEnd ? rootEnd : start, end);
982
+ }
983
+ for (i = path.length - 1; i >= 0; i -= 1) {
984
+ if (isWindowsSeparator(path.charCodeAt(i))) {
985
+ if (!matchedSlash) {
986
+ start = i + 1;
987
+ break;
988
+ }
989
+ }
990
+ else if (end === -1) {
991
+ matchedSlash = false;
992
+ end = i + 1;
993
+ }
994
+ }
995
+ if (end === -1) {
996
+ return '';
997
+ }
998
+ return path.slice(start < rootEnd ? rootEnd : start, end);
999
+ }
1000
+ function win32Extname(path) {
1001
+ assertPath(path);
1002
+ let startDot = -1;
1003
+ let startPart = 0;
1004
+ let end = -1;
1005
+ let matchedSlash = true;
1006
+ let preDotState = 0;
1007
+ for (let i = path.length - 1; i >= 0; i -= 1) {
1008
+ const code = path.charCodeAt(i);
1009
+ if (isWindowsSeparator(code)) {
1010
+ if (!matchedSlash) {
1011
+ startPart = i + 1;
1012
+ break;
1013
+ }
1014
+ continue;
1015
+ }
1016
+ if (end === -1) {
1017
+ matchedSlash = false;
1018
+ end = i + 1;
1019
+ }
1020
+ if (code === CHAR_DOT) {
1021
+ if (startDot === -1) {
1022
+ startDot = i;
1023
+ }
1024
+ else if (preDotState !== 1) {
1025
+ preDotState = 1;
1026
+ }
1027
+ }
1028
+ else if (startDot !== -1) {
1029
+ preDotState = -1;
1030
+ }
1031
+ }
1032
+ if (startDot === -1 ||
1033
+ end === -1 ||
1034
+ preDotState === 0 ||
1035
+ (preDotState === 1 && startDot === end - 1 && startDot === startPart + 1)) {
1036
+ return '';
1037
+ }
1038
+ return path.slice(startDot, end);
1039
+ }
1040
+ function win32Format(pathObject) {
1041
+ if (pathObject === null || typeof pathObject !== 'object') {
1042
+ throw new TypeError('The "pathObject" argument must be of type object. Received type ' + typeof pathObject);
1043
+ }
1044
+ const dir = pathObject.dir ?? pathObject.root;
1045
+ const base = pathObject.base ?? (pathObject.name ?? '') + (pathObject.ext ?? '');
1046
+ if (dir === undefined || dir.length === 0) {
1047
+ return base;
1048
+ }
1049
+ if (dir === pathObject.root) {
1050
+ return dir + base;
1051
+ }
1052
+ return dir + '\\' + base;
1053
+ }
1054
+ function win32Parse(path) {
1055
+ assertPath(path);
1056
+ const ret = { root: '', dir: '', base: '', ext: '', name: '' };
1057
+ if (path.length === 0) {
1058
+ return ret;
1059
+ }
1060
+ const len = path.length;
1061
+ let rootEnd = 0;
1062
+ const firstCode = path.charCodeAt(0);
1063
+ let isAbsolute = false;
1064
+ if (len === 1) {
1065
+ if (isWindowsSeparator(firstCode)) {
1066
+ ret.root = ret.dir = path;
1067
+ return ret;
1068
+ }
1069
+ ret.base = ret.name = path;
1070
+ return ret;
1071
+ }
1072
+ if (isWindowsSeparator(firstCode)) {
1073
+ isAbsolute = true;
1074
+ if (isWindowsSeparator(path.charCodeAt(1))) {
1075
+ let j = 2;
1076
+ let last = j;
1077
+ while (j < len && !isWindowsSeparator(path.charCodeAt(j))) {
1078
+ j += 1;
1079
+ }
1080
+ if (j < len && j !== last) {
1081
+ last = j;
1082
+ while (j < len && isWindowsSeparator(path.charCodeAt(j))) {
1083
+ j += 1;
1084
+ }
1085
+ if (j < len && j !== last) {
1086
+ last = j;
1087
+ while (j < len && !isWindowsSeparator(path.charCodeAt(j))) {
1088
+ j += 1;
1089
+ }
1090
+ if (j === len || j !== last) {
1091
+ rootEnd = j;
1092
+ }
1093
+ }
1094
+ }
1095
+ }
1096
+ else {
1097
+ rootEnd = 1;
1098
+ }
1099
+ }
1100
+ else if (isWindowsDeviceRoot(firstCode) && len > 1 && path.charCodeAt(1) === CHAR_COLON) {
1101
+ rootEnd = 2;
1102
+ if (len > 2 && isWindowsSeparator(path.charCodeAt(2))) {
1103
+ isAbsolute = true;
1104
+ rootEnd = 3;
1105
+ }
1106
+ }
1107
+ if (rootEnd > 0) {
1108
+ ret.root = path.slice(0, rootEnd);
1109
+ }
1110
+ let startDot = -1;
1111
+ let startPart = rootEnd;
1112
+ let end = -1;
1113
+ let matchedSlash = true;
1114
+ let i = path.length - 1;
1115
+ let preDotState = 0;
1116
+ for (; i >= rootEnd; i -= 1) {
1117
+ const code = path.charCodeAt(i);
1118
+ if (isWindowsSeparator(code)) {
1119
+ if (!matchedSlash) {
1120
+ startPart = i + 1;
1121
+ break;
1122
+ }
1123
+ continue;
1124
+ }
1125
+ if (end === -1) {
1126
+ matchedSlash = false;
1127
+ end = i + 1;
1128
+ }
1129
+ if (code === CHAR_DOT) {
1130
+ if (startDot === -1) {
1131
+ startDot = i;
1132
+ }
1133
+ else if (preDotState !== 1) {
1134
+ preDotState = 1;
1135
+ }
1136
+ }
1137
+ else if (startDot !== -1) {
1138
+ preDotState = -1;
1139
+ }
1140
+ }
1141
+ if (end !== -1) {
1142
+ const sliceStart = startPart === 0 && isAbsolute ? 1 : startPart;
1143
+ if (startDot === -1 ||
1144
+ preDotState === 0 ||
1145
+ (preDotState === 1 && startDot === end - 1 && startDot === startPart + 1)) {
1146
+ ret.base = ret.name = path.slice(sliceStart, end);
1147
+ }
1148
+ else {
1149
+ ret.name = path.slice(sliceStart, startDot);
1150
+ ret.base = path.slice(sliceStart, end);
1151
+ ret.ext = path.slice(startDot, end);
1152
+ }
1153
+ }
1154
+ if (startPart > 0 && startPart !== rootEnd) {
1155
+ ret.dir = path.slice(0, startPart - 1);
1156
+ }
1157
+ else if (rootEnd > 0) {
1158
+ ret.dir = ret.root;
1159
+ }
1160
+ return ret;
1161
+ }
1162
+ function win32ToNamespacedPath(path) {
1163
+ if (typeof path !== 'string' || path.length === 0) {
1164
+ return path;
1165
+ }
1166
+ const resolvedPath = win32Resolve(path);
1167
+ if (resolvedPath.length >= 2) {
1168
+ if (resolvedPath.charCodeAt(0) === CHAR_BACKWARD_SLASH) {
1169
+ if (resolvedPath.charCodeAt(1) === CHAR_BACKWARD_SLASH) {
1170
+ const code = resolvedPath.charCodeAt(2);
1171
+ if (code !== 63 && code !== 46) {
1172
+ return '\\\\?\\UNC\\' + resolvedPath.slice(2);
1173
+ }
1174
+ }
1175
+ }
1176
+ else if (isWindowsDeviceRoot(resolvedPath.charCodeAt(0)) &&
1177
+ resolvedPath.charCodeAt(1) === CHAR_COLON &&
1178
+ resolvedPath.charCodeAt(2) === CHAR_BACKWARD_SLASH) {
1179
+ return '\\\\?\\' + resolvedPath;
1180
+ }
1181
+ }
1182
+ return resolvedPath;
1183
+ }
1184
+ const posix = {
1185
+ resolve: posixResolve,
1186
+ normalize: posixNormalize,
1187
+ isAbsolute: posixIsAbsolute,
1188
+ join: posixJoin,
1189
+ relative: posixRelative,
1190
+ toNamespacedPath: posixToNamespacedPath,
1191
+ dirname: posixDirname,
1192
+ basename: posixBasename,
1193
+ extname: posixExtname,
1194
+ format: posixFormat,
1195
+ parse: posixParse,
1196
+ sep: '/',
1197
+ delimiter: ':',
1198
+ win32: undefined,
1199
+ posix: undefined
1200
+ };
1201
+ const win32 = {
1202
+ resolve: win32Resolve,
1203
+ normalize: win32Normalize,
1204
+ isAbsolute: win32IsAbsolute,
1205
+ join: win32Join,
1206
+ relative: win32Relative,
1207
+ toNamespacedPath: win32ToNamespacedPath,
1208
+ dirname: win32Dirname,
1209
+ basename: win32Basename,
1210
+ extname: win32Extname,
1211
+ format: win32Format,
1212
+ parse: win32Parse,
1213
+ sep: '\\',
1214
+ delimiter: ';',
1215
+ win32: undefined,
1216
+ posix: undefined
1217
+ };
1218
+ posix.win32 = win32;
1219
+ posix.posix = posix;
1220
+ win32.win32 = win32;
1221
+ win32.posix = posix;
1222
+ module.exports = posix;