@dsherret/path 0.3.3

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.
package/esm/mod.js ADDED
@@ -0,0 +1,2559 @@
1
+ // npm/esm/_dnt.shims.js
2
+ var dntGlobalThis = globalThis;
3
+
4
+ // npm/esm/deps/jsr.io/@std/internal/1.0.14/_os.js
5
+ function checkWindows() {
6
+ const global = dntGlobalThis;
7
+ const platform = global.process?.platform;
8
+ if (typeof platform === "string")
9
+ return platform.startsWith("win");
10
+ const os = global.Deno?.build?.os;
11
+ if (typeof os === "string")
12
+ return os === "windows";
13
+ return global.navigator?.platform?.startsWith("Win") ?? false;
14
+ }
15
+
16
+ // npm/esm/deps/jsr.io/@std/internal/1.0.14/os.js
17
+ var isWindows = checkWindows();
18
+
19
+ // npm/esm/deps/jsr.io/@std/path/1.1.6/_common/assert_path.js
20
+ function assertPath(path2) {
21
+ if (typeof path2 !== "string") {
22
+ throw new TypeError(`Path must be a string, received "${JSON.stringify(path2)}"`);
23
+ }
24
+ }
25
+
26
+ // npm/esm/deps/jsr.io/@std/path/1.1.6/_common/basename.js
27
+ function stripSuffix(name, suffix) {
28
+ if (suffix.length >= name.length) {
29
+ return name;
30
+ }
31
+ const lenDiff = name.length - suffix.length;
32
+ for (let i = suffix.length - 1; i >= 0; --i) {
33
+ if (name.charCodeAt(lenDiff + i) !== suffix.charCodeAt(i)) {
34
+ return name;
35
+ }
36
+ }
37
+ return name.slice(0, -suffix.length);
38
+ }
39
+ function lastPathSegment(path2, isSep, start = 0) {
40
+ let matchedNonSeparator = false;
41
+ let end = path2.length;
42
+ for (let i = path2.length - 1; i >= start; --i) {
43
+ if (isSep(path2.charCodeAt(i))) {
44
+ if (matchedNonSeparator) {
45
+ start = i + 1;
46
+ break;
47
+ }
48
+ } else if (!matchedNonSeparator) {
49
+ matchedNonSeparator = true;
50
+ end = i + 1;
51
+ }
52
+ }
53
+ return path2.slice(start, end);
54
+ }
55
+ function assertArgs(path2, suffix) {
56
+ assertPath(path2);
57
+ if (path2.length === 0)
58
+ return path2;
59
+ if (typeof suffix !== "string") {
60
+ throw new TypeError(`Suffix must be a string, received "${JSON.stringify(suffix)}"`);
61
+ }
62
+ }
63
+
64
+ // npm/esm/deps/jsr.io/@std/path/1.1.6/_common/from_file_url.js
65
+ function assertArg(url) {
66
+ url = url instanceof URL ? url : new URL(url);
67
+ if (url.protocol !== "file:") {
68
+ throw new TypeError(`URL must be a file URL: received "${url.protocol}"`);
69
+ }
70
+ return url;
71
+ }
72
+
73
+ // npm/esm/deps/jsr.io/@std/path/1.1.6/posix/from_file_url.js
74
+ function fromFileUrl(url) {
75
+ url = assertArg(url);
76
+ return decodeURIComponent(url.pathname.replace(/%(?![0-9A-Fa-f]{2})/g, "%25"));
77
+ }
78
+
79
+ // npm/esm/deps/jsr.io/@std/path/1.1.6/_common/strip_trailing_separators.js
80
+ function stripTrailingSeparators(segment, isSep) {
81
+ if (segment.length <= 1) {
82
+ return segment;
83
+ }
84
+ let end = segment.length;
85
+ for (let i = segment.length - 1; i > 0; i--) {
86
+ if (isSep(segment.charCodeAt(i))) {
87
+ end = i;
88
+ } else {
89
+ break;
90
+ }
91
+ }
92
+ return segment.slice(0, end);
93
+ }
94
+
95
+ // npm/esm/deps/jsr.io/@std/path/1.1.6/_common/constants.js
96
+ var CHAR_UPPERCASE_A = 65;
97
+ var CHAR_LOWERCASE_A = 97;
98
+ var CHAR_UPPERCASE_Z = 90;
99
+ var CHAR_LOWERCASE_Z = 122;
100
+ var CHAR_DOT = 46;
101
+ var CHAR_FORWARD_SLASH = 47;
102
+ var CHAR_BACKWARD_SLASH = 92;
103
+ var CHAR_COLON = 58;
104
+
105
+ // npm/esm/deps/jsr.io/@std/path/1.1.6/posix/_util.js
106
+ function isPosixPathSeparator(code) {
107
+ return code === CHAR_FORWARD_SLASH;
108
+ }
109
+
110
+ // npm/esm/deps/jsr.io/@std/path/1.1.6/posix/basename.js
111
+ function basename(path2, suffix = "") {
112
+ if (path2 instanceof URL) {
113
+ path2 = fromFileUrl(path2);
114
+ }
115
+ assertArgs(path2, suffix);
116
+ const lastSegment = lastPathSegment(path2, isPosixPathSeparator);
117
+ const strippedSegment = stripTrailingSeparators(lastSegment, isPosixPathSeparator);
118
+ return suffix ? stripSuffix(strippedSegment, suffix) : strippedSegment;
119
+ }
120
+
121
+ // npm/esm/deps/jsr.io/@std/path/1.1.6/windows/_util.js
122
+ function isPosixPathSeparator2(code) {
123
+ return code === CHAR_FORWARD_SLASH;
124
+ }
125
+ function isPathSeparator(code) {
126
+ return code === CHAR_FORWARD_SLASH || code === CHAR_BACKWARD_SLASH;
127
+ }
128
+ function isWindowsDeviceRoot(code) {
129
+ return code >= CHAR_LOWERCASE_A && code <= CHAR_LOWERCASE_Z || code >= CHAR_UPPERCASE_A && code <= CHAR_UPPERCASE_Z;
130
+ }
131
+
132
+ // npm/esm/deps/jsr.io/@std/path/1.1.6/windows/from_file_url.js
133
+ function fromFileUrl2(url) {
134
+ url = assertArg(url);
135
+ let path2 = decodeURIComponent(url.pathname.replace(/\//g, "\\").replace(/%(?![0-9A-Fa-f]{2})/g, "%25")).replace(/^\\*([A-Za-z]:)(\\|$)/, "$1\\");
136
+ if (url.hostname !== "") {
137
+ path2 = `\\\\${url.hostname}${path2}`;
138
+ }
139
+ return path2;
140
+ }
141
+
142
+ // npm/esm/deps/jsr.io/@std/path/1.1.6/windows/basename.js
143
+ function basename2(path2, suffix = "") {
144
+ if (path2 instanceof URL) {
145
+ path2 = fromFileUrl2(path2);
146
+ }
147
+ assertArgs(path2, suffix);
148
+ let start = 0;
149
+ if (path2.length >= 2) {
150
+ const drive = path2.charCodeAt(0);
151
+ if (isWindowsDeviceRoot(drive)) {
152
+ if (path2.charCodeAt(1) === CHAR_COLON)
153
+ start = 2;
154
+ }
155
+ }
156
+ const lastSegment = lastPathSegment(path2, isPathSeparator, start);
157
+ const strippedSegment = stripTrailingSeparators(lastSegment, isPathSeparator);
158
+ return suffix ? stripSuffix(strippedSegment, suffix) : strippedSegment;
159
+ }
160
+
161
+ // npm/esm/deps/jsr.io/@std/path/1.1.6/basename.js
162
+ function basename3(path2, suffix = "") {
163
+ return isWindows ? basename2(path2, suffix) : basename(path2, suffix);
164
+ }
165
+
166
+ // npm/esm/deps/jsr.io/@std/path/1.1.6/_common/dirname.js
167
+ function assertArg2(path2) {
168
+ assertPath(path2);
169
+ if (path2.length === 0)
170
+ return ".";
171
+ }
172
+
173
+ // npm/esm/deps/jsr.io/@std/path/1.1.6/posix/dirname.js
174
+ function dirname(path2) {
175
+ if (path2 instanceof URL) {
176
+ path2 = fromFileUrl(path2);
177
+ }
178
+ assertArg2(path2);
179
+ let end = -1;
180
+ let matchedNonSeparator = false;
181
+ for (let i = path2.length - 1; i >= 1; --i) {
182
+ if (isPosixPathSeparator(path2.charCodeAt(i))) {
183
+ if (matchedNonSeparator) {
184
+ end = i;
185
+ break;
186
+ }
187
+ } else {
188
+ matchedNonSeparator = true;
189
+ }
190
+ }
191
+ if (end === -1) {
192
+ return isPosixPathSeparator(path2.charCodeAt(0)) ? "/" : ".";
193
+ }
194
+ return stripTrailingSeparators(path2.slice(0, end), isPosixPathSeparator);
195
+ }
196
+
197
+ // npm/esm/deps/jsr.io/@std/path/1.1.6/windows/dirname.js
198
+ function dirname2(path2) {
199
+ if (path2 instanceof URL) {
200
+ path2 = fromFileUrl2(path2);
201
+ }
202
+ assertArg2(path2);
203
+ const len = path2.length;
204
+ let rootEnd = -1;
205
+ let end = -1;
206
+ let matchedSlash = true;
207
+ let offset = 0;
208
+ const code = path2.charCodeAt(0);
209
+ if (len > 1) {
210
+ if (isPathSeparator(code)) {
211
+ rootEnd = offset = 1;
212
+ if (isPathSeparator(path2.charCodeAt(1))) {
213
+ let j = 2;
214
+ let last = j;
215
+ for (; j < len; ++j) {
216
+ if (isPathSeparator(path2.charCodeAt(j)))
217
+ break;
218
+ }
219
+ if (j < len && j !== last) {
220
+ last = j;
221
+ for (; j < len; ++j) {
222
+ if (!isPathSeparator(path2.charCodeAt(j)))
223
+ break;
224
+ }
225
+ if (j < len && j !== last) {
226
+ last = j;
227
+ for (; j < len; ++j) {
228
+ if (isPathSeparator(path2.charCodeAt(j)))
229
+ break;
230
+ }
231
+ if (j === len) {
232
+ return path2;
233
+ }
234
+ if (j !== last) {
235
+ rootEnd = offset = j + 1;
236
+ }
237
+ }
238
+ }
239
+ }
240
+ } else if (isWindowsDeviceRoot(code)) {
241
+ if (path2.charCodeAt(1) === CHAR_COLON) {
242
+ rootEnd = offset = 2;
243
+ if (len > 2) {
244
+ if (isPathSeparator(path2.charCodeAt(2)))
245
+ rootEnd = offset = 3;
246
+ }
247
+ }
248
+ }
249
+ } else if (isPathSeparator(code)) {
250
+ return path2;
251
+ }
252
+ for (let i = len - 1; i >= offset; --i) {
253
+ if (isPathSeparator(path2.charCodeAt(i))) {
254
+ if (!matchedSlash) {
255
+ end = i;
256
+ break;
257
+ }
258
+ } else {
259
+ matchedSlash = false;
260
+ }
261
+ }
262
+ if (end === -1) {
263
+ if (rootEnd === -1)
264
+ return ".";
265
+ else
266
+ end = rootEnd;
267
+ }
268
+ return stripTrailingSeparators(path2.slice(0, end), isPosixPathSeparator2);
269
+ }
270
+
271
+ // npm/esm/deps/jsr.io/@std/path/1.1.6/dirname.js
272
+ function dirname3(path2) {
273
+ return isWindows ? dirname2(path2) : dirname(path2);
274
+ }
275
+
276
+ // npm/esm/deps/jsr.io/@std/path/1.1.6/posix/extname.js
277
+ function extname(path2) {
278
+ if (path2 instanceof URL) {
279
+ path2 = fromFileUrl(path2);
280
+ }
281
+ assertPath(path2);
282
+ let startDot = -1;
283
+ let startPart = 0;
284
+ let end = -1;
285
+ let matchedSlash = true;
286
+ let preDotState = 0;
287
+ for (let i = path2.length - 1; i >= 0; --i) {
288
+ const code = path2.charCodeAt(i);
289
+ if (isPosixPathSeparator(code)) {
290
+ if (!matchedSlash) {
291
+ startPart = i + 1;
292
+ break;
293
+ }
294
+ continue;
295
+ }
296
+ if (end === -1) {
297
+ matchedSlash = false;
298
+ end = i + 1;
299
+ }
300
+ if (code === CHAR_DOT) {
301
+ if (startDot === -1)
302
+ startDot = i;
303
+ else if (preDotState !== 1)
304
+ preDotState = 1;
305
+ } else if (startDot !== -1) {
306
+ preDotState = -1;
307
+ }
308
+ }
309
+ if (startDot === -1 || end === -1 || // We saw a non-dot character immediately before the dot
310
+ preDotState === 0 || // The (right-most) trimmed path component is exactly '..'
311
+ preDotState === 1 && startDot === end - 1 && startDot === startPart + 1) {
312
+ return "";
313
+ }
314
+ return path2.slice(startDot, end);
315
+ }
316
+
317
+ // npm/esm/deps/jsr.io/@std/path/1.1.6/windows/extname.js
318
+ function extname2(path2) {
319
+ if (path2 instanceof URL) {
320
+ path2 = fromFileUrl2(path2);
321
+ }
322
+ assertPath(path2);
323
+ let start = 0;
324
+ let startDot = -1;
325
+ let startPart = 0;
326
+ let end = -1;
327
+ let matchedSlash = true;
328
+ let preDotState = 0;
329
+ if (path2.length >= 2 && path2.charCodeAt(1) === CHAR_COLON && isWindowsDeviceRoot(path2.charCodeAt(0))) {
330
+ start = startPart = 2;
331
+ }
332
+ for (let i = path2.length - 1; i >= start; --i) {
333
+ const code = path2.charCodeAt(i);
334
+ if (isPathSeparator(code)) {
335
+ if (!matchedSlash) {
336
+ startPart = i + 1;
337
+ break;
338
+ }
339
+ continue;
340
+ }
341
+ if (end === -1) {
342
+ matchedSlash = false;
343
+ end = i + 1;
344
+ }
345
+ if (code === CHAR_DOT) {
346
+ if (startDot === -1)
347
+ startDot = i;
348
+ else if (preDotState !== 1)
349
+ preDotState = 1;
350
+ } else if (startDot !== -1) {
351
+ preDotState = -1;
352
+ }
353
+ }
354
+ if (startDot === -1 || end === -1 || // We saw a non-dot character immediately before the dot
355
+ preDotState === 0 || // The (right-most) trimmed path component is exactly '..'
356
+ preDotState === 1 && startDot === end - 1 && startDot === startPart + 1) {
357
+ return "";
358
+ }
359
+ return path2.slice(startDot, end);
360
+ }
361
+
362
+ // npm/esm/deps/jsr.io/@std/path/1.1.6/extname.js
363
+ function extname3(path2) {
364
+ return isWindows ? extname2(path2) : extname(path2);
365
+ }
366
+
367
+ // npm/esm/deps/jsr.io/@std/path/1.1.6/from_file_url.js
368
+ function fromFileUrl3(url) {
369
+ return isWindows ? fromFileUrl2(url) : fromFileUrl(url);
370
+ }
371
+
372
+ // npm/esm/deps/jsr.io/@std/path/1.1.6/posix/is_absolute.js
373
+ function isAbsolute(path2) {
374
+ assertPath(path2);
375
+ return path2.length > 0 && isPosixPathSeparator(path2.charCodeAt(0));
376
+ }
377
+
378
+ // npm/esm/deps/jsr.io/@std/path/1.1.6/windows/is_absolute.js
379
+ function isAbsolute2(path2) {
380
+ assertPath(path2);
381
+ const len = path2.length;
382
+ if (len === 0)
383
+ return false;
384
+ const code = path2.charCodeAt(0);
385
+ if (isPathSeparator(code)) {
386
+ return true;
387
+ } else if (isWindowsDeviceRoot(code)) {
388
+ if (len > 2 && path2.charCodeAt(1) === CHAR_COLON) {
389
+ if (isPathSeparator(path2.charCodeAt(2)))
390
+ return true;
391
+ }
392
+ }
393
+ return false;
394
+ }
395
+
396
+ // npm/esm/deps/jsr.io/@std/path/1.1.6/is_absolute.js
397
+ function isAbsolute3(path2) {
398
+ return isWindows ? isAbsolute2(path2) : isAbsolute(path2);
399
+ }
400
+
401
+ // npm/esm/deps/jsr.io/@std/path/1.1.6/_common/normalize.js
402
+ function assertArg4(path2) {
403
+ assertPath(path2);
404
+ if (path2.length === 0)
405
+ return ".";
406
+ }
407
+
408
+ // npm/esm/deps/jsr.io/@std/path/1.1.6/_common/normalize_string.js
409
+ function normalizeString(path2, allowAboveRoot, separator, isPathSeparator2) {
410
+ let res = "";
411
+ let lastSegmentLength = 0;
412
+ let lastSlash = -1;
413
+ let dots = 0;
414
+ let code;
415
+ for (let i = 0; i <= path2.length; ++i) {
416
+ if (i < path2.length)
417
+ code = path2.charCodeAt(i);
418
+ else if (isPathSeparator2(code))
419
+ break;
420
+ else
421
+ code = CHAR_FORWARD_SLASH;
422
+ if (isPathSeparator2(code)) {
423
+ if (lastSlash === i - 1 || dots === 1) {
424
+ } else if (lastSlash !== i - 1 && dots === 2) {
425
+ if (res.length < 2 || lastSegmentLength !== 2 || res.charCodeAt(res.length - 1) !== CHAR_DOT || res.charCodeAt(res.length - 2) !== CHAR_DOT) {
426
+ if (res.length > 2) {
427
+ const lastSlashIndex = res.lastIndexOf(separator);
428
+ if (lastSlashIndex === -1) {
429
+ res = "";
430
+ lastSegmentLength = 0;
431
+ } else {
432
+ res = res.slice(0, lastSlashIndex);
433
+ lastSegmentLength = res.length - 1 - res.lastIndexOf(separator);
434
+ }
435
+ lastSlash = i;
436
+ dots = 0;
437
+ continue;
438
+ } else if (res.length === 2 || res.length === 1) {
439
+ res = "";
440
+ lastSegmentLength = 0;
441
+ lastSlash = i;
442
+ dots = 0;
443
+ continue;
444
+ }
445
+ }
446
+ if (allowAboveRoot) {
447
+ if (res.length > 0)
448
+ res += `${separator}..`;
449
+ else
450
+ res = "..";
451
+ lastSegmentLength = 2;
452
+ }
453
+ } else {
454
+ if (res.length > 0)
455
+ res += separator + path2.slice(lastSlash + 1, i);
456
+ else
457
+ res = path2.slice(lastSlash + 1, i);
458
+ lastSegmentLength = i - lastSlash - 1;
459
+ }
460
+ lastSlash = i;
461
+ dots = 0;
462
+ } else if (code === CHAR_DOT && dots !== -1) {
463
+ ++dots;
464
+ } else {
465
+ dots = -1;
466
+ }
467
+ }
468
+ return res;
469
+ }
470
+
471
+ // npm/esm/deps/jsr.io/@std/path/1.1.6/posix/normalize.js
472
+ function normalize(path2) {
473
+ if (path2 instanceof URL) {
474
+ path2 = fromFileUrl(path2);
475
+ }
476
+ assertArg4(path2);
477
+ const isAbsolute4 = isPosixPathSeparator(path2.charCodeAt(0));
478
+ const trailingSeparator = isPosixPathSeparator(path2.charCodeAt(path2.length - 1));
479
+ path2 = normalizeString(path2, !isAbsolute4, "/", isPosixPathSeparator);
480
+ if (path2.length === 0 && !isAbsolute4)
481
+ path2 = ".";
482
+ if (path2.length > 0 && trailingSeparator)
483
+ path2 += "/";
484
+ if (isAbsolute4)
485
+ return `/${path2}`;
486
+ return path2;
487
+ }
488
+
489
+ // npm/esm/deps/jsr.io/@std/path/1.1.6/posix/join.js
490
+ function join(path2, ...paths) {
491
+ if (path2 === void 0)
492
+ return ".";
493
+ if (path2 instanceof URL) {
494
+ path2 = fromFileUrl(path2);
495
+ }
496
+ paths = path2 ? [path2, ...paths] : paths;
497
+ paths.forEach((path3) => assertPath(path3));
498
+ const joined = paths.filter((path3) => path3.length > 0).join("/");
499
+ return joined === "" ? "." : normalize(joined);
500
+ }
501
+
502
+ // npm/esm/deps/jsr.io/@std/path/1.1.6/windows/normalize.js
503
+ function normalize2(path2) {
504
+ if (path2 instanceof URL) {
505
+ path2 = fromFileUrl2(path2);
506
+ }
507
+ assertArg4(path2);
508
+ const len = path2.length;
509
+ let rootEnd = 0;
510
+ let device;
511
+ let isAbsolute4 = false;
512
+ const code = path2.charCodeAt(0);
513
+ if (len > 1) {
514
+ if (isPathSeparator(code)) {
515
+ isAbsolute4 = true;
516
+ if (isPathSeparator(path2.charCodeAt(1))) {
517
+ let j = 2;
518
+ let last = j;
519
+ for (; j < len; ++j) {
520
+ if (isPathSeparator(path2.charCodeAt(j)))
521
+ break;
522
+ }
523
+ if (j < len && j !== last) {
524
+ const firstPart = path2.slice(last, j);
525
+ last = j;
526
+ for (; j < len; ++j) {
527
+ if (!isPathSeparator(path2.charCodeAt(j)))
528
+ break;
529
+ }
530
+ if (j < len && j !== last) {
531
+ last = j;
532
+ for (; j < len; ++j) {
533
+ if (isPathSeparator(path2.charCodeAt(j)))
534
+ break;
535
+ }
536
+ if (j === len) {
537
+ return `\\\\${firstPart}\\${path2.slice(last)}\\`;
538
+ } else if (j !== last) {
539
+ device = `\\\\${firstPart}\\${path2.slice(last, j)}`;
540
+ rootEnd = j;
541
+ }
542
+ }
543
+ }
544
+ } else {
545
+ rootEnd = 1;
546
+ }
547
+ } else if (isWindowsDeviceRoot(code)) {
548
+ if (path2.charCodeAt(1) === CHAR_COLON) {
549
+ device = path2.slice(0, 2);
550
+ rootEnd = 2;
551
+ if (len > 2) {
552
+ if (isPathSeparator(path2.charCodeAt(2))) {
553
+ isAbsolute4 = true;
554
+ rootEnd = 3;
555
+ }
556
+ }
557
+ }
558
+ }
559
+ } else if (isPathSeparator(code)) {
560
+ return "\\";
561
+ }
562
+ let tail;
563
+ if (rootEnd < len) {
564
+ tail = normalizeString(path2.slice(rootEnd), !isAbsolute4, "\\", isPathSeparator);
565
+ } else {
566
+ tail = "";
567
+ }
568
+ if (tail.length === 0 && !isAbsolute4)
569
+ tail = ".";
570
+ if (tail.length > 0 && isPathSeparator(path2.charCodeAt(len - 1))) {
571
+ tail += "\\";
572
+ }
573
+ if (device === void 0) {
574
+ if (isAbsolute4) {
575
+ if (tail.length > 0)
576
+ return `\\${tail}`;
577
+ else
578
+ return "\\";
579
+ }
580
+ return tail;
581
+ } else if (isAbsolute4) {
582
+ if (tail.length > 0)
583
+ return `${device}\\${tail}`;
584
+ else
585
+ return `${device}\\`;
586
+ }
587
+ return device + tail;
588
+ }
589
+
590
+ // npm/esm/deps/jsr.io/@std/path/1.1.6/windows/join.js
591
+ function join2(path2, ...paths) {
592
+ if (path2 instanceof URL) {
593
+ path2 = fromFileUrl2(path2);
594
+ }
595
+ paths = path2 ? [path2, ...paths] : paths;
596
+ paths.forEach((path3) => assertPath(path3));
597
+ paths = paths.filter((path3) => path3.length > 0);
598
+ if (paths.length === 0)
599
+ return ".";
600
+ let needsReplace = true;
601
+ let slashCount = 0;
602
+ const firstPart = paths[0];
603
+ if (isPathSeparator(firstPart.charCodeAt(0))) {
604
+ ++slashCount;
605
+ const firstLen = firstPart.length;
606
+ if (firstLen > 1) {
607
+ if (isPathSeparator(firstPart.charCodeAt(1))) {
608
+ ++slashCount;
609
+ if (firstLen > 2) {
610
+ if (isPathSeparator(firstPart.charCodeAt(2)))
611
+ ++slashCount;
612
+ else {
613
+ needsReplace = false;
614
+ }
615
+ }
616
+ }
617
+ }
618
+ }
619
+ let joined = paths.join("\\");
620
+ if (needsReplace) {
621
+ for (; slashCount < joined.length; ++slashCount) {
622
+ if (!isPathSeparator(joined.charCodeAt(slashCount)))
623
+ break;
624
+ }
625
+ if (slashCount >= 2)
626
+ joined = `\\${joined.slice(slashCount)}`;
627
+ }
628
+ return normalize2(joined);
629
+ }
630
+
631
+ // npm/esm/deps/jsr.io/@std/path/1.1.6/join.js
632
+ function join3(path2, ...paths) {
633
+ return isWindows ? join2(path2, ...paths) : join(path2, ...paths);
634
+ }
635
+
636
+ // npm/esm/deps/jsr.io/@std/path/1.1.6/normalize.js
637
+ function normalize3(path2) {
638
+ return isWindows ? normalize2(path2) : normalize(path2);
639
+ }
640
+
641
+ // npm/esm/deps/jsr.io/@std/path/1.1.6/_common/env.js
642
+ function cwd(errorMessage) {
643
+ const global = dntGlobalThis;
644
+ const getCwd = global.process?.cwd ?? global.Deno?.cwd;
645
+ if (typeof getCwd !== "function") {
646
+ throw new TypeError(errorMessage);
647
+ }
648
+ return getCwd();
649
+ }
650
+
651
+ // npm/esm/deps/jsr.io/@std/path/1.1.6/posix/resolve.js
652
+ function resolve(...pathSegments) {
653
+ let resolvedPath = "";
654
+ let resolvedAbsolute = false;
655
+ for (let i = pathSegments.length - 1; i >= -1 && !resolvedAbsolute; i--) {
656
+ let path2;
657
+ if (i >= 0)
658
+ path2 = pathSegments[i];
659
+ else {
660
+ path2 = cwd("Resolved a relative path without a current working directory (CWD)");
661
+ }
662
+ assertPath(path2);
663
+ if (path2.length === 0) {
664
+ continue;
665
+ }
666
+ resolvedPath = `${path2}/${resolvedPath}`;
667
+ resolvedAbsolute = isPosixPathSeparator(path2.charCodeAt(0));
668
+ }
669
+ resolvedPath = normalizeString(resolvedPath, !resolvedAbsolute, "/", isPosixPathSeparator);
670
+ if (resolvedAbsolute) {
671
+ if (resolvedPath.length > 0)
672
+ return `/${resolvedPath}`;
673
+ else
674
+ return "/";
675
+ } else if (resolvedPath.length > 0)
676
+ return resolvedPath;
677
+ else
678
+ return ".";
679
+ }
680
+
681
+ // npm/esm/deps/jsr.io/@std/path/1.1.6/_common/relative.js
682
+ function assertArgs2(from, to) {
683
+ assertPath(from);
684
+ assertPath(to);
685
+ if (from === to)
686
+ return "";
687
+ }
688
+
689
+ // npm/esm/deps/jsr.io/@std/path/1.1.6/posix/relative.js
690
+ function relative(from, to) {
691
+ assertArgs2(from, to);
692
+ from = resolve(from);
693
+ to = resolve(to);
694
+ if (from === to)
695
+ return "";
696
+ let fromStart = 1;
697
+ const fromEnd = from.length;
698
+ for (; fromStart < fromEnd; ++fromStart) {
699
+ if (!isPosixPathSeparator(from.charCodeAt(fromStart)))
700
+ break;
701
+ }
702
+ const fromLen = fromEnd - fromStart;
703
+ let toStart = 1;
704
+ const toEnd = to.length;
705
+ for (; toStart < toEnd; ++toStart) {
706
+ if (!isPosixPathSeparator(to.charCodeAt(toStart)))
707
+ break;
708
+ }
709
+ const toLen = toEnd - toStart;
710
+ const length = fromLen < toLen ? fromLen : toLen;
711
+ let lastCommonSep = -1;
712
+ let i = 0;
713
+ for (; i <= length; ++i) {
714
+ if (i === length) {
715
+ if (toLen > length) {
716
+ if (isPosixPathSeparator(to.charCodeAt(toStart + i))) {
717
+ return to.slice(toStart + i + 1);
718
+ } else if (i === 0) {
719
+ return to.slice(toStart + i);
720
+ }
721
+ } else if (fromLen > length) {
722
+ if (isPosixPathSeparator(from.charCodeAt(fromStart + i))) {
723
+ lastCommonSep = i;
724
+ } else if (i === 0) {
725
+ lastCommonSep = 0;
726
+ }
727
+ }
728
+ break;
729
+ }
730
+ const fromCode = from.charCodeAt(fromStart + i);
731
+ const toCode = to.charCodeAt(toStart + i);
732
+ if (fromCode !== toCode)
733
+ break;
734
+ else if (isPosixPathSeparator(fromCode))
735
+ lastCommonSep = i;
736
+ }
737
+ let out = "";
738
+ for (i = fromStart + lastCommonSep + 1; i <= fromEnd; ++i) {
739
+ if (i === fromEnd || isPosixPathSeparator(from.charCodeAt(i))) {
740
+ if (out.length === 0)
741
+ out += "..";
742
+ else
743
+ out += "/..";
744
+ }
745
+ }
746
+ if (out.length > 0)
747
+ return out + to.slice(toStart + lastCommonSep);
748
+ else {
749
+ toStart += lastCommonSep;
750
+ if (isPosixPathSeparator(to.charCodeAt(toStart)))
751
+ ++toStart;
752
+ return to.slice(toStart);
753
+ }
754
+ }
755
+
756
+ // npm/esm/deps/jsr.io/@std/path/1.1.6/windows/resolve.js
757
+ function resolve2(...pathSegments) {
758
+ let resolvedDevice = "";
759
+ let resolvedTail = "";
760
+ let resolvedAbsolute = false;
761
+ for (let i = pathSegments.length - 1; i >= -1; i--) {
762
+ let path2;
763
+ if (i >= 0) {
764
+ path2 = pathSegments[i];
765
+ } else if (!resolvedDevice) {
766
+ path2 = cwd("Resolved a drive-letter-less path without a current working directory (CWD)");
767
+ } else {
768
+ path2 = cwd("Resolved a relative path without a current working directory (CWD)");
769
+ if (path2 === void 0 || path2.slice(0, 3).toLowerCase() !== `${resolvedDevice.toLowerCase()}\\`) {
770
+ path2 = `${resolvedDevice}\\`;
771
+ }
772
+ }
773
+ assertPath(path2);
774
+ const len = path2.length;
775
+ if (len === 0)
776
+ continue;
777
+ let rootEnd = 0;
778
+ let device = "";
779
+ let isAbsolute4 = false;
780
+ const code = path2.charCodeAt(0);
781
+ if (len > 1) {
782
+ if (isPathSeparator(code)) {
783
+ isAbsolute4 = true;
784
+ if (isPathSeparator(path2.charCodeAt(1))) {
785
+ let j = 2;
786
+ let last = j;
787
+ for (; j < len; ++j) {
788
+ if (isPathSeparator(path2.charCodeAt(j)))
789
+ break;
790
+ }
791
+ if (j < len && j !== last) {
792
+ const firstPart = path2.slice(last, j);
793
+ last = j;
794
+ for (; j < len; ++j) {
795
+ if (!isPathSeparator(path2.charCodeAt(j)))
796
+ break;
797
+ }
798
+ if (j < len && j !== last) {
799
+ last = j;
800
+ for (; j < len; ++j) {
801
+ if (isPathSeparator(path2.charCodeAt(j)))
802
+ break;
803
+ }
804
+ if (j === len) {
805
+ device = `\\\\${firstPart}\\${path2.slice(last)}`;
806
+ rootEnd = j;
807
+ } else if (j !== last) {
808
+ device = `\\\\${firstPart}\\${path2.slice(last, j)}`;
809
+ rootEnd = j;
810
+ }
811
+ }
812
+ }
813
+ } else {
814
+ rootEnd = 1;
815
+ }
816
+ } else if (isWindowsDeviceRoot(code)) {
817
+ if (path2.charCodeAt(1) === CHAR_COLON) {
818
+ device = path2.slice(0, 2);
819
+ rootEnd = 2;
820
+ if (len > 2) {
821
+ if (isPathSeparator(path2.charCodeAt(2))) {
822
+ isAbsolute4 = true;
823
+ rootEnd = 3;
824
+ }
825
+ }
826
+ }
827
+ }
828
+ } else if (isPathSeparator(code)) {
829
+ rootEnd = 1;
830
+ isAbsolute4 = true;
831
+ }
832
+ if (device.length > 0 && resolvedDevice.length > 0 && device.toLowerCase() !== resolvedDevice.toLowerCase()) {
833
+ continue;
834
+ }
835
+ if (resolvedDevice.length === 0 && device.length > 0) {
836
+ resolvedDevice = device;
837
+ }
838
+ if (!resolvedAbsolute) {
839
+ resolvedTail = `${path2.slice(rootEnd)}\\${resolvedTail}`;
840
+ resolvedAbsolute = isAbsolute4;
841
+ }
842
+ if (resolvedAbsolute && resolvedDevice.length > 0)
843
+ break;
844
+ }
845
+ resolvedTail = normalizeString(resolvedTail, !resolvedAbsolute, "\\", isPathSeparator);
846
+ return resolvedDevice + (resolvedAbsolute ? "\\" : "") + resolvedTail || ".";
847
+ }
848
+
849
+ // npm/esm/deps/jsr.io/@std/path/1.1.6/windows/relative.js
850
+ function relative2(from, to) {
851
+ assertArgs2(from, to);
852
+ const fromOrig = resolve2(from);
853
+ const toOrig = resolve2(to);
854
+ if (fromOrig === toOrig)
855
+ return "";
856
+ from = fromOrig.toLowerCase();
857
+ to = toOrig.toLowerCase();
858
+ if (from === to)
859
+ return "";
860
+ let fromStart = 0;
861
+ let fromEnd = from.length;
862
+ for (; fromStart < fromEnd; ++fromStart) {
863
+ if (from.charCodeAt(fromStart) !== CHAR_BACKWARD_SLASH)
864
+ break;
865
+ }
866
+ for (; fromEnd - 1 > fromStart; --fromEnd) {
867
+ if (from.charCodeAt(fromEnd - 1) !== CHAR_BACKWARD_SLASH)
868
+ break;
869
+ }
870
+ const fromLen = fromEnd - fromStart;
871
+ let toStart = 0;
872
+ let toEnd = to.length;
873
+ for (; toStart < toEnd; ++toStart) {
874
+ if (to.charCodeAt(toStart) !== CHAR_BACKWARD_SLASH)
875
+ break;
876
+ }
877
+ for (; toEnd - 1 > toStart; --toEnd) {
878
+ if (to.charCodeAt(toEnd - 1) !== CHAR_BACKWARD_SLASH)
879
+ break;
880
+ }
881
+ const toLen = toEnd - toStart;
882
+ const length = fromLen < toLen ? fromLen : toLen;
883
+ let lastCommonSep = -1;
884
+ let i = 0;
885
+ for (; i <= length; ++i) {
886
+ if (i === length) {
887
+ if (toLen > length) {
888
+ if (to.charCodeAt(toStart + i) === CHAR_BACKWARD_SLASH) {
889
+ return toOrig.slice(toStart + i + 1);
890
+ } else if (i === 2) {
891
+ return toOrig.slice(toStart + i);
892
+ }
893
+ }
894
+ if (fromLen > length) {
895
+ if (from.charCodeAt(fromStart + i) === CHAR_BACKWARD_SLASH) {
896
+ lastCommonSep = i;
897
+ } else if (i === 2) {
898
+ lastCommonSep = 3;
899
+ }
900
+ }
901
+ break;
902
+ }
903
+ const fromCode = from.charCodeAt(fromStart + i);
904
+ const toCode = to.charCodeAt(toStart + i);
905
+ if (fromCode !== toCode)
906
+ break;
907
+ else if (fromCode === CHAR_BACKWARD_SLASH)
908
+ lastCommonSep = i;
909
+ }
910
+ if (i !== length && lastCommonSep === -1) {
911
+ return toOrig;
912
+ }
913
+ let out = "";
914
+ if (lastCommonSep === -1)
915
+ lastCommonSep = 0;
916
+ for (i = fromStart + lastCommonSep + 1; i <= fromEnd; ++i) {
917
+ if (i === fromEnd || from.charCodeAt(i) === CHAR_BACKWARD_SLASH) {
918
+ if (out.length === 0)
919
+ out += "..";
920
+ else
921
+ out += "\\..";
922
+ }
923
+ }
924
+ if (out.length > 0) {
925
+ return out + toOrig.slice(toStart + lastCommonSep, toEnd);
926
+ } else {
927
+ toStart += lastCommonSep;
928
+ if (toOrig.charCodeAt(toStart) === CHAR_BACKWARD_SLASH)
929
+ ++toStart;
930
+ return toOrig.slice(toStart, toEnd);
931
+ }
932
+ }
933
+
934
+ // npm/esm/deps/jsr.io/@std/path/1.1.6/relative.js
935
+ function relative3(from, to) {
936
+ return isWindows ? relative2(from, to) : relative(from, to);
937
+ }
938
+
939
+ // npm/esm/deps/jsr.io/@std/path/1.1.6/resolve.js
940
+ function resolve3(...pathSegments) {
941
+ return isWindows ? resolve2(...pathSegments) : resolve(...pathSegments);
942
+ }
943
+
944
+ // npm/esm/deps/jsr.io/@std/path/1.1.6/_common/to_file_url.js
945
+ var WHITESPACE_ENCODINGS = {
946
+ " ": "%09",
947
+ "\n": "%0A",
948
+ "\v": "%0B",
949
+ "\f": "%0C",
950
+ "\r": "%0D",
951
+ " ": "%20"
952
+ };
953
+ function encodeWhitespace(string) {
954
+ return string.replaceAll(/[\s]/g, (c) => {
955
+ return WHITESPACE_ENCODINGS[c] ?? c;
956
+ });
957
+ }
958
+
959
+ // npm/esm/deps/jsr.io/@std/path/1.1.6/posix/to_file_url.js
960
+ function toFileUrl(path2) {
961
+ if (!isAbsolute(path2)) {
962
+ throw new TypeError(`Path must be absolute: received "${path2}"`);
963
+ }
964
+ const url = new URL("file:///");
965
+ url.pathname = encodeWhitespace(path2.replace(/^\/+/, "/").replace(/%/g, "%25").replace(/\\/g, "%5C"));
966
+ return url;
967
+ }
968
+
969
+ // npm/esm/deps/jsr.io/@std/path/1.1.6/windows/to_file_url.js
970
+ function toFileUrl2(path2) {
971
+ if (!isAbsolute2(path2)) {
972
+ throw new TypeError(`Path must be absolute: received "${path2}"`);
973
+ }
974
+ const [, hostname, pathname] = path2.match(/^(?:[/\\]{2}([^/\\]+)(?=[/\\](?:[^/\\]|$)))?(.*)/);
975
+ const url = new URL("file:///");
976
+ url.pathname = encodeWhitespace(pathname.replace(/%/g, "%25"));
977
+ if (hostname !== void 0 && hostname !== "localhost") {
978
+ url.hostname = hostname;
979
+ if (!url.hostname) {
980
+ throw new TypeError(`Invalid hostname: "${url.hostname}"`);
981
+ }
982
+ }
983
+ return url;
984
+ }
985
+
986
+ // npm/esm/deps/jsr.io/@std/path/1.1.6/to_file_url.js
987
+ function toFileUrl3(path2) {
988
+ return isWindows ? toFileUrl2(path2) : toFileUrl(path2);
989
+ }
990
+
991
+ // npm/esm/_fs.js
992
+ var nodeProcess = globalThis.process;
993
+ var nodeFs;
994
+ function getNodeFs() {
995
+ return nodeFs ??= nodeProcess.getBuiltinModule("node:fs");
996
+ }
997
+ var nodeFsPromises;
998
+ function getNodeFsPromises() {
999
+ return nodeFsPromises ??= nodeProcess.getBuiltinModule("node:fs/promises");
1000
+ }
1001
+ function isNotFoundError(err) {
1002
+ return err?.code === "ENOENT";
1003
+ }
1004
+ function createNotFoundError(message) {
1005
+ const err = new Error(message);
1006
+ err.code = "ENOENT";
1007
+ return err;
1008
+ }
1009
+ function isWindows2() {
1010
+ return process.platform === "win32";
1011
+ }
1012
+ var FsFile = class {
1013
+ /** @internal */
1014
+ _fd;
1015
+ /** @internal */
1016
+ constructor(fd) {
1017
+ this._fd = fd;
1018
+ }
1019
+ /** Writes data to the file, resolving to the number of bytes written.
1020
+ *
1021
+ * Strings are encoded as UTF-8.
1022
+ */
1023
+ write(data) {
1024
+ const bytes = typeof data === "string" ? new TextEncoder().encode(data) : data;
1025
+ return new Promise((resolve4, reject) => {
1026
+ getNodeFs().write(this._fd, bytes, 0, bytes.length, null, (err, written) => {
1027
+ if (err)
1028
+ reject(err);
1029
+ else
1030
+ resolve4(written);
1031
+ });
1032
+ });
1033
+ }
1034
+ /** Synchronously writes data to the file, returning the number of bytes written.
1035
+ *
1036
+ * Strings are encoded as UTF-8.
1037
+ */
1038
+ writeSync(data) {
1039
+ const bytes = typeof data === "string" ? new TextEncoder().encode(data) : data;
1040
+ return getNodeFs().writeSync(this._fd, bytes, 0, bytes.length);
1041
+ }
1042
+ /** Reads into `buf`, resolving to the number of bytes read (0 at EOF). */
1043
+ read(buf) {
1044
+ return new Promise((resolve4, reject) => {
1045
+ getNodeFs().read(this._fd, buf, 0, buf.length, null, (err, bytesRead) => {
1046
+ if (err)
1047
+ reject(err);
1048
+ else
1049
+ resolve4(bytesRead);
1050
+ });
1051
+ });
1052
+ }
1053
+ /** Synchronously reads into `buf`, returning the number of bytes read (0 at EOF). */
1054
+ readSync(buf) {
1055
+ return getNodeFs().readSync(this._fd, buf, 0, buf.length, null);
1056
+ }
1057
+ /** Closes the file handle. */
1058
+ close() {
1059
+ getNodeFs().closeSync(this._fd);
1060
+ }
1061
+ /** A writable stream that writes to this file. */
1062
+ get writable() {
1063
+ const fd = this._fd;
1064
+ return new WritableStream({
1065
+ write(chunk) {
1066
+ return new Promise((resolve4, reject) => {
1067
+ getNodeFs().write(fd, chunk, 0, chunk.length, null, (err) => {
1068
+ if (err)
1069
+ reject(err);
1070
+ else
1071
+ resolve4();
1072
+ });
1073
+ });
1074
+ }
1075
+ });
1076
+ }
1077
+ /** A readable stream that reads from this file. */
1078
+ get readable() {
1079
+ const fd = this._fd;
1080
+ return new ReadableStream({
1081
+ pull(controller) {
1082
+ return new Promise((resolve4, reject) => {
1083
+ const buf = new Uint8Array(16384);
1084
+ getNodeFs().read(fd, buf, 0, buf.length, null, (err, bytesRead) => {
1085
+ if (err) {
1086
+ reject(err);
1087
+ return;
1088
+ }
1089
+ if (bytesRead === 0) {
1090
+ controller.close();
1091
+ } else {
1092
+ controller.enqueue(buf.subarray(0, bytesRead));
1093
+ }
1094
+ resolve4();
1095
+ });
1096
+ });
1097
+ }
1098
+ });
1099
+ }
1100
+ };
1101
+ function stat(path2) {
1102
+ return getNodeFsPromises().stat(path2);
1103
+ }
1104
+ function statSync(path2) {
1105
+ return getNodeFs().statSync(path2);
1106
+ }
1107
+ function lstat(path2) {
1108
+ return getNodeFsPromises().lstat(path2);
1109
+ }
1110
+ function lstatSync(path2) {
1111
+ return getNodeFs().lstatSync(path2);
1112
+ }
1113
+ function realPath(path2) {
1114
+ return getNodeFsPromises().realpath(path2);
1115
+ }
1116
+ function realPathSync(path2) {
1117
+ return getNodeFs().realpathSync(path2);
1118
+ }
1119
+ async function mkdirFn(path2, options) {
1120
+ await getNodeFsPromises().mkdir(path2, options);
1121
+ }
1122
+ function mkdirSyncFn(path2, options) {
1123
+ getNodeFs().mkdirSync(path2, options);
1124
+ }
1125
+ async function linkFn(oldPath, newPath) {
1126
+ await getNodeFsPromises().link(oldPath, newPath);
1127
+ }
1128
+ function linkSyncFn(oldPath, newPath) {
1129
+ getNodeFs().linkSync(oldPath, newPath);
1130
+ }
1131
+ async function symlinkFn(target, path2, type) {
1132
+ await getNodeFsPromises().symlink(target, path2, type?.type);
1133
+ }
1134
+ function symlinkSyncFn(target, path2, type) {
1135
+ getNodeFs().symlinkSync(target, path2, type?.type);
1136
+ }
1137
+ async function* readDir(path2) {
1138
+ const entries = await getNodeFsPromises().readdir(path2, {
1139
+ withFileTypes: true
1140
+ });
1141
+ yield* entries;
1142
+ }
1143
+ function* readDirSync(path2) {
1144
+ yield* getNodeFs().readdirSync(path2, { withFileTypes: true });
1145
+ }
1146
+ async function readFile(path2, options) {
1147
+ return new Uint8Array(await getNodeFsPromises().readFile(path2, { signal: options?.signal }));
1148
+ }
1149
+ function readFileSync(path2) {
1150
+ return new Uint8Array(getNodeFs().readFileSync(path2));
1151
+ }
1152
+ function readTextFile(path2, options) {
1153
+ return getNodeFsPromises().readFile(path2, {
1154
+ encoding: "utf8",
1155
+ signal: options?.signal
1156
+ });
1157
+ }
1158
+ function readTextFileSync(path2) {
1159
+ return getNodeFs().readFileSync(path2, "utf8");
1160
+ }
1161
+ async function chmod(path2, mode) {
1162
+ await getNodeFsPromises().chmod(path2, mode);
1163
+ }
1164
+ function chmodSync(path2, mode) {
1165
+ getNodeFs().chmodSync(path2, mode);
1166
+ }
1167
+ async function chown(path2, uid, gid) {
1168
+ await getNodeFsPromises().chown(path2, uid ?? -1, gid ?? -1);
1169
+ }
1170
+ function chownSync(path2, uid, gid) {
1171
+ getNodeFs().chownSync(path2, uid ?? -1, gid ?? -1);
1172
+ }
1173
+ function openFile(path2, options) {
1174
+ return new Promise((resolve4, reject) => {
1175
+ getNodeFs().open(path2, openOptionsToFlags(options), options?.mode, (err, fd) => {
1176
+ if (err)
1177
+ reject(err);
1178
+ else
1179
+ resolve4(new FsFile(fd));
1180
+ });
1181
+ });
1182
+ }
1183
+ function openFileSync(path2, options) {
1184
+ const fd = getNodeFs().openSync(path2, openOptionsToFlags(options), options?.mode);
1185
+ return new FsFile(fd);
1186
+ }
1187
+ function createFile(path2) {
1188
+ return openFile(path2, {
1189
+ write: true,
1190
+ create: true,
1191
+ truncate: true,
1192
+ read: true
1193
+ });
1194
+ }
1195
+ function createFileSync(path2) {
1196
+ return openFileSync(path2, {
1197
+ write: true,
1198
+ create: true,
1199
+ truncate: true,
1200
+ read: true
1201
+ });
1202
+ }
1203
+ async function remove(path2, options) {
1204
+ if (options?.recursive) {
1205
+ await getNodeFsPromises().rm(path2, { recursive: true });
1206
+ return;
1207
+ }
1208
+ const info = await getNodeFsPromises().lstat(path2);
1209
+ if (info.isDirectory()) {
1210
+ await getNodeFsPromises().rmdir(path2);
1211
+ } else {
1212
+ await getNodeFsPromises().unlink(path2);
1213
+ }
1214
+ }
1215
+ function removeSync(path2, options) {
1216
+ if (options?.recursive) {
1217
+ getNodeFs().rmSync(path2, { recursive: true });
1218
+ return;
1219
+ }
1220
+ const info = getNodeFs().lstatSync(path2);
1221
+ if (info.isDirectory()) {
1222
+ getNodeFs().rmdirSync(path2);
1223
+ } else {
1224
+ getNodeFs().unlinkSync(path2);
1225
+ }
1226
+ }
1227
+ async function copyFileFn(src, dest) {
1228
+ await getNodeFsPromises().copyFile(src, dest);
1229
+ }
1230
+ function copyFileSyncFn(src, dest) {
1231
+ getNodeFs().copyFileSync(src, dest);
1232
+ }
1233
+ async function renameFn(oldPath, newPath) {
1234
+ await getNodeFsPromises().rename(oldPath, newPath);
1235
+ }
1236
+ function renameSyncFn(oldPath, newPath) {
1237
+ getNodeFs().renameSync(oldPath, newPath);
1238
+ }
1239
+ async function ensureDir(path2) {
1240
+ await mkdirFn(path2, { recursive: true });
1241
+ }
1242
+ function ensureDirSync(path2) {
1243
+ mkdirSyncFn(path2, { recursive: true });
1244
+ }
1245
+ async function ensureFile(path2) {
1246
+ const info = await lstatOrUndefined(path2);
1247
+ if (info != null) {
1248
+ if (info.isFile())
1249
+ return;
1250
+ throw new Error(`Path '${path2}' already exists and is not a file.`);
1251
+ }
1252
+ await mkdirFn(dirname3(path2), { recursive: true });
1253
+ (await createFile(path2)).close();
1254
+ }
1255
+ function ensureFileSync(path2) {
1256
+ const info = lstatOrUndefinedSync(path2);
1257
+ if (info != null) {
1258
+ if (info.isFile())
1259
+ return;
1260
+ throw new Error(`Path '${path2}' already exists and is not a file.`);
1261
+ }
1262
+ mkdirSyncFn(dirname3(path2), { recursive: true });
1263
+ createFileSync(path2).close();
1264
+ }
1265
+ async function emptyDir(path2) {
1266
+ try {
1267
+ const entries = [];
1268
+ for await (const entry of readDir(path2)) {
1269
+ entries.push(entry);
1270
+ }
1271
+ for (const entry of entries) {
1272
+ await remove(join3(path2, entry.name), { recursive: true });
1273
+ }
1274
+ } catch (err) {
1275
+ if (!isNotFoundError(err))
1276
+ throw err;
1277
+ await mkdirFn(path2, { recursive: true });
1278
+ }
1279
+ }
1280
+ function emptyDirSync(path2) {
1281
+ try {
1282
+ const entries = [...readDirSync(path2)];
1283
+ for (const entry of entries) {
1284
+ removeSync(join3(path2, entry.name), { recursive: true });
1285
+ }
1286
+ } catch (err) {
1287
+ if (!isNotFoundError(err))
1288
+ throw err;
1289
+ mkdirSyncFn(path2, { recursive: true });
1290
+ }
1291
+ }
1292
+ async function copy(src, dest, options) {
1293
+ const overwrite = options?.overwrite ?? false;
1294
+ const srcInfo = await stat(src);
1295
+ await copyRecursive(src, dest, srcInfo, overwrite);
1296
+ }
1297
+ function copySync(src, dest, options) {
1298
+ const overwrite = options?.overwrite ?? false;
1299
+ const srcInfo = statSync(src);
1300
+ copyRecursiveSync(src, dest, srcInfo, overwrite);
1301
+ }
1302
+ async function copyRecursive(src, dest, srcInfo, overwrite) {
1303
+ let destInfo = await lstatOrUndefined(dest);
1304
+ if (destInfo != null && !overwrite) {
1305
+ throw new Error(`'${dest}' already exists.`);
1306
+ }
1307
+ if (srcInfo.isDirectory()) {
1308
+ if (destInfo != null && !destInfo.isDirectory()) {
1309
+ await remove(dest);
1310
+ destInfo = void 0;
1311
+ }
1312
+ if (destInfo == null) {
1313
+ await mkdirFn(dest, { recursive: true });
1314
+ }
1315
+ for await (const entry of readDir(src)) {
1316
+ const srcChild = join3(src, entry.name);
1317
+ const destChild = join3(dest, entry.name);
1318
+ const childInfo = await stat(srcChild);
1319
+ await copyRecursive(srcChild, destChild, childInfo, overwrite);
1320
+ }
1321
+ } else {
1322
+ if (destInfo != null && destInfo.isDirectory()) {
1323
+ throw new Error(`Cannot overwrite directory '${dest}' with file '${src}'.`);
1324
+ }
1325
+ await copyFileFn(src, dest);
1326
+ }
1327
+ }
1328
+ function copyRecursiveSync(src, dest, srcInfo, overwrite) {
1329
+ let destInfo = lstatOrUndefinedSync(dest);
1330
+ if (destInfo != null && !overwrite) {
1331
+ throw new Error(`'${dest}' already exists.`);
1332
+ }
1333
+ if (srcInfo.isDirectory()) {
1334
+ if (destInfo != null && !destInfo.isDirectory()) {
1335
+ removeSync(dest);
1336
+ destInfo = void 0;
1337
+ }
1338
+ if (destInfo == null) {
1339
+ mkdirSyncFn(dest, { recursive: true });
1340
+ }
1341
+ for (const entry of readDirSync(src)) {
1342
+ const srcChild = join3(src, entry.name);
1343
+ const destChild = join3(dest, entry.name);
1344
+ const childInfo = statSync(srcChild);
1345
+ copyRecursiveSync(srcChild, destChild, childInfo, overwrite);
1346
+ }
1347
+ } else {
1348
+ if (destInfo != null && destInfo.isDirectory()) {
1349
+ throw new Error(`Cannot overwrite directory '${dest}' with file '${src}'.`);
1350
+ }
1351
+ copyFileSyncFn(src, dest);
1352
+ }
1353
+ }
1354
+ async function lstatOrUndefined(path2) {
1355
+ try {
1356
+ return await lstat(path2);
1357
+ } catch (err) {
1358
+ if (isNotFoundError(err))
1359
+ return void 0;
1360
+ throw err;
1361
+ }
1362
+ }
1363
+ function lstatOrUndefinedSync(path2) {
1364
+ try {
1365
+ return lstatSync(path2);
1366
+ } catch (err) {
1367
+ if (isNotFoundError(err))
1368
+ return void 0;
1369
+ throw err;
1370
+ }
1371
+ }
1372
+ function openOptionsToFlags(options) {
1373
+ const C = getNodeFs().constants;
1374
+ if (!options)
1375
+ return C.O_RDONLY;
1376
+ const { read, write, append, truncate, create, createNew } = options;
1377
+ const needsWrite = write || append || create || createNew;
1378
+ let flags;
1379
+ if (read && needsWrite)
1380
+ flags = C.O_RDWR;
1381
+ else if (needsWrite)
1382
+ flags = C.O_WRONLY;
1383
+ else
1384
+ flags = C.O_RDONLY;
1385
+ if (append)
1386
+ flags |= C.O_APPEND;
1387
+ if (truncate)
1388
+ flags |= C.O_TRUNC;
1389
+ if (createNew)
1390
+ flags |= C.O_CREAT | C.O_EXCL;
1391
+ else if (create)
1392
+ flags |= C.O_CREAT;
1393
+ return flags;
1394
+ }
1395
+
1396
+ // npm/esm/mod.js
1397
+ function path(path2) {
1398
+ return new Path(path2);
1399
+ }
1400
+ var mod_default = path;
1401
+ var Path = class _Path {
1402
+ #path;
1403
+ #knownResolved = false;
1404
+ /** This is a special symbol that allows different versions of
1405
+ * `Path` API to match on `instanceof` checks. Ideally
1406
+ * people shouldn't be mixing versions, but if it happens then
1407
+ * this will maybe reduce some bugs.
1408
+ * @internal
1409
+ */
1410
+ static instanceofSymbol = /* @__PURE__ */ Symbol.for("@david/path.Path");
1411
+ /** Creates a new path from the provided string, URL, or another Path. */
1412
+ constructor(path2) {
1413
+ if (path2 instanceof URL) {
1414
+ this.#path = fromFileUrl3(path2);
1415
+ } else if (path2 instanceof _Path) {
1416
+ this.#path = path2.toString();
1417
+ } else if (typeof path2 === "string") {
1418
+ if (path2.startsWith("file://")) {
1419
+ this.#path = fromFileUrl3(path2);
1420
+ } else {
1421
+ this.#path = path2;
1422
+ }
1423
+ } else {
1424
+ throw new Error(`Invalid path argument: ${path2}
1425
+
1426
+ Provide a URL, string, or another Path.`);
1427
+ }
1428
+ }
1429
+ /** @internal */
1430
+ static [Symbol.hasInstance](instance) {
1431
+ return instance?.constructor?.instanceofSymbol === _Path.instanceofSymbol;
1432
+ }
1433
+ /** @internal */
1434
+ [/* @__PURE__ */ Symbol.for("Deno.customInspect")]() {
1435
+ return `Path("${this.#path}")`;
1436
+ }
1437
+ /** @internal */
1438
+ [/* @__PURE__ */ Symbol.for("nodejs.util.inspect.custom")]() {
1439
+ return `Path("${this.#path}")`;
1440
+ }
1441
+ /** Gets the string representation of this path. */
1442
+ toString() {
1443
+ return this.#path;
1444
+ }
1445
+ /** Resolves the path and gets the file URL. */
1446
+ toFileUrl() {
1447
+ const resolvedPath = this.resolve();
1448
+ return toFileUrl3(resolvedPath.toString());
1449
+ }
1450
+ /** If this path reference is the same as another one. */
1451
+ equals(otherPath) {
1452
+ return this.resolve().toString() === otherPath.resolve().toString();
1453
+ }
1454
+ /** Follows symlinks and gets if this path is a directory. */
1455
+ isDirSync() {
1456
+ return this.statSync()?.isDirectory() ?? false;
1457
+ }
1458
+ /** Follows symlinks and gets if this path is a file. */
1459
+ isFileSync() {
1460
+ return this.statSync()?.isFile() ?? false;
1461
+ }
1462
+ /** Gets if this path is a symlink. */
1463
+ isSymlinkSync() {
1464
+ return this.lstatSync()?.isSymbolicLink() ?? false;
1465
+ }
1466
+ /** Gets if this path is an absolute path. */
1467
+ isAbsolute() {
1468
+ return isAbsolute3(this.#path);
1469
+ }
1470
+ /** Gets if this path is relative. */
1471
+ isRelative() {
1472
+ return !this.isAbsolute();
1473
+ }
1474
+ /** Joins the provided path segments onto this path. */
1475
+ join(...pathSegments) {
1476
+ return new _Path(join3(this.#path, ...pathSegments));
1477
+ }
1478
+ /** Resolves this path to an absolute path along with the provided path segments. */
1479
+ resolve(...pathSegments) {
1480
+ if (this.#knownResolved && pathSegments.length === 0) {
1481
+ return this;
1482
+ }
1483
+ const resolvedPath = resolve3(this.#path, ...pathSegments);
1484
+ if (pathSegments.length === 0 && resolvedPath === this.#path) {
1485
+ this.#knownResolved = true;
1486
+ return this;
1487
+ } else {
1488
+ const pathRef = new _Path(resolvedPath);
1489
+ pathRef.#knownResolved = true;
1490
+ return pathRef;
1491
+ }
1492
+ }
1493
+ /**
1494
+ * Normalizes the `path`, resolving `'..'` and `'.'` segments.
1495
+ * Note that resolving these segments does not necessarily mean that all will be eliminated.
1496
+ * A `'..'` at the top-level will be preserved, and an empty path is canonically `'.'`.
1497
+ */
1498
+ normalize() {
1499
+ return new _Path(normalize3(this.#path));
1500
+ }
1501
+ /** Resolves the file info of this path following symlinks. */
1502
+ async stat() {
1503
+ try {
1504
+ return await stat(this.#path);
1505
+ } catch (err) {
1506
+ if (isNotFoundError(err)) {
1507
+ return void 0;
1508
+ } else {
1509
+ throw err;
1510
+ }
1511
+ }
1512
+ }
1513
+ /** Synchronously resolves the file info of this path following symlinks. */
1514
+ statSync() {
1515
+ try {
1516
+ return statSync(this.#path);
1517
+ } catch (err) {
1518
+ if (isNotFoundError(err)) {
1519
+ return void 0;
1520
+ } else {
1521
+ throw err;
1522
+ }
1523
+ }
1524
+ }
1525
+ /** Resolves the file info of this path without following symlinks. */
1526
+ async lstat() {
1527
+ try {
1528
+ return await lstat(this.#path);
1529
+ } catch (err) {
1530
+ if (isNotFoundError(err)) {
1531
+ return void 0;
1532
+ } else {
1533
+ throw err;
1534
+ }
1535
+ }
1536
+ }
1537
+ /** Synchronously resolves the file info of this path without following symlinks. */
1538
+ lstatSync() {
1539
+ try {
1540
+ return lstatSync(this.#path);
1541
+ } catch (err) {
1542
+ if (isNotFoundError(err)) {
1543
+ return void 0;
1544
+ } else {
1545
+ throw err;
1546
+ }
1547
+ }
1548
+ }
1549
+ /**
1550
+ * Gets the directory path. In most cases, it is recommended
1551
+ * to use `.parent()` instead since it will give you a `PathRef`.
1552
+ */
1553
+ dirname() {
1554
+ return dirname3(this.#path);
1555
+ }
1556
+ /** Gets the file or directory name of the path. */
1557
+ basename() {
1558
+ return basename3(this.#path);
1559
+ }
1560
+ /** Resolves the path getting all its ancestor directories in order. */
1561
+ *ancestors() {
1562
+ let ancestor = this.parent();
1563
+ while (ancestor != null) {
1564
+ yield ancestor;
1565
+ ancestor = ancestor.parent();
1566
+ }
1567
+ }
1568
+ /** Iterates over the components of a path. */
1569
+ *components() {
1570
+ const path2 = this.normalize();
1571
+ let last_index = 0;
1572
+ if (path2.#path.startsWith("\\\\?\\")) {
1573
+ last_index = nextSlash(path2.#path, 4);
1574
+ if (last_index === -1) {
1575
+ yield path2.#path;
1576
+ return;
1577
+ } else {
1578
+ yield path2.#path.substring(0, last_index);
1579
+ last_index += 1;
1580
+ }
1581
+ } else if (path2.#path.startsWith("/")) {
1582
+ last_index += 1;
1583
+ }
1584
+ while (true) {
1585
+ const index = nextSlash(path2.#path, last_index);
1586
+ if (index < 0) {
1587
+ const part = path2.#path.substring(last_index);
1588
+ if (part.length > 0) {
1589
+ yield part;
1590
+ }
1591
+ return;
1592
+ }
1593
+ yield path2.#path.substring(last_index, index);
1594
+ last_index = index + 1;
1595
+ }
1596
+ function nextSlash(path3, start) {
1597
+ for (let i = start; i < path3.length; i++) {
1598
+ const c = path3.charCodeAt(i);
1599
+ if (c === 47 || c === 92) {
1600
+ return i;
1601
+ }
1602
+ }
1603
+ return -1;
1604
+ }
1605
+ }
1606
+ // This is private because this doesn't handle stuff like `\\?\` at the start
1607
+ // so it's only used internally with #endsWith for perf. API consumers should
1608
+ // use .components()
1609
+ *#rcomponents() {
1610
+ const path2 = this.normalize();
1611
+ let last_index = void 0;
1612
+ while (last_index == null || last_index > 0) {
1613
+ const index = nextSlash(path2.#path, last_index == null ? void 0 : last_index - 1);
1614
+ if (index < 0) {
1615
+ const part2 = path2.#path.substring(0, last_index);
1616
+ if (part2.length > 0) {
1617
+ yield part2;
1618
+ }
1619
+ return;
1620
+ }
1621
+ const part = path2.#path.substring(index + 1, last_index);
1622
+ if (last_index != null || part.length > 0) {
1623
+ yield part;
1624
+ }
1625
+ last_index = index;
1626
+ }
1627
+ function nextSlash(path3, start) {
1628
+ for (let i = start ?? path3.length - 1; i >= 0; i--) {
1629
+ const c = path3.charCodeAt(i);
1630
+ if (c === 47 || c === 92) {
1631
+ return i;
1632
+ }
1633
+ }
1634
+ return -1;
1635
+ }
1636
+ }
1637
+ /** Gets if the provided path starts with the specified Path, URL, or string.
1638
+ *
1639
+ * This verifies based on matching the components.
1640
+ *
1641
+ * ```
1642
+ * assert(new Path("/a/b/c").startsWith("/a/b"));
1643
+ * assert(!new Path("/example").endsWith("/exam"));
1644
+ * ```
1645
+ */
1646
+ startsWith(path2) {
1647
+ const startsWithComponents = ensurePath(path2).components();
1648
+ for (const component of this.components()) {
1649
+ const next = startsWithComponents.next();
1650
+ if (next.done) {
1651
+ return true;
1652
+ }
1653
+ if (next.value !== component) {
1654
+ return false;
1655
+ }
1656
+ }
1657
+ return startsWithComponents.next().done ?? true;
1658
+ }
1659
+ /** Gets if the provided path ends with the specified Path, URL, or string.
1660
+ *
1661
+ * This verifies based on matching the components.
1662
+ *
1663
+ * ```
1664
+ * assert(new Path("/a/b/c").endsWith("b/c"));
1665
+ * assert(!new Path("/a/b/example").endsWith("ple"));
1666
+ * ```
1667
+ */
1668
+ endsWith(path2) {
1669
+ const endsWithComponents = ensurePath(path2).#rcomponents();
1670
+ for (const component of this.#rcomponents()) {
1671
+ const next = endsWithComponents.next();
1672
+ if (next.done) {
1673
+ return true;
1674
+ }
1675
+ if (next.value !== component) {
1676
+ return false;
1677
+ }
1678
+ }
1679
+ return endsWithComponents.next().done ?? true;
1680
+ }
1681
+ /** Gets the parent directory or returns undefined if the parent is the root directory. */
1682
+ parent() {
1683
+ const resolvedPath = this.resolve();
1684
+ const dirname4 = resolvedPath.dirname();
1685
+ if (dirname4 === resolvedPath.#path) {
1686
+ return void 0;
1687
+ } else {
1688
+ return new _Path(dirname4);
1689
+ }
1690
+ }
1691
+ /** Gets the parent or throws if the current directory was the root. */
1692
+ parentOrThrow() {
1693
+ const parent = this.parent();
1694
+ if (parent == null) {
1695
+ throw new Error(`Cannot get the parent directory of '${this.#path}'.`);
1696
+ }
1697
+ return parent;
1698
+ }
1699
+ /**
1700
+ * Returns the extension of the path with leading period or undefined
1701
+ * if there is no extension.
1702
+ */
1703
+ extname() {
1704
+ const extName = extname3(this.#path);
1705
+ return extName.length === 0 ? void 0 : extName;
1706
+ }
1707
+ /** Gets a new path reference with the provided extension. */
1708
+ withExtname(ext) {
1709
+ const currentExt = this.extname();
1710
+ const hasLeadingPeriod = ext.charCodeAt(0) === /* period */
1711
+ 46;
1712
+ if (!hasLeadingPeriod && ext.length !== 0) {
1713
+ ext = "." + ext;
1714
+ }
1715
+ return new _Path(this.#path.substring(0, this.#path.length - (currentExt?.length ?? 0)) + ext);
1716
+ }
1717
+ /** Gets a new path reference with the provided file or directory name. */
1718
+ withBasename(basename4) {
1719
+ const currentBaseName = this.basename();
1720
+ return new _Path(this.#path.substring(0, this.#path.length - currentBaseName.length) + basename4);
1721
+ }
1722
+ /** Gets the relative path from this path to the specified path. */
1723
+ relative(to) {
1724
+ const toPathRef = ensurePath(to);
1725
+ return relative3(this.resolve().#path, toPathRef.resolve().toString());
1726
+ }
1727
+ /** Gets if the path exists. Beware of TOCTOU issues. */
1728
+ exists() {
1729
+ return this.lstat().then((info) => info != null);
1730
+ }
1731
+ /** Synchronously gets if the path exists. Beware of TOCTOU issues. */
1732
+ existsSync() {
1733
+ return this.lstatSync() != null;
1734
+ }
1735
+ /** Resolves to the absolute normalized path, with symbolic links resolved. */
1736
+ realPath() {
1737
+ return realPath(this.#path).then((path2) => new _Path(path2));
1738
+ }
1739
+ /** Synchronously resolves to the absolute normalized path, with symbolic links resolved. */
1740
+ realPathSync() {
1741
+ return new _Path(realPathSync(this.#path));
1742
+ }
1743
+ /** Creates a directory at this path.
1744
+ * @remarks By default, this is recursive.
1745
+ */
1746
+ async mkdir(options) {
1747
+ await mkdirFn(this.#path, {
1748
+ recursive: true,
1749
+ ...options
1750
+ });
1751
+ return this;
1752
+ }
1753
+ /** Synchronously creates a directory at this path.
1754
+ * @remarks By default, this is recursive.
1755
+ */
1756
+ mkdirSync(options) {
1757
+ mkdirSyncFn(this.#path, {
1758
+ recursive: true,
1759
+ ...options
1760
+ });
1761
+ return this;
1762
+ }
1763
+ async symlinkTo(target, opts) {
1764
+ await createSymlink(this.#resolveCreateSymlinkOpts(target, opts));
1765
+ }
1766
+ symlinkToSync(target, opts) {
1767
+ createSymlinkSync(this.#resolveCreateSymlinkOpts(target, opts));
1768
+ }
1769
+ #resolveCreateSymlinkOpts(target, opts) {
1770
+ if (opts?.kind == null) {
1771
+ if (typeof target === "string") {
1772
+ return {
1773
+ fromPath: this.resolve(),
1774
+ targetPath: ensurePath(target),
1775
+ text: target,
1776
+ type: opts?.type
1777
+ };
1778
+ } else {
1779
+ throw new Error("Please specify if this symlink is absolute or relative. Otherwise provide the target text.");
1780
+ }
1781
+ }
1782
+ const targetPath = ensurePath(target).resolve();
1783
+ if (opts?.kind === "relative") {
1784
+ const fromPath = this.resolve();
1785
+ const relativePath = fromPath.parentOrThrow().relative(targetPath);
1786
+ return {
1787
+ fromPath,
1788
+ targetPath,
1789
+ text: relativePath,
1790
+ type: opts?.type
1791
+ };
1792
+ } else {
1793
+ return {
1794
+ fromPath: this.resolve(),
1795
+ targetPath,
1796
+ text: targetPath.toString(),
1797
+ type: opts?.type
1798
+ };
1799
+ }
1800
+ }
1801
+ /**
1802
+ * Creates a hardlink to the provided target path.
1803
+ */
1804
+ async linkTo(targetPath) {
1805
+ const targetPathRef = ensurePath(targetPath).resolve();
1806
+ await linkFn(targetPathRef.toString(), this.resolve().toString());
1807
+ }
1808
+ /**
1809
+ * Synchronously creates a hardlink to the provided target path.
1810
+ */
1811
+ linkToSync(targetPath) {
1812
+ const targetPathRef = ensurePath(targetPath).resolve();
1813
+ linkSyncFn(targetPathRef.toString(), this.resolve().toString());
1814
+ }
1815
+ /** Reads the entries in the directory. */
1816
+ async *readDir() {
1817
+ const dir = this.resolve();
1818
+ for await (const entry of readDir(dir.#path)) {
1819
+ const out = entry;
1820
+ out.path = dir.join(entry.name);
1821
+ yield out;
1822
+ }
1823
+ }
1824
+ /** Synchronously reads the entries in the directory. */
1825
+ *readDirSync() {
1826
+ const dir = this.resolve();
1827
+ for (const entry of readDirSync(dir.#path)) {
1828
+ const out = entry;
1829
+ out.path = dir.join(entry.name);
1830
+ yield out;
1831
+ }
1832
+ }
1833
+ /** Reads only the directory file paths, not including symlinks. */
1834
+ async *readDirFilePaths() {
1835
+ const dir = this.resolve();
1836
+ for await (const entry of readDir(dir.#path)) {
1837
+ if (entry.isFile()) {
1838
+ yield dir.join(entry.name);
1839
+ }
1840
+ }
1841
+ }
1842
+ /** Synchronously reads only the directory file paths, not including symlinks. */
1843
+ *readDirFilePathsSync() {
1844
+ const dir = this.resolve();
1845
+ for (const entry of readDirSync(dir.#path)) {
1846
+ if (entry.isFile()) {
1847
+ yield dir.join(entry.name);
1848
+ }
1849
+ }
1850
+ }
1851
+ /** Reads the bytes from the file. */
1852
+ readBytes(options) {
1853
+ return readFile(this.#path, options);
1854
+ }
1855
+ /** Synchronously reads the bytes from the file. */
1856
+ readBytesSync() {
1857
+ return readFileSync(this.#path);
1858
+ }
1859
+ /** Calls `.readBytes()`, but returns undefined if the path doesn't exist. */
1860
+ readMaybeBytes(options) {
1861
+ return notFoundToUndefined(() => this.readBytes(options));
1862
+ }
1863
+ /** Calls `.readBytesSync()`, but returns undefined if the path doesn't exist. */
1864
+ readMaybeBytesSync() {
1865
+ return notFoundToUndefinedSync(() => this.readBytesSync());
1866
+ }
1867
+ /** Reads the text from the file. */
1868
+ readText(options) {
1869
+ return readTextFile(this.#path, options);
1870
+ }
1871
+ /** Synchronously reads the text from the file. */
1872
+ readTextSync() {
1873
+ return readTextFileSync(this.#path);
1874
+ }
1875
+ /** Calls `.readText()`, but returns undefined when the path doesn't exist.
1876
+ * @remarks This still errors for other kinds of errors reading a file.
1877
+ */
1878
+ readMaybeText(options) {
1879
+ return notFoundToUndefined(() => this.readText(options));
1880
+ }
1881
+ /** Calls `.readTextSync()`, but returns undefined when the path doesn't exist.
1882
+ * @remarks This still errors for other kinds of errors reading a file.
1883
+ */
1884
+ readMaybeTextSync() {
1885
+ return notFoundToUndefinedSync(() => this.readTextSync());
1886
+ }
1887
+ /** Reads the file's text and returns an array of its lines.
1888
+ *
1889
+ * Lines are split at `\n` or `\r\n`. Line terminators are not included.
1890
+ * A trailing blank line caused by a final line ending is excluded (matches
1891
+ * [Rust's `str::lines`](https://doc.rust-lang.org/std/primitive.str.html#method.lines)).
1892
+ */
1893
+ async lines(options) {
1894
+ return [...splitLines(await this.readText(options))];
1895
+ }
1896
+ /** Synchronously reads the file's text and returns an array of its lines.
1897
+ *
1898
+ * See `.lines()` for the splitting semantics.
1899
+ */
1900
+ linesSync() {
1901
+ return [...splitLines(this.readTextSync())];
1902
+ }
1903
+ /** Streams the file and iterates over its lines without loading it all into memory.
1904
+ *
1905
+ * See `.lines()` for the splitting semantics.
1906
+ */
1907
+ async *linesIter(options) {
1908
+ const file = await openFile(this.#path, { read: true });
1909
+ try {
1910
+ const decoder = new TextDecoder();
1911
+ const chunk = new Uint8Array(16384);
1912
+ let buffer = "";
1913
+ while (true) {
1914
+ options?.signal?.throwIfAborted();
1915
+ const n = await file.read(chunk);
1916
+ if (n === 0)
1917
+ break;
1918
+ buffer += decoder.decode(chunk.subarray(0, n), { stream: true });
1919
+ let start = 0;
1920
+ while (true) {
1921
+ const nl = buffer.indexOf("\n", start);
1922
+ if (nl === -1)
1923
+ break;
1924
+ const end = nl > start && buffer.charCodeAt(nl - 1) === 13 ? nl - 1 : nl;
1925
+ yield buffer.substring(start, end);
1926
+ start = nl + 1;
1927
+ }
1928
+ if (start > 0)
1929
+ buffer = buffer.substring(start);
1930
+ }
1931
+ buffer += decoder.decode();
1932
+ if (buffer !== "")
1933
+ yield buffer;
1934
+ } finally {
1935
+ try {
1936
+ file.close();
1937
+ } catch {
1938
+ }
1939
+ }
1940
+ }
1941
+ /** Synchronously streams the file and iterates over its lines without
1942
+ * loading it all into memory.
1943
+ *
1944
+ * See `.lines()` for the splitting semantics.
1945
+ */
1946
+ *linesIterSync() {
1947
+ const file = openFileSync(this.#path, { read: true });
1948
+ try {
1949
+ const decoder = new TextDecoder();
1950
+ const chunk = new Uint8Array(16384);
1951
+ let buffer = "";
1952
+ while (true) {
1953
+ const n = file.readSync(chunk);
1954
+ if (n === 0)
1955
+ break;
1956
+ buffer += decoder.decode(chunk.subarray(0, n), { stream: true });
1957
+ let start = 0;
1958
+ while (true) {
1959
+ const nl = buffer.indexOf("\n", start);
1960
+ if (nl === -1)
1961
+ break;
1962
+ const end = nl > start && buffer.charCodeAt(nl - 1) === 13 ? nl - 1 : nl;
1963
+ yield buffer.substring(start, end);
1964
+ start = nl + 1;
1965
+ }
1966
+ if (start > 0)
1967
+ buffer = buffer.substring(start);
1968
+ }
1969
+ buffer += decoder.decode();
1970
+ if (buffer !== "")
1971
+ yield buffer;
1972
+ } finally {
1973
+ try {
1974
+ file.close();
1975
+ } catch {
1976
+ }
1977
+ }
1978
+ }
1979
+ /** Reads and parses the file as JSON, throwing if it doesn't exist or is not valid JSON. */
1980
+ async readJson(options) {
1981
+ return this.#parseJson(await this.readText(options));
1982
+ }
1983
+ /** Synchronously reads and parses the file as JSON, throwing if it doesn't
1984
+ * exist or is not valid JSON. */
1985
+ readJsonSync() {
1986
+ return this.#parseJson(this.readTextSync());
1987
+ }
1988
+ #parseJson(text) {
1989
+ try {
1990
+ return JSON.parse(text);
1991
+ } catch (err) {
1992
+ throw new Error(`Failed parsing JSON in '${this.toString()}'.`, {
1993
+ cause: err
1994
+ });
1995
+ }
1996
+ }
1997
+ /**
1998
+ * Calls `.readJson()`, but returns undefined if the file doesn't exist.
1999
+ * @remarks This method will still throw if the file cannot be parsed as JSON.
2000
+ */
2001
+ readMaybeJson(options) {
2002
+ return notFoundToUndefined(() => this.readJson(options));
2003
+ }
2004
+ /**
2005
+ * Calls `.readJsonSync()`, but returns undefined if the file doesn't exist.
2006
+ * @remarks This method will still throw if the file cannot be parsed as JSON.
2007
+ */
2008
+ readMaybeJsonSync() {
2009
+ return notFoundToUndefinedSync(() => this.readJsonSync());
2010
+ }
2011
+ /** Writes out the provided bytes or text to the file.
2012
+ *
2013
+ * Strings are encoded as UTF-8.
2014
+ */
2015
+ async write(data, options) {
2016
+ const bytes = typeof data === "string" ? new TextEncoder().encode(data) : data;
2017
+ await this.#withFileForWriting(options, (file) => {
2018
+ return writeAll(file, bytes, options?.signal);
2019
+ });
2020
+ return this;
2021
+ }
2022
+ /** Synchronously writes out the provided bytes or text to the file.
2023
+ *
2024
+ * Strings are encoded as UTF-8.
2025
+ */
2026
+ writeSync(data, options) {
2027
+ const bytes = typeof data === "string" ? new TextEncoder().encode(data) : data;
2028
+ this.#withFileForWritingSync(options, (file) => {
2029
+ writeAllSync(file, bytes, options?.signal);
2030
+ });
2031
+ return this;
2032
+ }
2033
+ /** Writes the provided text to the file.
2034
+ * @deprecated Use `.write(text)` instead — `write` now accepts strings.
2035
+ */
2036
+ writeText(text, options) {
2037
+ return this.write(text, options);
2038
+ }
2039
+ /** Synchronously writes the provided text to the file.
2040
+ * @deprecated Use `.writeSync(text)` instead — `writeSync` now accepts strings.
2041
+ */
2042
+ writeTextSync(text, options) {
2043
+ return this.writeSync(text, options);
2044
+ }
2045
+ /** Writes out the provided object as compact JSON. */
2046
+ async writeJson(obj, options) {
2047
+ await this.write(JSON.stringify(obj) + "\n", options);
2048
+ return this;
2049
+ }
2050
+ /** Synchronously writes out the provided object as compact JSON. */
2051
+ writeJsonSync(obj, options) {
2052
+ this.writeSync(JSON.stringify(obj) + "\n", options);
2053
+ return this;
2054
+ }
2055
+ /** Writes out the provided object as formatted JSON. */
2056
+ async writeJsonPretty(obj, options) {
2057
+ await this.write(JSON.stringify(obj, void 0, 2) + "\n", options);
2058
+ return this;
2059
+ }
2060
+ /** Synchronously writes out the provided object as formatted JSON. */
2061
+ writeJsonPrettySync(obj, options) {
2062
+ this.writeSync(JSON.stringify(obj, void 0, 2) + "\n", options);
2063
+ return this;
2064
+ }
2065
+ /** Appends the provided bytes or text to the file.
2066
+ *
2067
+ * Strings are encoded as UTF-8.
2068
+ */
2069
+ async append(data, options) {
2070
+ const bytes = typeof data === "string" ? new TextEncoder().encode(data) : data;
2071
+ await this.#withFileForAppending(options, (file) => writeAll(file, bytes, options?.signal));
2072
+ return this;
2073
+ }
2074
+ /** Synchronously appends the provided bytes or text to the file.
2075
+ *
2076
+ * Strings are encoded as UTF-8.
2077
+ */
2078
+ appendSync(data, options) {
2079
+ const bytes = typeof data === "string" ? new TextEncoder().encode(data) : data;
2080
+ this.#withFileForAppendingSync(options, (file) => {
2081
+ writeAllSync(file, bytes, options?.signal);
2082
+ });
2083
+ return this;
2084
+ }
2085
+ #withFileForAppending(options, action) {
2086
+ return this.#withFileForWriting({
2087
+ append: true,
2088
+ ...options
2089
+ }, action);
2090
+ }
2091
+ async #withFileForWriting(options, action) {
2092
+ const file = await this.#openFileMaybeCreatingDirectory({
2093
+ write: true,
2094
+ create: true,
2095
+ truncate: options?.append !== true,
2096
+ ...options
2097
+ });
2098
+ try {
2099
+ return await action(file);
2100
+ } finally {
2101
+ try {
2102
+ file.close();
2103
+ } catch {
2104
+ }
2105
+ }
2106
+ }
2107
+ /** Opens a file, but handles if the directory does not exist. */
2108
+ async #openFileMaybeCreatingDirectory(options) {
2109
+ const resolvedPath = this.resolve();
2110
+ try {
2111
+ return await resolvedPath.open(options);
2112
+ } catch (err) {
2113
+ if (isNotFoundError(err)) {
2114
+ const parent = resolvedPath.parent();
2115
+ if (parent != null) {
2116
+ try {
2117
+ await parent.mkdir();
2118
+ } catch {
2119
+ throw err;
2120
+ }
2121
+ }
2122
+ return await resolvedPath.open(options);
2123
+ } else {
2124
+ throw err;
2125
+ }
2126
+ }
2127
+ }
2128
+ #withFileForAppendingSync(options, action) {
2129
+ return this.#withFileForWritingSync({
2130
+ append: true,
2131
+ ...options
2132
+ }, action);
2133
+ }
2134
+ #withFileForWritingSync(options, action) {
2135
+ const file = this.#openFileForWritingSync(options);
2136
+ try {
2137
+ return action(file);
2138
+ } finally {
2139
+ try {
2140
+ file.close();
2141
+ } catch {
2142
+ }
2143
+ }
2144
+ }
2145
+ /** Opens a file for writing, but handles if the directory does not exist. */
2146
+ #openFileForWritingSync(options) {
2147
+ return this.#openFileMaybeCreatingDirectorySync({
2148
+ write: true,
2149
+ create: true,
2150
+ truncate: options?.append !== true,
2151
+ ...options
2152
+ });
2153
+ }
2154
+ /** Opens a file for writing, but handles if the directory does not exist. */
2155
+ #openFileMaybeCreatingDirectorySync(options) {
2156
+ try {
2157
+ return this.openSync(options);
2158
+ } catch (err) {
2159
+ if (isNotFoundError(err)) {
2160
+ const parent = this.resolve().parent();
2161
+ if (parent != null) {
2162
+ try {
2163
+ parent.mkdirSync();
2164
+ } catch {
2165
+ throw err;
2166
+ }
2167
+ }
2168
+ return this.openSync(options);
2169
+ } else {
2170
+ throw err;
2171
+ }
2172
+ }
2173
+ }
2174
+ /** Changes the permissions of the file or directory. */
2175
+ async chmod(mode) {
2176
+ await chmod(this.#path, mode);
2177
+ return this;
2178
+ }
2179
+ /** Synchronously changes the permissions of the file or directory. */
2180
+ chmodSync(mode) {
2181
+ chmodSync(this.#path, mode);
2182
+ return this;
2183
+ }
2184
+ /** Changes the ownership permissions of the file. */
2185
+ async chown(uid, gid) {
2186
+ await chown(this.#path, uid, gid);
2187
+ return this;
2188
+ }
2189
+ /** Synchronously changes the ownership permissions of the file. */
2190
+ chownSync(uid, gid) {
2191
+ chownSync(this.#path, uid, gid);
2192
+ return this;
2193
+ }
2194
+ /** Creates a new file or opens the existing one. */
2195
+ create() {
2196
+ return createFile(this.#path).then((file) => createFsFileWrapper(file));
2197
+ }
2198
+ /** Synchronously creates a new file or opens the existing one. */
2199
+ createSync() {
2200
+ return createFsFileWrapper(createFileSync(this.#path));
2201
+ }
2202
+ /** Creates a file throwing if a file previously existed. */
2203
+ createNew() {
2204
+ return this.open({
2205
+ createNew: true,
2206
+ read: true,
2207
+ write: true
2208
+ });
2209
+ }
2210
+ /** Synchronously creates a file throwing if a file previously existed. */
2211
+ createNewSync() {
2212
+ return this.openSync({
2213
+ createNew: true,
2214
+ read: true,
2215
+ write: true
2216
+ });
2217
+ }
2218
+ /** Opens a file. */
2219
+ open(options) {
2220
+ return openFile(this.#path, options).then((file) => createFsFileWrapper(file));
2221
+ }
2222
+ /** Opens a file synchronously. */
2223
+ openSync(options) {
2224
+ return createFsFileWrapper(openFileSync(this.#path, options));
2225
+ }
2226
+ /** Removes the file or directory from the file system. */
2227
+ async remove(options) {
2228
+ await remove(this.#path, options);
2229
+ return this;
2230
+ }
2231
+ /** Removes the file or directory from the file system synchronously. */
2232
+ removeSync(options) {
2233
+ removeSync(this.#path, options);
2234
+ return this;
2235
+ }
2236
+ /** Removes the file or directory from the file system, but doesn't throw
2237
+ * when the file doesn't exist.
2238
+ */
2239
+ async ensureRemove(options) {
2240
+ try {
2241
+ return await this.remove(options);
2242
+ } catch (err) {
2243
+ if (isNotFoundError(err)) {
2244
+ return this;
2245
+ } else {
2246
+ throw err;
2247
+ }
2248
+ }
2249
+ }
2250
+ /** Removes the file or directory from the file system, but doesn't throw
2251
+ * when the file doesn't exist.
2252
+ */
2253
+ ensureRemoveSync(options) {
2254
+ try {
2255
+ return this.removeSync(options);
2256
+ } catch (err) {
2257
+ if (isNotFoundError(err)) {
2258
+ return this;
2259
+ } else {
2260
+ throw err;
2261
+ }
2262
+ }
2263
+ }
2264
+ /**
2265
+ * Ensures that a directory is empty.
2266
+ * Deletes directory contents if the directory is not empty.
2267
+ * If the directory does not exist, it is created.
2268
+ * The directory itself is not deleted.
2269
+ */
2270
+ async emptyDir() {
2271
+ await emptyDir(this.toString());
2272
+ return this;
2273
+ }
2274
+ /** Synchronous version of `emptyDir()` */
2275
+ emptyDirSync() {
2276
+ emptyDirSync(this.toString());
2277
+ return this;
2278
+ }
2279
+ /** Ensures that the directory exists.
2280
+ * If the directory structure does not exist, it is created. Like mkdir -p.
2281
+ */
2282
+ async ensureDir() {
2283
+ await ensureDir(this.toString());
2284
+ return this;
2285
+ }
2286
+ /** Synchronously ensures that the directory exists.
2287
+ * If the directory structure does not exist, it is created. Like mkdir -p.
2288
+ */
2289
+ ensureDirSync() {
2290
+ ensureDirSync(this.toString());
2291
+ return this;
2292
+ }
2293
+ /**
2294
+ * Ensures that the file exists.
2295
+ * If the file that is requested to be created is in directories that do
2296
+ * not exist these directories are created. If the file already exists,
2297
+ * it is NOTMODIFIED.
2298
+ */
2299
+ async ensureFile() {
2300
+ await ensureFile(this.toString());
2301
+ return this;
2302
+ }
2303
+ /**
2304
+ * Synchronously ensures that the file exists.
2305
+ * If the file that is requested to be created is in directories that do
2306
+ * not exist these directories are created. If the file already exists,
2307
+ * it is NOTMODIFIED.
2308
+ */
2309
+ ensureFileSync() {
2310
+ ensureFileSync(this.toString());
2311
+ return this;
2312
+ }
2313
+ /** Copies a file or directory to the provided destination.
2314
+ * @returns The destination path.
2315
+ */
2316
+ async copy(destinationPath, options) {
2317
+ const pathRef = ensurePath(destinationPath);
2318
+ await copy(this.#path, pathRef.toString(), options);
2319
+ return pathRef;
2320
+ }
2321
+ /** Copies a file or directory to the provided destination synchronously.
2322
+ * @returns The destination path.
2323
+ */
2324
+ copySync(destinationPath, options) {
2325
+ const pathRef = ensurePath(destinationPath);
2326
+ copySync(this.#path, pathRef.toString(), options);
2327
+ return pathRef;
2328
+ }
2329
+ /**
2330
+ * Copies the file or directory to the specified directory.
2331
+ * @returns The destination path.
2332
+ */
2333
+ copyToDir(destinationDirPath, options) {
2334
+ const destinationPath = ensurePath(destinationDirPath).join(this.basename());
2335
+ return this.copy(destinationPath, options);
2336
+ }
2337
+ /**
2338
+ * Copies the file or directory to the specified directory synchronously.
2339
+ * @returns The destination path.
2340
+ */
2341
+ copyToDirSync(destinationDirPath, options) {
2342
+ const destinationPath = ensurePath(destinationDirPath).join(this.basename());
2343
+ return this.copySync(destinationPath, options);
2344
+ }
2345
+ /**
2346
+ * Copies the file to the specified destination path.
2347
+ * @returns The destination path.
2348
+ */
2349
+ copyFile(destinationPath) {
2350
+ const pathRef = ensurePath(destinationPath);
2351
+ return copyFileFn(this.#path, pathRef.toString()).then(() => pathRef);
2352
+ }
2353
+ /**
2354
+ * Copies the file to the destination path synchronously.
2355
+ * @returns The destination path.
2356
+ */
2357
+ copyFileSync(destinationPath) {
2358
+ const pathRef = ensurePath(destinationPath);
2359
+ copyFileSyncFn(this.#path, pathRef.toString());
2360
+ return pathRef;
2361
+ }
2362
+ /**
2363
+ * Copies the file to the specified directory.
2364
+ * @returns The destination path.
2365
+ */
2366
+ copyFileToDir(destinationDirPath) {
2367
+ const destinationPath = ensurePath(destinationDirPath).join(this.basename());
2368
+ return this.copyFile(destinationPath);
2369
+ }
2370
+ /**
2371
+ * Copies the file to the specified directory synchronously.
2372
+ * @returns The destination path.
2373
+ */
2374
+ copyFileToDirSync(destinationDirPath) {
2375
+ const destinationPath = ensurePath(destinationDirPath).join(this.basename());
2376
+ return this.copyFileSync(destinationPath);
2377
+ }
2378
+ /**
2379
+ * Moves the file or directory returning a promise that resolves to
2380
+ * the renamed path.
2381
+ * @returns The destination path.
2382
+ */
2383
+ rename(newPath) {
2384
+ const pathRef = ensurePath(newPath);
2385
+ return renameFn(this.#path, pathRef.toString()).then(() => pathRef);
2386
+ }
2387
+ /**
2388
+ * Moves the file or directory returning the renamed path synchronously.
2389
+ * @returns The destination path.
2390
+ */
2391
+ renameSync(newPath) {
2392
+ const pathRef = ensurePath(newPath);
2393
+ renameSyncFn(this.#path, pathRef.toString());
2394
+ return pathRef;
2395
+ }
2396
+ /**
2397
+ * Moves the file or directory to the specified directory.
2398
+ * @returns The destination path.
2399
+ */
2400
+ renameToDir(destinationDirPath) {
2401
+ const destinationPath = ensurePath(destinationDirPath).join(this.basename());
2402
+ return this.rename(destinationPath);
2403
+ }
2404
+ /**
2405
+ * Moves the file or directory to the specified directory synchronously.
2406
+ * @returns The destination path.
2407
+ */
2408
+ renameToDirSync(destinationDirPath) {
2409
+ const destinationPath = ensurePath(destinationDirPath).join(this.basename());
2410
+ return this.renameSync(destinationPath);
2411
+ }
2412
+ /** Opens the file and pipes it to the writable stream. */
2413
+ async pipeTo(dest, options) {
2414
+ const file = await openFile(this.#path, { read: true });
2415
+ try {
2416
+ await file.readable.pipeTo(dest, options);
2417
+ } finally {
2418
+ try {
2419
+ file.close();
2420
+ } catch {
2421
+ }
2422
+ }
2423
+ return this;
2424
+ }
2425
+ };
2426
+ function ensurePath(path2) {
2427
+ return path2 instanceof Path ? path2 : new Path(path2);
2428
+ }
2429
+ function createFsFileWrapper(file) {
2430
+ Object.setPrototypeOf(file, FsFileWrapper.prototype);
2431
+ return file;
2432
+ }
2433
+ var FsFileWrapper = class extends FsFile {
2434
+ /** Writes the provided text to this file, looping to handle partial writes. */
2435
+ writeText(text) {
2436
+ return this.writeBytes(new TextEncoder().encode(text));
2437
+ }
2438
+ /** Synchronously writes the provided text to this file, looping to handle partial writes. */
2439
+ writeTextSync(text) {
2440
+ return this.writeBytesSync(new TextEncoder().encode(text));
2441
+ }
2442
+ /** Writes all the provided bytes to this file, looping to handle partial writes. */
2443
+ async writeBytes(bytes) {
2444
+ let nwritten = 0;
2445
+ while (nwritten < bytes.length) {
2446
+ nwritten += await this.write(bytes.subarray(nwritten));
2447
+ }
2448
+ return this;
2449
+ }
2450
+ /** Synchronously writes all the provided bytes to this file, looping to handle partial writes. */
2451
+ writeBytesSync(bytes) {
2452
+ let nwritten = 0;
2453
+ while (nwritten < bytes.length) {
2454
+ nwritten += this.writeSync(bytes.subarray(nwritten));
2455
+ }
2456
+ return this;
2457
+ }
2458
+ /** Writes all the provided data to this file, dispatching to `.writeText` or `.writeBytes` based on input type. */
2459
+ writeAll(data) {
2460
+ return typeof data === "string" ? this.writeText(data) : this.writeBytes(data);
2461
+ }
2462
+ /** Synchronously writes all the provided data to this file, dispatching to `.writeTextSync` or `.writeBytesSync` based on input type. */
2463
+ writeAllSync(data) {
2464
+ return typeof data === "string" ? this.writeTextSync(data) : this.writeBytesSync(data);
2465
+ }
2466
+ };
2467
+ async function createSymlink(opts) {
2468
+ let kind = opts.type;
2469
+ if (kind == null && isWindows2()) {
2470
+ const info = await opts.targetPath.lstat();
2471
+ if (info?.isDirectory()) {
2472
+ kind = "dir";
2473
+ } else if (info?.isFile()) {
2474
+ kind = "file";
2475
+ } else {
2476
+ throw createNotFoundError(`The target path '${opts.targetPath}' did not exist or path kind could not be determined. When the path doesn't exist, you need to specify a symlink type on Windows.`);
2477
+ }
2478
+ }
2479
+ await symlinkFn(opts.text, opts.fromPath.toString(), kind == null ? void 0 : {
2480
+ type: kind
2481
+ });
2482
+ }
2483
+ function createSymlinkSync(opts) {
2484
+ let kind = opts.type;
2485
+ if (kind == null && isWindows2()) {
2486
+ const info = opts.targetPath.lstatSync();
2487
+ if (info?.isDirectory()) {
2488
+ kind = "dir";
2489
+ } else if (info?.isFile()) {
2490
+ kind = "file";
2491
+ } else {
2492
+ throw createNotFoundError(`The target path '${opts.targetPath}' did not exist or path kind could not be determined. When the path doesn't exist, you need to specify a symlink type on Windows.`);
2493
+ }
2494
+ }
2495
+ symlinkSyncFn(opts.text, opts.fromPath.toString(), kind == null ? void 0 : {
2496
+ type: kind
2497
+ });
2498
+ }
2499
+ async function notFoundToUndefined(action) {
2500
+ try {
2501
+ return await action();
2502
+ } catch (err) {
2503
+ if (isNotFoundError(err)) {
2504
+ return void 0;
2505
+ } else {
2506
+ throw err;
2507
+ }
2508
+ }
2509
+ }
2510
+ function notFoundToUndefinedSync(action) {
2511
+ try {
2512
+ return action();
2513
+ } catch (err) {
2514
+ if (isNotFoundError(err)) {
2515
+ return void 0;
2516
+ } else {
2517
+ throw err;
2518
+ }
2519
+ }
2520
+ }
2521
+ async function writeAll(writer, data, signal) {
2522
+ let nwritten = 0;
2523
+ while (nwritten < data.length) {
2524
+ signal?.throwIfAborted();
2525
+ nwritten += await writer.write(data.subarray(nwritten));
2526
+ }
2527
+ }
2528
+ function writeAllSync(writer, data, signal) {
2529
+ let nwritten = 0;
2530
+ while (nwritten < data.length) {
2531
+ signal?.throwIfAborted();
2532
+ nwritten += writer.writeSync(data.subarray(nwritten));
2533
+ }
2534
+ }
2535
+ function* splitLines(text) {
2536
+ if (text === "")
2537
+ return;
2538
+ let start = 0;
2539
+ while (true) {
2540
+ const nl = text.indexOf("\n", start);
2541
+ if (nl === -1) {
2542
+ if (start < text.length)
2543
+ yield text.substring(start);
2544
+ return;
2545
+ }
2546
+ const end = nl > start && text.charCodeAt(nl - 1) === 13 ? nl - 1 : nl;
2547
+ yield text.substring(start, end);
2548
+ start = nl + 1;
2549
+ if (start === text.length)
2550
+ return;
2551
+ }
2552
+ }
2553
+ export {
2554
+ FsFile,
2555
+ FsFileWrapper,
2556
+ Path,
2557
+ mod_default as default,
2558
+ path
2559
+ };