@shd101wyy/yo 0.1.11 → 0.1.13
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/README.md +10 -1
- package/out/cjs/index.cjs +579 -573
- package/out/cjs/yo-cli.cjs +1413 -592
- package/out/esm/index.mjs +437 -431
- package/out/types/src/build-runner.d.ts +1 -1
- package/out/types/src/doc/builder.d.ts +21 -0
- package/out/types/src/doc/builder.test.d.ts +1 -0
- package/out/types/src/doc/extractor.d.ts +27 -0
- package/out/types/src/doc/extractor.test.d.ts +1 -0
- package/out/types/src/doc/model.d.ts +87 -0
- package/out/types/src/doc/render-html.d.ts +23 -0
- package/out/types/src/doc/render-html.test.d.ts +1 -0
- package/out/types/src/doc/render-json.d.ts +7 -0
- package/out/types/src/doc/render-json.test.d.ts +1 -0
- package/out/types/src/doc/render-markdown.d.ts +13 -0
- package/out/types/src/doc/render-markdown.test.d.ts +1 -0
- package/out/types/src/doc/sections.d.ts +7 -0
- package/out/types/src/doc/sections.test.d.ts +1 -0
- package/out/types/src/doc-command.d.ts +10 -0
- package/out/types/src/env.d.ts +1 -0
- package/out/types/src/evaluator/builtins/build.d.ts +17 -0
- package/out/types/src/evaluator/context.d.ts +1 -0
- package/out/types/src/evaluator/exprs/import.d.ts +2 -0
- package/out/types/src/expr.d.ts +2 -1
- package/out/types/src/tests/import-path.test.d.ts +1 -0
- package/out/types/src/token.d.ts +4 -0
- package/out/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +2 -1
- package/scripts/build-site.ts +461 -0
- package/std/alg/hash.yo +12 -24
- package/std/allocator.yo +21 -29
- package/std/async.yo +4 -2
- package/std/build.yo +188 -42
- package/std/cli/arg_parser.yo +37 -1
- package/std/collections/array_list.yo +8 -20
- package/std/collections/btree_map.yo +15 -20
- package/std/collections/deque.yo +13 -15
- package/std/collections/hash_map.yo +15 -54
- package/std/collections/hash_set.yo +14 -50
- package/std/collections/linked_list.yo +6 -23
- package/std/collections/priority_queue.yo +15 -17
- package/std/crypto/md5.yo +10 -9
- package/std/crypto/random.yo +14 -12
- package/std/crypto/sha256.yo +9 -8
- package/std/encoding/base64.yo +13 -15
- package/std/encoding/hex.yo +14 -10
- package/std/encoding/html.yo +14 -11
- package/std/encoding/html_char_utils.yo +14 -11
- package/std/encoding/html_entities.yo +7 -8
- package/std/encoding/json.yo +36 -19
- package/std/encoding/punycode.yo +21 -18
- package/std/encoding/toml.yo +23 -9
- package/std/encoding/utf16.yo +16 -9
- package/std/error.yo +10 -23
- package/std/fmt/display.yo +15 -17
- package/std/fmt/index.yo +6 -27
- package/std/fmt/to_string.yo +4 -10
- package/std/fmt/writer.yo +33 -34
- package/std/fs/dir.yo +37 -30
- package/std/fs/file.yo +77 -75
- package/std/fs/metadata.yo +25 -25
- package/std/fs/temp.yo +21 -27
- package/std/fs/types.yo +20 -23
- package/std/fs/walker.yo +26 -31
- package/std/gc.yo +5 -0
- package/std/glob/index.yo +3 -0
- package/std/http/client.yo +25 -11
- package/std/http/http.yo +20 -0
- package/std/http/index.yo +1 -0
- package/std/io/reader.yo +4 -8
- package/std/io/writer.yo +4 -7
- package/std/libc/assert.yo +2 -2
- package/std/libc/ctype.yo +1 -2
- package/std/libc/dirent.yo +1 -2
- package/std/libc/errno.yo +1 -2
- package/std/libc/fcntl.yo +2 -2
- package/std/libc/float.yo +1 -2
- package/std/libc/limits.yo +1 -2
- package/std/libc/math.yo +2 -0
- package/std/libc/signal.yo +1 -2
- package/std/libc/stdatomic.yo +1 -2
- package/std/libc/stdint.yo +4 -3
- package/std/libc/stdio.yo +2 -0
- package/std/libc/stdlib.yo +2 -0
- package/std/libc/string.yo +2 -0
- package/std/libc/sys/stat.yo +1 -2
- package/std/libc/time.yo +2 -2
- package/std/libc/unistd.yo +2 -0
- package/std/libc/wctype.yo +1 -2
- package/std/libc/windows.yo +2 -2
- package/std/log/index.yo +11 -26
- package/std/net/addr.yo +18 -11
- package/std/net/dns.yo +3 -2
- package/std/net/errors.yo +16 -2
- package/std/net/tcp.yo +25 -22
- package/std/net/udp.yo +14 -12
- package/std/os/env.yo +23 -18
- package/std/os/signal.yo +31 -19
- package/std/path.yo +23 -74
- package/std/prelude.yo +284 -113
- package/std/process.yo +23 -37
- package/std/regex/compiler.yo +3 -5
- package/std/regex/flags.yo +11 -11
- package/std/regex/index.yo +2 -13
- package/std/regex/match.yo +3 -5
- package/std/regex/node.yo +6 -6
- package/std/regex/parser.yo +2 -4
- package/std/regex/unicode.yo +5 -5
- package/std/regex/vm.yo +5 -5
- package/std/string/index.yo +2 -1
- package/std/string/rune.yo +25 -1
- package/std/string/string.yo +31 -19
- package/std/string/unicode.yo +14 -15
- package/std/sync/channel.yo +18 -28
- package/std/sync/cond.yo +4 -0
- package/std/sync/mutex.yo +4 -1
- package/std/sync/once.yo +17 -19
- package/std/sync/rwlock.yo +19 -22
- package/std/sync/waitgroup.yo +21 -23
- package/std/sys/advise.yo +4 -4
- package/std/sys/bufio/buf_reader.yo +19 -16
- package/std/sys/bufio/buf_writer.yo +14 -11
- package/std/sys/clock.yo +4 -4
- package/std/sys/constants.yo +5 -5
- package/std/sys/copy.yo +9 -8
- package/std/sys/dir.yo +9 -8
- package/std/sys/dns.yo +8 -8
- package/std/sys/errors.yo +35 -6
- package/std/sys/events.yo +3 -3
- package/std/sys/externs.yo +3 -3
- package/std/sys/fallocate.yo +4 -4
- package/std/sys/fcntl.yo +8 -6
- package/std/sys/file.yo +7 -8
- package/std/sys/future.yo +1 -3
- package/std/sys/iov.yo +4 -4
- package/std/sys/lock.yo +7 -7
- package/std/sys/mmap.yo +7 -8
- package/std/sys/path.yo +4 -7
- package/std/sys/perm.yo +8 -8
- package/std/sys/pipe.yo +9 -8
- package/std/sys/process.yo +8 -8
- package/std/sys/seek.yo +4 -4
- package/std/sys/signal.yo +4 -4
- package/std/sys/signals.yo +4 -4
- package/std/sys/socket.yo +4 -4
- package/std/sys/socketpair.yo +4 -4
- package/std/sys/sockinfo.yo +4 -4
- package/std/sys/statfs.yo +8 -8
- package/std/sys/statx.yo +4 -4
- package/std/sys/sysinfo.yo +4 -4
- package/std/sys/tcp.yo +8 -8
- package/std/sys/temp.yo +9 -8
- package/std/sys/time.yo +8 -8
- package/std/sys/timer.yo +7 -8
- package/std/sys/tty.yo +13 -10
- package/std/sys/udp.yo +8 -8
- package/std/sys/umask.yo +4 -4
- package/std/sys/unix.yo +5 -5
- package/std/testing/bench.yo +21 -10
- package/std/thread.yo +18 -9
- package/std/time/datetime.yo +12 -14
- package/std/time/duration.yo +12 -14
- package/std/time/instant.yo +13 -16
- package/std/time/sleep.yo +9 -8
- package/std/url/index.yo +3 -19
- package/std/worker.yo +10 -18
package/std/path.yo
CHANGED
|
@@ -1,54 +1,40 @@
|
|
|
1
|
+
//! Cross-platform filesystem path manipulation.
|
|
2
|
+
|
|
1
3
|
open import "./string";
|
|
2
4
|
open import "./fmt";
|
|
3
5
|
open import "./collections/array_list";
|
|
4
6
|
|
|
5
|
-
|
|
6
|
-
* Path - Cross-platform path manipulation
|
|
7
|
-
*
|
|
8
|
-
* Provides utilities for working with filesystem paths similar to Node.js's path module.
|
|
9
|
-
* Path operations are synchronous (pure computation, no I/O).
|
|
10
|
-
*/
|
|
11
|
-
|
|
7
|
+
/// Path parsing error variants.
|
|
12
8
|
PathError :: enum(
|
|
9
|
+
/// The path string was empty.
|
|
13
10
|
EmptyPath,
|
|
11
|
+
/// The path string was malformed.
|
|
14
12
|
InvalidPath(message: String)
|
|
15
13
|
);
|
|
16
14
|
export PathError;
|
|
17
15
|
|
|
18
|
-
|
|
19
|
-
* Path separator for the current platform
|
|
20
|
-
* Unix: '/', Windows: '\\'
|
|
21
|
-
* TODO: Support Windows paths later
|
|
22
|
-
*/
|
|
16
|
+
/// Platform-specific path separator: `'/'` on Unix, `'\\'` on Windows.
|
|
23
17
|
PATH_SEPARATOR :: cond(
|
|
24
18
|
(__yo_process_platform() == "windows") => u8(92), // '\' for Windows
|
|
25
19
|
true => u8(47) // '/' for Unix
|
|
26
20
|
);
|
|
27
21
|
export PATH_SEPARATOR;
|
|
28
22
|
|
|
29
|
-
|
|
30
|
-
* Path delimiter for the current platform
|
|
31
|
-
* Unix: ':', Windows: ';'
|
|
32
|
-
* TODO: Support Windows paths later
|
|
33
|
-
*/
|
|
23
|
+
/// Platform-specific path list delimiter: `':'` on Unix, `';'` on Windows.
|
|
34
24
|
PATH_DELIMITER :: cond(
|
|
35
25
|
(__yo_process_platform() == "windows") => u8(59), // ';' for Windows
|
|
36
26
|
true => u8(58) // ':' for Unix
|
|
37
27
|
);
|
|
38
28
|
export PATH_DELIMITER;
|
|
39
29
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
*/
|
|
30
|
+
/// Filesystem path with segment-based operations.
|
|
31
|
+
/// Paths are normalized on construction: `.` segments are removed, `..` pops the parent.
|
|
43
32
|
Path :: object(
|
|
44
33
|
_segments: ArrayList(String),
|
|
45
34
|
_is_absolute: bool
|
|
46
35
|
);
|
|
47
36
|
impl(Path,
|
|
48
|
-
|
|
49
|
-
* Create a new path from a string
|
|
50
|
-
* Example: Path.new("./src/main.yo")
|
|
51
|
-
*/
|
|
37
|
+
/// Create a new path from a string. Normalizes separators and resolves `.`/`..`.
|
|
52
38
|
new : (fn(path_str: String) -> Self)({
|
|
53
39
|
segments := ArrayList(String).new();
|
|
54
40
|
is_abs := false;
|
|
@@ -173,10 +159,7 @@ impl(Path,
|
|
|
173
159
|
return Self(_segments: segments, _is_absolute: is_abs);
|
|
174
160
|
}),
|
|
175
161
|
|
|
176
|
-
|
|
177
|
-
* Create a path from a C string
|
|
178
|
-
* Example: Path.from_cstr(c"./src/main.yo")
|
|
179
|
-
*/
|
|
162
|
+
/// Create a path from a C string pointer.
|
|
180
163
|
from_cstr : (fn(cstr: *(u8)) -> Self)({
|
|
181
164
|
str_result := String.from_cstr(cstr);
|
|
182
165
|
match(str_result,
|
|
@@ -190,10 +173,7 @@ impl(Path,
|
|
|
190
173
|
);
|
|
191
174
|
}),
|
|
192
175
|
|
|
193
|
-
|
|
194
|
-
* Join this path with another path
|
|
195
|
-
* Example: Path.new("/usr").join(Path.new("local/bin"))
|
|
196
|
-
*/
|
|
176
|
+
/// Join this path with another. If `other` is absolute, returns `other`.
|
|
197
177
|
join : (fn(self: Self, other: Self) -> Self)({
|
|
198
178
|
// If other is absolute, return other
|
|
199
179
|
cond(
|
|
@@ -237,10 +217,7 @@ impl(Path,
|
|
|
237
217
|
return Self(_segments: new_segments, _is_absolute: self._is_absolute);
|
|
238
218
|
}),
|
|
239
219
|
|
|
240
|
-
|
|
241
|
-
* Get the parent path
|
|
242
|
-
* Example: Path.new("/usr/local/bin").parent() => Some(Path.new("/usr/local"))
|
|
243
|
-
*/
|
|
220
|
+
/// Get the parent directory path, or `.None` if there are no segments.
|
|
244
221
|
parent : (fn(self: Self) -> Option(Self))({
|
|
245
222
|
cond(
|
|
246
223
|
(self._segments.len() == usize(0)) => {
|
|
@@ -266,10 +243,7 @@ impl(Path,
|
|
|
266
243
|
return .Some(Self(_segments: new_segments, _is_absolute: self._is_absolute));
|
|
267
244
|
}),
|
|
268
245
|
|
|
269
|
-
|
|
270
|
-
* Get the file name (last segment)
|
|
271
|
-
* Example: Path.new("/usr/local/bin").file_name() => Some("bin")
|
|
272
|
-
*/
|
|
246
|
+
/// Get the last path segment (filename), or `.None` for empty paths.
|
|
273
247
|
file_name : (fn(self: Self) -> Option(String))({
|
|
274
248
|
cond(
|
|
275
249
|
(self._segments.len() == usize(0)) => {
|
|
@@ -281,10 +255,7 @@ impl(Path,
|
|
|
281
255
|
return self._segments.get((self._segments.len() - usize(1)));
|
|
282
256
|
}),
|
|
283
257
|
|
|
284
|
-
|
|
285
|
-
* Get the file stem (file name without extension)
|
|
286
|
-
* Example: Path.new("main.yo").file_stem() => Some("main")
|
|
287
|
-
*/
|
|
258
|
+
/// Get the filename without its extension, or `.None` for empty paths.
|
|
288
259
|
file_stem : (fn(self: Self) -> Option(String))({
|
|
289
260
|
name_opt := self.file_name();
|
|
290
261
|
match(name_opt,
|
|
@@ -310,10 +281,7 @@ impl(Path,
|
|
|
310
281
|
);
|
|
311
282
|
}),
|
|
312
283
|
|
|
313
|
-
|
|
314
|
-
* Get the file extension
|
|
315
|
-
* Example: Path.new("main.yo").extension() => Some("yo")
|
|
316
|
-
*/
|
|
284
|
+
/// Get the file extension (without the dot), or `.None` if there is none.
|
|
317
285
|
extension : (fn(self: Self) -> Option(String))({
|
|
318
286
|
name_opt := self.file_name();
|
|
319
287
|
match(name_opt,
|
|
@@ -346,10 +314,7 @@ impl(Path,
|
|
|
346
314
|
);
|
|
347
315
|
}),
|
|
348
316
|
|
|
349
|
-
|
|
350
|
-
* Replace the extension of the path
|
|
351
|
-
* Example: Path.new("main.yo").with_extension("js") => Path.new("main.js")
|
|
352
|
-
*/
|
|
317
|
+
/// Return a new path with the extension replaced by `ext`.
|
|
353
318
|
with_extension : (fn(self: Self, ext: String) -> Self)({
|
|
354
319
|
cond(
|
|
355
320
|
(self._segments.len() == usize(0)) => {
|
|
@@ -390,10 +355,7 @@ impl(Path,
|
|
|
390
355
|
);
|
|
391
356
|
}),
|
|
392
357
|
|
|
393
|
-
|
|
394
|
-
* Replace the file name (last segment) with a new name
|
|
395
|
-
* Example: Path.new("/usr/local/bin").with_file_name("lib") => Path.new("/usr/local/lib")
|
|
396
|
-
*/
|
|
358
|
+
/// Return a new path with the last segment replaced by `name`.
|
|
397
359
|
with_file_name : (fn(self: Self, name: String) -> Self)({
|
|
398
360
|
cond(
|
|
399
361
|
(self._segments.len() == usize(0)) => {
|
|
@@ -424,10 +386,7 @@ impl(Path,
|
|
|
424
386
|
return Self(_segments: new_segments, _is_absolute: self._is_absolute);
|
|
425
387
|
}),
|
|
426
388
|
|
|
427
|
-
|
|
428
|
-
* Check if this path starts with the given base path
|
|
429
|
-
* Example: Path.new("/usr/local/bin").starts_with(Path.new("/usr")) => true
|
|
430
|
-
*/
|
|
389
|
+
/// Check if this path starts with the given base path (segment-wise).
|
|
431
390
|
starts_with : (fn(self: Self, base: Self) -> bool)({
|
|
432
391
|
// Absolute vs relative mismatch
|
|
433
392
|
cond(
|
|
@@ -476,10 +435,7 @@ impl(Path,
|
|
|
476
435
|
return true;
|
|
477
436
|
}),
|
|
478
437
|
|
|
479
|
-
|
|
480
|
-
* Check if this path ends with the given suffix path
|
|
481
|
-
* Example: Path.new("/usr/local/bin").ends_with(Path.new("local/bin")) => true
|
|
482
|
-
*/
|
|
438
|
+
/// Check if this path ends with the given suffix path (segment-wise).
|
|
483
439
|
ends_with : (fn(self: Self, suffix: Self) -> bool)({
|
|
484
440
|
// Suffix has more segments than self
|
|
485
441
|
cond(
|
|
@@ -543,10 +499,7 @@ impl(Path,
|
|
|
543
499
|
return true;
|
|
544
500
|
}),
|
|
545
501
|
|
|
546
|
-
|
|
547
|
-
* Get all path components as a list of strings
|
|
548
|
-
* Example: Path.new("/usr/local/bin").components() => ["/", "usr", "local", "bin"]
|
|
549
|
-
*/
|
|
502
|
+
/// Get all path components as a list. Absolute paths start with `"/"`.
|
|
550
503
|
components : (fn(self: Self) -> ArrayList(String))({
|
|
551
504
|
result := ArrayList(String).with_capacity((self._segments.len() + usize(1)));
|
|
552
505
|
|
|
@@ -575,16 +528,12 @@ impl(Path,
|
|
|
575
528
|
return result;
|
|
576
529
|
}),
|
|
577
530
|
|
|
578
|
-
|
|
579
|
-
* Check if the path is absolute
|
|
580
|
-
*/
|
|
531
|
+
/// Check if the path is absolute.
|
|
581
532
|
is_absolute : (fn(self: Self) -> bool)(
|
|
582
533
|
self._is_absolute
|
|
583
534
|
),
|
|
584
535
|
|
|
585
|
-
|
|
586
|
-
* Check if the path is relative
|
|
587
|
-
*/
|
|
536
|
+
/// Check if the path is relative (not absolute).
|
|
588
537
|
is_relative : (fn(self: Self) -> bool)(
|
|
589
538
|
!self._is_absolute
|
|
590
539
|
)
|