-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathyavascript.d.ts
5773 lines (5198 loc) · 191 KB
/
yavascript.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// NOTE: This copy of yavascript.d.ts reflects what is in git.
// APIs may differ from what you have installed.
// Run `yavascript --print-types > yavascript.d.ts` to get the types
// corresponding to your specific `yavascript` binary.
// ===============
// ---------------
// YavaScript APIs
// ---------------
// ===============
/**
* Prints help and usage text about the provided value, if any is available.
*/
declare var help: {
/**
* Prints help and usage text about the provided value, if any is available.
*/
(value?: any): void;
/**
* Set the help text for the provided value to the provided string.
*
* If the value is later passed into the `help` function, the provided text
* will be printed.
*/
setHelpText: {
/**
* Set the help text for the provided value to the provided string.
*
* If the value is later passed into the `help` function, the provided text
* will be printed.
*
* To set help text for the values `null` or `undefined`, `allowNullish`
* must be `true`.
*/
(value: object, text: string, allowNullish?: boolean): void;
/**
* Lazily sets the help text for the provided value using the provided
* string-returning function.
*
* The first time help text is requested for the value, the string-returning
* function will be called, and its result will be registered as the help
* text for the value. Afterwards, the function will not be called again;
* instead, it will re-use the text returned from the first time the
* function was called.
*/
lazy(value: object, getText: () => string): void;
};
};
/** Info about the currently-running yavascript binary */
declare const yavascript: {
/**
* The version of the currently-running yavascript binary.
*
* Will be something formatted like one of these:
* - "v0.0.7"
* - "v0.1.3-alpha"
* - "git-286a3a336849"
* - "git-286a3a336849-dirty"
*
* Or, more formally: either a "V" version string or a "GIT" version string:
* - "V" version strings start with the character 'v', followed by a semver
* version string, optionally followed by the character '-' and any
* arbitrary content afterwards.
* - "GIT" version strings start with the prefix "git-", followed by the
* first 12 digits of a git commit SHA, optionally followed by the
* character '-' and any arbitrary content afterwards.
*/
version: string;
/** The processor architecture we're running on. */
arch: "x86_64" | "arm64";
/**
* The version of the ecma262 standard supported by the currently-running yavascript binary.
*
* Will always be in the format "ES" + a year. Is never lower than ES2020.
*/
ecmaVersion: string;
/** The compilers yavascript uses internally to load files. */
compilers: {
js(
code: string,
options?: { filename?: string; expression?: boolean }
): string;
tsx(
code: string,
options?: { filename?: string; expression?: boolean }
): string;
ts(
code: string,
options?: { filename?: string; expression?: boolean }
): string;
jsx(
code: string,
options?: { filename?: string; expression?: boolean }
): string;
coffee(
code: string,
options?: { filename?: string; expression?: boolean }
): string;
civet(
code: string,
options?: { filename?: string; expression?: boolean }
): string;
autodetect(
code: string,
options?: { filename?: string; expression?: boolean }
): string;
};
};
/**
* An object representing the process's environment variables. You can read
* from it to read environment variables, write into it to set environment
* variables, and/or delete properties from it to unset environment variables.
* Any value you write will be coerced into a string.
*/
declare const env: { [key: string]: string | undefined };
/**
* Parse command line --flags into an object of flags and an array of
* positional arguments. This function is opinionated; if it doesn't meet your
* needs, you can parse the `scriptArgs` global manually.
*
* Flags `--like-this`, `--like_this`, or `--LIKE_THIS` get converted into
* property names `likeThis` on the returned flags object.
*
* Flags like this: `-v` get converted into into property names like this: `v`
* on the returned flags object.
*
* Anything that appears after `--` is considered a positional argument instead
* of a flag. `--` is not present in the returned positional arguments Array.
*
* @param hints - An object whose keys are flag names (in camelCase) and whose values indicate what type to treat that flag as. Valid property values are `String`, `Boolean`, `Number`, and `Path`. `Path` will resolve relative paths into absolute paths for you. If no hints object is specified, `parseScriptArgs` will do its best to guess, based on the command-line args.
* @param argv - An array containing the command line flags you want to parse. If unspecified, `scriptArgs.slice(2)` will be used (we slice 2 in order to skip the yavascript binary and script name). If you pass in an array here, it should only contain command-line flags, not the binary being called.
*
* @returns An object with three properties: `flags`, `args`, and `metadata`. `flags` is an object whose keys are camelCase flag names and whose values are strings, booleans, numbers, or `Path`s corresponding to the input command-line args. `args` is an Array of positional arguments, as found on the command-line. `metadata` contains information about what name and type the flags got mapped to.
*/
declare function parseScriptArgs(
hints?: {
[key: string]: typeof String | typeof Boolean | typeof Number | typeof Path;
},
args?: Array<string>
): {
flags: { [key: string]: any };
args: Array<string>;
metadata: {
keys: {
[key: string]: string | undefined;
};
hints: {
[key: string]: string | undefined;
};
guesses: {
[key: string]: string | undefined;
};
};
};
/**
* Read the contents of a file from disk.
*/
declare const readFile: {
/**
* Read the contents of a file from disk, as a UTF-8 string.
*/
(path: string | Path): string;
/**
* Read the contents of a file from disk, as a UTF-8 string.
*/
(path: string | Path, options: {}): string;
/**
* Read the contents of a file from disk, as a UTF-8 string.
*/
(path: string | Path, options: { binary: false }): string;
/**
* Read the contents of a file from disk, as an ArrayBuffer.
*/
(path: string | Path, options: { binary: true }): ArrayBuffer;
};
/**
* Write the contents of a string or ArrayBuffer to a file.
*
* Strings are written using the UTF-8 encoding.
*/
declare function writeFile(
path: string | Path,
data: string | ArrayBuffer
): void;
/**
* Function which returns true if the path points to a regular file.
*/
declare function isFile(path: string | Path): boolean;
/**
* Function which returns true if the path points to a directory, or if the
* path points to a symlink which points to a directory. Otherwise, it returns
* false.
*/
declare function isDir(path: string | Path): boolean;
/**
* Returns true if the path points to a symlink.
*/
declare function isLink(path: string | Path): boolean;
/**
* Returns true if the resource at the provided path can be executed by the
* current user.
*
* If nothing exists at that path, an error will be thrown.
*/
declare function isExecutable(path: string | Path): boolean;
/**
* Returns true if the resource at the provided path can be read by the current
* user.
*
* If nothing exists at that path, an error will be thrown.
*/
declare function isReadable(path: string | Path): boolean;
/**
* Returns true if a resource at the provided path could be written to by the
* current user.
*/
declare function isWritable(path: string | Path): boolean;
/**
* Delete the file or directory at the specified path.
*
* If the directory isn't empty, its contents will be deleted, too.
*
* Provides the same functionality as the command `rm -rf`.
*/
declare function remove(path: string | Path): void;
/**
* Returns true if a file or directory exists at the specified path.
*
* Provides the same functionality as the command `test -e`.
*/
declare function exists(path: string | Path): boolean;
/**
* Options for {@link copy}.
*/
declare type CopyOptions = {
/**
* What to do when attempting to copy something into a location where
* something else already exists.
*
* Defaults to "error".
*/
whenTargetExists?: "overwrite" | "skip" | "error";
/** Options which control logging. */
logging?: {
/**
* If provided, this function will be called multiple times as `copy`
* traverses the filesystem, to help you understand what's going on and/or
* troubleshoot things. In most cases, it makes sense to use a logging
* function here, like so:
*
* ```js
* copy("./source", "./destination", {
* logging: { trace: console.log },
* });
* ```
*
* Defaults to the current value of {@link logger.trace}. `logger.trace`
* defaults to a no-op function.
*/
trace?: (...args: Array<any>) => void;
/**
* An optional, user-provided logging function to be used for informational
* messages.
*
* Defaults to the current value of {@link logger.info}. `logger.info`
* defaults to a function which writes to stderr.
*/
info?: (...args: Array<any>) => void;
};
};
/**
* Copies a file or folder from one location to another.
* Folders are copied recursively.
*
* Provides the same functionality as the command `cp -R`.
*/
declare function copy(
from: string | Path,
to: string | Path,
options?: CopyOptions
): void;
/**
* Rename the file or directory at the specified path.
*
* Provides the same functionality as the command `mv`.
*/
declare function rename(from: string | Path, to: string | Path): void;
/** An object that represents a filesystem path. */
declare class Path {
/** The character used to separate path segments on this OS. */
static readonly OS_SEGMENT_SEPARATOR: "/" | "\\";
/**
* The character used to separate entries within the PATH environment
* variable on this OS.
*/
static readonly OS_ENV_VAR_SEPARATOR: ":" | ";";
/**
* A list of suffixes that could appear in the filename for a program on the
* current OS. For instance, on Windows, programs often end with ".exe".
*
* On Unix-like OSes, this is empty. On Windows, it's based on `env.PATHEXT`.
*/
static readonly OS_PROGRAM_EXTENSIONS: ReadonlySet<string>;
/** Split one or more path strings into an array of path segments. */
static splitToSegments(inputParts: Array<string> | string): Array<string>;
/**
* Search the provided path string or strings for a path separator character,
* and return it. If none is found, return `fallback`, which defaults to the
* OS's path segment separator.
*/
static detectSeparator<Fallback extends string | null = string>(
input: Array<string> | string,
// @ts-ignore might be instantiated with a different subtype
fallback: Fallback = Path.OS_SEGMENT_SEPARATOR
): string | Fallback;
/**
* Concatenates the input path(s) and then resolves all non-leading `.` and
* `..` segments.
*/
static normalize(
...inputs: Array<string | Path | Array<string | Path>>
): Path;
/**
* Return whether the provided path is absolute; that is, whether it
* starts with either `/` or a drive letter (ie `C:`).
*/
static isAbsolute(path: string | Path): boolean;
/**
* An array of the path segments that make up this path.
*
* For `/tmp/foo.txt`, it'd be `["", "tmp", "foo.txt"]`.
*
* For `C:\something\somewhere.txt`, it'd be `["C:", "something", "somewhere.txt"]`.
*/
segments: Array<string>;
/**
* The path separator that should be used to turn this path into a string.
*
* Will be either `/` or `\`.
*/
separator: string;
/** Create a new Path object using the provided input(s). */
constructor(...inputs: Array<string | Path | Array<string | Path>>);
/**
* Create a new Path object using the provided segments and separator.
*
* If unspecified, `separator` defaults to `Path.OS_SEGMENT_SEPARATOR`.
*/
static fromRaw(segments: Array<string>, separator?: string): Path;
/**
* Resolve all non-leading `.` and `..` segments in this path.
*/
normalize(): Path;
/**
* Create a new Path by appending additional path segments onto the end of
* this Path's segments.
*
* The returned path will use this path's separator.
*/
concat(...other: Array<string | Path | Array<string | Path>>): Path;
/**
* Return whether this path is absolute; that is, whether it starts with
* either `/`, `\`, or a drive letter (ie `C:`).
*/
isAbsolute(): boolean;
/**
* Make a second Path object containing the same segments and separator as
* this one.
*
* Note that although it contains the same segments, the new Path does not use
* the same Array instance for segments as this one.
*/
clone(): this;
/**
* Express this path relative to `dir`.
*
* @param dir - The directory to create a new path relative to.
* @param options - Options that affect the resulting path.
*/
relativeTo(
dir: Path | string,
options?: {
/**
* Defaults to false. When true, a leading `./` will be omitted from the
* path, if present. Note that a leading `../` will never be omitted.
*/
noLeadingDot?: boolean;
}
): Path;
/**
* Turn this path into a string by joining its segments using its separator.
*/
toString(): string;
/**
* Alias for `toString`; causes Path objects to be serialized as strings when
* they (or an object referencing them) are passed into JSON.stringify.
*/
toJSON(): string;
/**
* Return the final path segment of this path. If this path has no path
* segments, the empty string is returned.
*/
basename(): string;
/**
* Return the trailing extension of this path. The `options` parameter works
* the same as the global `extname`'s `options` parameter.
*/
extname(options?: { full?: boolean }): string;
/**
* Return a new Path containing all of the path segments in this one except
* for the last one; ie. the path to the directory that contains this path.
*/
dirname(): Path;
/**
* Return whether this path starts with the provided value, by comparing one
* path segment at a time.
*
* The starting segments of this path must *exactly* match the segments in the
* provided value.
*
* This means that, given two Paths A and B:
*
* ```
* A: Path { /home/user/.config }
* B: Path { /home/user/.config2 }
* ```
*
* Path B does *not* start with Path A, because `".config" !== ".config2"`.
*/
startsWith(value: string | Path | Array<string | Path>): boolean;
/**
* Return whether this path ends with the provided value, by comparing one
* path segment at a time.
*
* The ending segments of this path must *exactly* match the segments in the
* provided value.
*
* This means that, given two Paths A and B:
*
* ```
* A: Path { /home/1user/.config }
* B: Path { user/.config }
* ```
*
* Path A does *not* end with Path B, because `"1user" !== "user"`.
*/
endsWith(value: string | Path | Array<string | Path>): boolean;
/**
* Return the path segment index at which `value` appears in this path, or
* `-1` if it doesn't appear in this path.
*
* @param value - The value to search for. If the value contains more than one path segment, the returned index will refer to the location of the value's first path segment.
* @param fromIndex - The index into this path's segments to begin searching at. Defaults to `0`.
*/
indexOf(
value: string | Path | Array<string | Path>,
fromIndex?: number | undefined
): number;
/**
* Return whether `value` appears in this path.
*
* @param value - The value to search for.
* @param fromIndex - The index into this path's segments to begin searching at. Defaults to `0`.
*/
includes(
value: string | Path | Array<string | Path>,
fromIndex?: number | undefined
): boolean;
/**
* Return a new Path wherein the segments in `value` have been replaced with
* the segments in `replacement`. If the segments in `value` are not present
* in this path, a clone of this path is returned.
*
* Note that only the first match is replaced.
*
* @param value - What should be replaced
* @param replacement - What it should be replaced with
*/
replace(
value: string | Path | Array<string | Path>,
replacement: string | Path | Array<string | Path>
): Path;
/**
* Return a new Path wherein all occurrences of the segments in `value` have
* been replaced with the segments in `replacement`. If the segments in
* `value` are not present in this path, a clone of this path is returned.
*
* @param value - What should be replaced
* @param replacement - What it should be replaced with
*/
replaceAll(
value: string | Path | Array<string | Path>,
replacement: string | Path | Array<string | Path>
): Path;
/**
* Return a copy of this path but with the final segment replaced with `replacement`
*
* @param replacement - The new final segment(s) for the returned Path
*/
replaceLast(replacement: string | Path | Array<string | Path>): Path;
}
/**
* The absolute path to the currently-executing file (whether script or module).
*
* Behaves the same as in Node.js, except that it's also present within ES
* modules.
*
* Example: `/home/suchipi/some-folder/some-file.js`
*/
declare var __filename: string;
/**
* The absolute path to the directory containing the currently-executing file.
*
* Behaves the same as in Node.js, except that it's also present within ES
* modules.
*
* Example: `/home/suchipi/some-folder`
*/
declare var __dirname: string;
/**
* Return the last component of a path string.
*
* Provides the same functionality as the unix binary of the same name.
*/
declare function basename(path: string | Path): string;
/**
* Reads the contents of one or more files from disk as either one UTF-8 string
* or one ArrayBuffer.
*/
declare const cat: {
/**
* Read the contents of one or more files from disk, as one UTF-8 string.
*/
(paths: string | Path | Array<string | Path>): string;
/**
* Read the contents of one or more files from disk, as one UTF-8 string.
*/
(paths: string | Path | Array<string | Path>, options: {}): string;
/**
* Read the contents of one or more files from disk, as one UTF-8 string.
*/
(
paths: string | Path | Array<string | Path>,
options: { binary: false }
): string;
/**
* Read the contents of one or more files from disk, as one ArrayBuffer.
*/
(
paths: string | Path | Array<string | Path>,
options: { binary: true }
): ArrayBuffer;
};
/**
* Change the process's current working directory to the specified path. If no
* path is specified, moves to the user's home directory.
*
* Provides the same functionality as the shell builtin of the same name.
*/
declare function cd(path?: string | Path): void;
/** A string representing who a permission applies to. */
declare type ChmodPermissionsWho =
| "user"
| "group"
| "others"
| "all"
| "u"
| "g"
| "o"
| "a"
| "ug"
| "go"
| "uo";
/** A string representing the access level for the given permission. */
declare type ChmodPermissionsWhat =
| "read"
| "write"
| "execute"
| "readwrite"
| "none"
| "full"
| "r"
| "w"
| "x"
| "rw"
| "rx"
| "wx"
| "rwx";
/**
* Set the permission bits for the specified file.
*
* @param permissions The permission bits to set. This can be a number, a string containing an octal number, or an object.
* @param path The path to the file.
*/
declare function chmod(
permissions:
| number
| string
| Record<ChmodPermissionsWho, ChmodPermissionsWhat>,
path: string | Path
): void;
/**
* Removes the final component from a path string.
*
* Provides the same functionality as the unix binary of the same name.
*/
declare function dirname(path: string | Path): Path;
/**
* Print one or more values to stdout.
*/
declare const echo: typeof console.log;
/**
* Exit the yavascript process.
*
* Provides the same functionality as the shell builtin of the same name.
*
* If exit is called with an argument, that argument is used as the exit code.
* Otherwise, `exit.code` is used, which defaults to 0.
*
* `exit.code` will also be used as the exit status code for the yavascript
* process if the process exits normally.
*/
declare const exit: {
(code?: number): never;
code: number;
};
/**
* Returns the file extension of the file at a given path.
*
* If the file has no extension (eg `Makefile`, etc), then `''` will be returned.
*
* Pass `{ full: true }` to get compound extensions, eg `.d.ts` or `.test.js` instead of just `.ts`/`.js`.
*/
declare function extname(
pathOrFilename: string | Path,
options?: { full?: boolean }
): string;
/**
* Returns the contents of a directory, as absolute paths. `.` and `..` are
* omitted.
*/
declare function ls(dir?: string | Path): Array<Path>;
/**
* Create a directory (folder).
*
* Provides the same functionality as the unix binary of the same name.
*/
declare function mkdir(
path: string | Path,
options?: {
recursive?: boolean;
mode?: number;
logging?: {
trace?: (...args: Array<any>) => void;
info?: (...args: Array<any>) => void;
};
}
): void;
/**
* Create a directory (folder) and all parents, recursively
*
* Alias for `mkdir(path, { recursive: true })`.
*
* Provides the same functionality as `mkdir -p`.
*/
declare function mkdirp(
path: string | Path,
options?: {
mode?: number;
logging?: {
trace?: (...args: Array<any>) => void;
info?: (...args: Array<any>) => void;
};
}
): void;
/**
* Print data to stdout using C-style format specifiers.
*
* The same formats as the standard C library printf are supported. Integer
* format types (e.g. `%d`) truncate the Numbers or BigInts to 32 bits. Use the l
* modifier (e.g. `%ld`) to truncate to 64 bits.
*/
declare function printf(format: string, ...args: Array<any>): void;
/**
* Returns the process's current working directory.
*
* Provides the same functionality as the shell builtin of the same name.
*/
declare const pwd: {
/**
* Returns the process's current working directory.
*
* Provides the same functionality as the shell builtin of the same name.
*/
(): Path;
/**
* A frozen, read-only `Path` object containing what `pwd()` was when
* yavascript first started up.
*/
readonly initial: Path;
};
/**
* Reads a symlink.
*
* Returns the target of the symlink, which may be absolute or relative.
*
* Provides the same functionality as the unix binary of the same name.
*/
declare function readlink(path: string | Path): Path;
/**
* Get the absolute path given a relative path. Symlinks are also resolved.
*
* The path's target file/directory must exist.
*
* Provides the same functionality as the unix binary of the same name.
*/
declare function realpath(path: string | Path): Path;
/**
* Blocks the current thread for at least the specified number of milliseconds,
* but maybe a tiny bit longer.
*
* alias for `sleep.sync`.
*/
declare var sleep: {
/**
* Blocks the current thread for at least the specified number of milliseconds,
* but maybe a tiny bit longer.
*
* alias for `sleep.sync`.
*
* @param milliseconds - The number of milliseconds to block for.
*/
(milliseconds: number): void;
/**
* Blocks the current thread for at least the specified number of milliseconds,
* but maybe a tiny bit longer.
*
* @param milliseconds - The number of milliseconds to block for.
*/
sync(milliseconds: number): void;
/**
* Returns a Promise which resolves in at least the specified number of
* milliseconds, maybe a little longer.
*
* @param milliseconds - The number of milliseconds to wait before the returned Promise should be resolved.
*/
async(milliseconds: number): Promise<void>;
};
/**
* If the file at `path` exists, update its creation/modification timestamps.
*
* Otherwise, create an empty file at that path.
*
* @param path The target path for the file.
*/
declare function touch(path: string | Path): void;
/**
* Searches the system for the path to a program named `binaryName`.
*
* If the program can't be found, `null` is returned.
*
* @param binaryName The program to search for
* @param options Options which affect how the search is performed
* @param options.searchPaths A list of folders where programs may be found. Defaults to `env.PATH?.split(Path.OS_ENV_VAR_SEPARATOR) || []`.
* @param options.suffixes A list of filename extension suffixes to include in the search, ie [".exe"]. Defaults to `Path.OS_PROGRAM_EXTENSIONS`.
* @param options.trace A logging function that will be called at various times during the execution of `which`. Defaults to {@link logger.trace}.
*/
declare function which(
binaryName: string,
options?: {
/**
* A list of folders where programs may be found. Defaults to
* `env.PATH?.split(Path.OS_ENV_VAR_SEPARATOR) || []`.
*/
searchPaths?: Array<Path | string>;
/**
* A list of filename extension suffixes to include in the search, ie
* `[".exe"]`. Defaults to {@link Path.OS_PROGRAM_EXTENSIONS}.
*/
suffixes?: Array<string>;
/** Options which control logging. */
logging?: {
/**
* If provided, this logging function will be called multiple times as
* `which` runs, to help you understand what's going on and/or troubleshoot
* things. In most cases, it makes sense to use a function from `console`
* here, like so:
*
* ```js
* which("bash", {
* logging: { trace: console.log }
* });
* ```
*
* Defaults to the current value of {@link logger.trace}. `logger.trace`
* defaults to a no-op function.
*/
trace?: (...args: Array<any>) => void;
};
}
): Path | null;
declare type BaseExecOptions = {
/** Sets the current working directory for the child process. */
cwd?: string | Path;
/** Sets environment variables within the process. */
env?: { [key: string | number]: string | number | boolean };
/** Options which control logging. */
logging?: {
/**
* If provided, this logging function will be called multiple times as
* `exec` runs, to help you understand what's going on and/or troubleshoot
* things. In most cases, it makes sense to use a function from `console`
* here, like so:
*
* ```js
* exec(["echo", "hi"], {
* logging: { trace: console.log },
* });
* ```
*
* Defaults to the current value of {@link logger.trace}. `logger.trace`
* defaults to a no-op function.
*/
trace?: (...args: Array<any>) => void;
/**
* An optional, user-provided logging function to be used for informational
* messages. Less verbose than `logging.trace`.
*
* Defaults to the current value of {@link logger.info}. `logger.info`
* defaults to a function which logs to stderr.
*/
info?: (...args: Array<any>) => void;
};
/**
* Whether an Error should be thrown when the process exits with a nonzero
* status code.
*
* Defaults to true.
*/
failOnNonZeroStatus?: boolean;
/**
* If true, stdout and stderr will be collected into strings or array buffers
* and returned instead of being printed to the screen.
*
* Defaults to false. true is an alias for "utf8".
*/
captureOutput?: boolean | "utf8" | "arraybuffer";
/**
* If true, exec doesn't return until the process is done running. If false,
* exec returns an object with a "wait" method which can be used to wait for
* the process to be done running.
*
* Defaults to true.
*/
block?: boolean;
};
type ExecWaitResult<ExecOptions extends BaseExecOptions> = ExecOptions extends
| { captureOutput: true | "utf8" | "arraybuffer" }
| { failOnNonZeroStatus: false }
? (ExecOptions["captureOutput"] extends true | "utf8"
? { stdout: string; stderr: string }
: {}) &
(ExecOptions["captureOutput"] extends "arraybuffer"
? { stdout: ArrayBuffer; stderr: ArrayBuffer }
: {}) &
(ExecOptions["failOnNonZeroStatus"] extends false
?
| { status: number; signal: undefined }
| { status: undefined; signal: number }
: {})
: void;
declare interface Exec {
<
ExecOptions extends BaseExecOptions = {
failOnNonZeroStatus: true;
captureOutput: false;
block: true;
}
>(
args: Array<string | Path | number> | string | Path,
options?: ExecOptions
): ExecOptions["block"] extends false
? { wait(): ExecWaitResult<ExecOptions> }
: ExecWaitResult<ExecOptions>;
/**
* Parse the provided value into an array of command-line argument strings,
* using the same logic that {@link exec} and {@link ChildProcess} use.
*/
toArgv(args: Array<string | Path | number> | string | Path): Array<string>;
}
/**
* Runs a child process using the provided arguments.
*
* The first value in the arguments array is the program to run.
*/
declare const exec: Exec;
/** Alias for `exec(args, { captureOutput: true })` */
declare function $(args: Array<string | Path | number> | string | Path): {