yavascript 0.0.5 → 0.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +16 -6
- package/bin/darwin/yavascript +0 -0
- package/bin/darwin-arm/yavascript +0 -0
- package/bin/linux/yavascript +0 -0
- package/bin/windows/yavascript.exe +0 -0
- package/package.json +2 -2
- package/yavascript.d.ts +815 -331
package/README.md
CHANGED
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
# yavascript
|
|
2
2
|
|
|
3
|
-
<!-- NOTE: this file is also used as help text by the CLI. Don't use markdown syntax below this line unless said syntax would also be clearly readable as plain text. -->
|
|
4
|
-
|
|
5
3
|
YavaScript is a bash-like script runner which is distributed as a single
|
|
6
|
-
statically-linked binary. Scripts are written in JavaScript
|
|
7
|
-
APIs available for all the things you'd normally want to do in
|
|
8
|
-
such as:
|
|
4
|
+
statically-linked binary. Scripts are written in JavaScript or CoffeeScript.
|
|
5
|
+
There are global APIs available for all the things you'd normally want to do in
|
|
6
|
+
a bash script, such as:
|
|
9
7
|
|
|
10
8
|
- Running programs
|
|
11
9
|
- Accessing environment variables
|
|
@@ -40,4 +38,16 @@ supporting the ES2020 specification.
|
|
|
40
38
|
- Original QuickJS engine: https://bellard.org/quickjs/
|
|
41
39
|
- The fork we use: https://github.com/suchipi/quickjs/
|
|
42
40
|
|
|
43
|
-
|
|
41
|
+
## Compiling
|
|
42
|
+
|
|
43
|
+
### Binaries (all platforms)
|
|
44
|
+
|
|
45
|
+
You will need docker installed, then run `./scripts/build.sh`.
|
|
46
|
+
|
|
47
|
+
### Docker image
|
|
48
|
+
|
|
49
|
+
You will need docker installed, then run `docker build -t yourusername/yavascript .`.
|
|
50
|
+
|
|
51
|
+
---
|
|
52
|
+
|
|
53
|
+
YavaScript is written with <3 by Lily Skye.
|
package/bin/darwin/yavascript
CHANGED
|
Binary file
|
|
Binary file
|
package/bin/linux/yavascript
CHANGED
|
Binary file
|
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "yavascript",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.6",
|
|
4
4
|
"main": "lib/index.js",
|
|
5
5
|
"bin": "lib/cli.js",
|
|
6
6
|
"types": "yavascript.d.ts",
|
|
7
|
-
"author": "Lily
|
|
7
|
+
"author": "Lily Skye <me@suchipi.com>",
|
|
8
8
|
"license": "MIT",
|
|
9
9
|
"repository": "suchipi/yavascript"
|
|
10
10
|
}
|
package/yavascript.d.ts
CHANGED
|
@@ -1,12 +1,8 @@
|
|
|
1
|
-
|
|
1
|
+
// ===============
|
|
2
2
|
// ---------------
|
|
3
3
|
// YavaScript APIs
|
|
4
4
|
// ---------------
|
|
5
|
-
|
|
6
|
-
// -----------
|
|
7
|
-
// --- env ---
|
|
8
|
-
// -----------
|
|
9
|
-
|
|
5
|
+
// ===============
|
|
10
6
|
/**
|
|
11
7
|
* An object representing the process's environment variables. You can read
|
|
12
8
|
* from it to read environment variables, write into it to set environment
|
|
@@ -15,139 +11,125 @@
|
|
|
15
11
|
*/
|
|
16
12
|
declare const env: { [key: string]: string | undefined };
|
|
17
13
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
14
|
+
/**
|
|
15
|
+
* Return the contents of a directory, as absolute paths. `.` and `..` are
|
|
16
|
+
* omitted.
|
|
17
|
+
*
|
|
18
|
+
* Use the `relativePaths` option to get relative paths instead (relative to
|
|
19
|
+
* the parent directory).
|
|
20
|
+
*/
|
|
21
|
+
declare function ls(
|
|
22
|
+
dir?: string,
|
|
23
|
+
options?: { relativePaths?: boolean }
|
|
24
|
+
): Array<string>;
|
|
25
25
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
26
|
+
/**
|
|
27
|
+
* Read a symlink.
|
|
28
|
+
*
|
|
29
|
+
* Returns the target of the symlink, which may be absolute or relative.
|
|
30
|
+
*
|
|
31
|
+
* Provides the same functionality as the unix binary of the same name.
|
|
32
|
+
*/
|
|
33
|
+
declare function readlink(path: string): string;
|
|
29
34
|
|
|
30
|
-
|
|
31
|
-
|
|
35
|
+
/**
|
|
36
|
+
* Read the contents of a file from disk, as a UTF-8 string.
|
|
37
|
+
*/
|
|
38
|
+
declare function readFile(path: string): string;
|
|
32
39
|
|
|
33
|
-
|
|
40
|
+
/**
|
|
41
|
+
* Write the contents of a string or ArrayBuffer to a file.
|
|
42
|
+
*
|
|
43
|
+
* Strings are written using the UTF-8 encoding.
|
|
44
|
+
*/
|
|
45
|
+
declare function writeFile(path: string, data: string | ArrayBuffer): void;
|
|
34
46
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
* If true, stdout and stderr will be collected into strings and returned
|
|
47
|
-
* instead of being printed to the screen.
|
|
48
|
-
*
|
|
49
|
-
* Defaults to false.
|
|
50
|
-
*/
|
|
51
|
-
captureOutput: false;
|
|
52
|
-
}
|
|
53
|
-
): void;
|
|
47
|
+
/**
|
|
48
|
+
* Function which returns true if the path points to a directory, or if the
|
|
49
|
+
* path points to a symlink which points to a directory. Otherwise, it returns
|
|
50
|
+
* false.
|
|
51
|
+
*/
|
|
52
|
+
interface IsDir {
|
|
53
|
+
/**
|
|
54
|
+
* Returns true if the path points to a directory, or if the path points to
|
|
55
|
+
* a symlink which points to a directory. Otherwise, returns false.
|
|
56
|
+
*/
|
|
57
|
+
(path: string): boolean;
|
|
54
58
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
* status code.
|
|
61
|
-
*
|
|
62
|
-
* Defaults to true.
|
|
63
|
-
*/
|
|
64
|
-
failOnNonZeroStatus: false;
|
|
65
|
-
/**
|
|
66
|
-
* If true, stdout and stderr will be collected into strings and returned
|
|
67
|
-
* instead of being printed to the screen.
|
|
68
|
-
*
|
|
69
|
-
* Defaults to false.
|
|
70
|
-
*/
|
|
71
|
-
captureOutput: false;
|
|
72
|
-
}
|
|
73
|
-
): { status: number };
|
|
59
|
+
/**
|
|
60
|
+
* Maximum number of symlinks to follow before erroring. Defaults to 100.
|
|
61
|
+
*/
|
|
62
|
+
symlinkLimit: number;
|
|
63
|
+
}
|
|
74
64
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
*
|
|
82
|
-
* Defaults to true.
|
|
83
|
-
*/
|
|
84
|
-
failOnNonZeroStatus: false;
|
|
85
|
-
}
|
|
86
|
-
): { status: number };
|
|
65
|
+
/**
|
|
66
|
+
* Function which returns true if the path points to a directory, or if the
|
|
67
|
+
* path points to a symlink which points to a directory. Otherwise, it returns
|
|
68
|
+
* false.
|
|
69
|
+
*/
|
|
70
|
+
declare const isDir: IsDir;
|
|
87
71
|
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
* Whether an Error should be thrown when the process exits with a nonzero
|
|
93
|
-
* status code.
|
|
94
|
-
*
|
|
95
|
-
* Defaults to true.
|
|
96
|
-
*/
|
|
97
|
-
failOnNonZeroStatus: true;
|
|
98
|
-
/**
|
|
99
|
-
* If true, stdout and stderr will be collected into strings and returned
|
|
100
|
-
* instead of being printed to the screen.
|
|
101
|
-
*
|
|
102
|
-
* Defaults to false.
|
|
103
|
-
*/
|
|
104
|
-
captureOutput: true;
|
|
105
|
-
}
|
|
106
|
-
): { stdout: string; stderr: string };
|
|
72
|
+
/**
|
|
73
|
+
* Returns true if the path points to a symlink.
|
|
74
|
+
*/
|
|
75
|
+
declare function isLink(path: string): boolean;
|
|
107
76
|
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
*/
|
|
117
|
-
captureOutput: true;
|
|
118
|
-
}
|
|
119
|
-
): { stdout: string; stderr: string };
|
|
77
|
+
/**
|
|
78
|
+
* Delete the file or directory at the specified path.
|
|
79
|
+
*
|
|
80
|
+
* If the directory isn't empty, its contents will be deleted, too.
|
|
81
|
+
*
|
|
82
|
+
* Provides the same functionality as the command `rm -rf`.
|
|
83
|
+
*/
|
|
84
|
+
declare function remove(path: string): void;
|
|
120
85
|
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
*
|
|
128
|
-
* Defaults to true.
|
|
129
|
-
*/
|
|
130
|
-
failOnNonZeroStatus: false;
|
|
131
|
-
captureOutput: true;
|
|
132
|
-
}
|
|
133
|
-
): { stdout: string; stderr: string; status: number };
|
|
86
|
+
/**
|
|
87
|
+
* Returns true if a file or directory exists at the specified path.
|
|
88
|
+
*
|
|
89
|
+
* Provides the same functionality as the command `test -e`.
|
|
90
|
+
*/
|
|
91
|
+
declare function exists(path: string): boolean;
|
|
134
92
|
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
93
|
+
/**
|
|
94
|
+
* Create directories for each of the provided path components,
|
|
95
|
+
* if they don't already exist.
|
|
96
|
+
*
|
|
97
|
+
* Provides the same functionality as the command `mkdir -p`.
|
|
98
|
+
*/
|
|
99
|
+
declare function ensureDir(path: string): string;
|
|
138
100
|
|
|
139
|
-
/**
|
|
140
|
-
|
|
101
|
+
/**
|
|
102
|
+
* Options for {@link copy}.
|
|
103
|
+
*/
|
|
104
|
+
declare type CopyOptions = {
|
|
105
|
+
/**
|
|
106
|
+
* What to do when attempting to copy something into a location where
|
|
107
|
+
* something else already exists.
|
|
108
|
+
*
|
|
109
|
+
* Defaults to "error".
|
|
110
|
+
*/
|
|
111
|
+
whenTargetExists?: "overwrite" | "skip" | "error";
|
|
141
112
|
|
|
142
|
-
/**
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
113
|
+
/**
|
|
114
|
+
* If provided, this function will be called multiple times as `copy`
|
|
115
|
+
* traverses the filesystem, to help you understand what's going on and/or
|
|
116
|
+
* troubleshoot things. In most cases, it makes sense to use a logging
|
|
117
|
+
* function here, like so:
|
|
118
|
+
*
|
|
119
|
+
* ```js
|
|
120
|
+
* copy("./source", "./destination", { trace: console.log });
|
|
121
|
+
* ```
|
|
122
|
+
*/
|
|
123
|
+
trace?: (...args: Array<any>) => void;
|
|
146
124
|
};
|
|
147
125
|
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
126
|
+
/**
|
|
127
|
+
* Copy a file or folder from one location to another.
|
|
128
|
+
* Folders are copied recursively.
|
|
129
|
+
*
|
|
130
|
+
* Provides the same functionality as the command `cp -R`.
|
|
131
|
+
*/
|
|
132
|
+
declare function copy(from: string, to: string, options?: CopyOptions): void;
|
|
151
133
|
|
|
152
134
|
/**
|
|
153
135
|
* Change the process's current working directory to the specified path.
|
|
@@ -265,152 +247,145 @@ declare const __filename: string;
|
|
|
265
247
|
*/
|
|
266
248
|
declare const __dirname: string;
|
|
267
249
|
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
/**
|
|
273
|
-
* Returns the absolute path to the root folder of the git/hg repo.
|
|
274
|
-
*
|
|
275
|
-
* This is done by running `git rev-parse --show-toplevel` and `hg root`.
|
|
276
|
-
*
|
|
277
|
-
* If `relativeTo` is provided, the git and hg commands will be executed in
|
|
278
|
-
* that folder instead of in `pwd()`.
|
|
279
|
-
*/
|
|
280
|
-
declare function repoRoot(relativeTo?: string): string;
|
|
281
|
-
|
|
282
|
-
/**
|
|
283
|
-
* Returns whether the provided path is ignored by git.
|
|
284
|
-
*/
|
|
285
|
-
declare function isGitignored(path: string): boolean;
|
|
286
|
-
|
|
287
|
-
// ------------------
|
|
288
|
-
// --- filesystem ---
|
|
289
|
-
// ------------------
|
|
290
|
-
|
|
291
|
-
/**
|
|
292
|
-
* Return the contents of a directory, as absolute paths. `.` and `..` are
|
|
293
|
-
* omitted.
|
|
294
|
-
*
|
|
295
|
-
* Use the `relativePaths` option to get relative paths instead (relative to
|
|
296
|
-
* the parent directory).
|
|
297
|
-
*/
|
|
298
|
-
declare function ls(
|
|
299
|
-
dir?: string,
|
|
300
|
-
options?: { relativePaths?: boolean }
|
|
301
|
-
): Array<string>;
|
|
302
|
-
|
|
303
|
-
/**
|
|
304
|
-
* Read a symlink.
|
|
305
|
-
*
|
|
306
|
-
* Returns the target of the symlink, which may be absolute or relative.
|
|
307
|
-
*
|
|
308
|
-
* Provides the same functionality as the unix binary of the same name.
|
|
309
|
-
*/
|
|
310
|
-
declare function readlink(path: string): string;
|
|
311
|
-
|
|
312
|
-
/**
|
|
313
|
-
* Read the contents of a file from disk, as a UTF-8 string.
|
|
314
|
-
*/
|
|
315
|
-
declare function readFile(path: string): string;
|
|
250
|
+
declare type BaseExecOptions = {
|
|
251
|
+
/** Sets the current working directory for the child process. */
|
|
252
|
+
cwd?: string;
|
|
316
253
|
|
|
317
|
-
/**
|
|
318
|
-
|
|
319
|
-
*
|
|
320
|
-
* Strings are written using the UTF-8 encoding.
|
|
321
|
-
*/
|
|
322
|
-
declare function writeFile(path: string, data: string | ArrayBuffer): void;
|
|
254
|
+
/** Sets environment variables within the process. */
|
|
255
|
+
env?: { [key: string | number]: string | number | boolean };
|
|
323
256
|
|
|
324
|
-
/**
|
|
325
|
-
* Function which returns true if the path points to a directory, or if the
|
|
326
|
-
* path points to a symlink which points to a directory. Otherwise, it returns
|
|
327
|
-
* false.
|
|
328
|
-
*/
|
|
329
|
-
interface IsDir {
|
|
330
257
|
/**
|
|
331
|
-
*
|
|
332
|
-
*
|
|
258
|
+
* If provided, this function will be called multiple times as `exec`
|
|
259
|
+
* runs, to help you understand what's going on and/or troubleshoot things.
|
|
260
|
+
* In most cases, it makes sense to use a logging function here, like so:
|
|
261
|
+
*
|
|
262
|
+
* ```js
|
|
263
|
+
* exec(["echo", "hi"], { trace: console.log });
|
|
264
|
+
* ```
|
|
333
265
|
*/
|
|
334
|
-
(
|
|
266
|
+
trace?: (...args: Array<any>) => void;
|
|
267
|
+
};
|
|
335
268
|
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
*/
|
|
339
|
-
symlinkLimit: number;
|
|
340
|
-
}
|
|
269
|
+
declare interface Exec {
|
|
270
|
+
(args: Array<string> | string): void;
|
|
341
271
|
|
|
342
|
-
|
|
343
|
-
* Function which returns true if the path points to a directory, or if the
|
|
344
|
-
* path points to a symlink which points to a directory. Otherwise, it returns
|
|
345
|
-
* false.
|
|
346
|
-
*/
|
|
347
|
-
declare const isDir: IsDir;
|
|
272
|
+
(args: Array<string> | string, options: Record<string, never>): void;
|
|
348
273
|
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
274
|
+
(
|
|
275
|
+
args: Array<string> | string,
|
|
276
|
+
options: BaseExecOptions & {
|
|
277
|
+
/**
|
|
278
|
+
* Whether an Error should be thrown when the process exits with a nonzero
|
|
279
|
+
* status code.
|
|
280
|
+
*
|
|
281
|
+
* Defaults to true.
|
|
282
|
+
*/
|
|
283
|
+
failOnNonZeroStatus: true;
|
|
284
|
+
/**
|
|
285
|
+
* If true, stdout and stderr will be collected into strings and returned
|
|
286
|
+
* instead of being printed to the screen.
|
|
287
|
+
*
|
|
288
|
+
* Defaults to false.
|
|
289
|
+
*/
|
|
290
|
+
captureOutput: false;
|
|
291
|
+
}
|
|
292
|
+
): void;
|
|
353
293
|
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
294
|
+
(
|
|
295
|
+
args: Array<string> | string,
|
|
296
|
+
options: BaseExecOptions & {
|
|
297
|
+
/**
|
|
298
|
+
* Whether an Error should be thrown when the process exits with a nonzero
|
|
299
|
+
* status code.
|
|
300
|
+
*
|
|
301
|
+
* Defaults to true.
|
|
302
|
+
*/
|
|
303
|
+
failOnNonZeroStatus: false;
|
|
304
|
+
/**
|
|
305
|
+
* If true, stdout and stderr will be collected into strings and returned
|
|
306
|
+
* instead of being printed to the screen.
|
|
307
|
+
*
|
|
308
|
+
* Defaults to false.
|
|
309
|
+
*/
|
|
310
|
+
captureOutput: false;
|
|
311
|
+
}
|
|
312
|
+
):
|
|
313
|
+
| { status: number; signal: undefined }
|
|
314
|
+
| { status: undefined; signal: number };
|
|
362
315
|
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
316
|
+
(
|
|
317
|
+
args: Array<string> | string,
|
|
318
|
+
options: BaseExecOptions & {
|
|
319
|
+
/**
|
|
320
|
+
* Whether an Error should be thrown when the process exits with a nonzero
|
|
321
|
+
* status code.
|
|
322
|
+
*
|
|
323
|
+
* Defaults to true.
|
|
324
|
+
*/
|
|
325
|
+
failOnNonZeroStatus: false;
|
|
326
|
+
}
|
|
327
|
+
):
|
|
328
|
+
| { status: number; signal: undefined }
|
|
329
|
+
| { status: undefined; signal: number };
|
|
369
330
|
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
331
|
+
(
|
|
332
|
+
args: Array<string> | string,
|
|
333
|
+
options: BaseExecOptions & {
|
|
334
|
+
/**
|
|
335
|
+
* Whether an Error should be thrown when the process exits with a nonzero
|
|
336
|
+
* status code.
|
|
337
|
+
*
|
|
338
|
+
* Defaults to true.
|
|
339
|
+
*/
|
|
340
|
+
failOnNonZeroStatus: true;
|
|
341
|
+
/**
|
|
342
|
+
* If true, stdout and stderr will be collected into strings and returned
|
|
343
|
+
* instead of being printed to the screen.
|
|
344
|
+
*
|
|
345
|
+
* Defaults to false.
|
|
346
|
+
*/
|
|
347
|
+
captureOutput: true;
|
|
348
|
+
}
|
|
349
|
+
): { stdout: string; stderr: string };
|
|
377
350
|
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
351
|
+
(
|
|
352
|
+
args: Array<string> | string,
|
|
353
|
+
options: BaseExecOptions & {
|
|
354
|
+
/**
|
|
355
|
+
* If true, stdout and stderr will be collected into strings and returned
|
|
356
|
+
* instead of being printed to the screen.
|
|
357
|
+
*
|
|
358
|
+
* Defaults to false.
|
|
359
|
+
*/
|
|
360
|
+
captureOutput: true;
|
|
361
|
+
}
|
|
362
|
+
): { stdout: string; stderr: string };
|
|
389
363
|
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
}
|
|
364
|
+
(
|
|
365
|
+
args: Array<string> | string,
|
|
366
|
+
options: BaseExecOptions & {
|
|
367
|
+
/**
|
|
368
|
+
* Whether an Error should be thrown when the process exits with a nonzero
|
|
369
|
+
* status code.
|
|
370
|
+
*
|
|
371
|
+
* Defaults to true.
|
|
372
|
+
*/
|
|
373
|
+
failOnNonZeroStatus: false;
|
|
374
|
+
captureOutput: true;
|
|
375
|
+
}
|
|
376
|
+
):
|
|
377
|
+
| { stdout: string; stderr: string; status: number; signal: undefined }
|
|
378
|
+
| { stdout: string; stderr: string; status: undefined; signal: number };
|
|
379
|
+
}
|
|
402
380
|
|
|
403
|
-
/**
|
|
404
|
-
|
|
405
|
-
* Folders are copied recursively.
|
|
406
|
-
*
|
|
407
|
-
* Provides the same functionality as the command `cp -R`.
|
|
408
|
-
*/
|
|
409
|
-
declare function copy(from: string, to: string, options?: CopyOptions): void;
|
|
381
|
+
/** Run a child process using the provided arguments. The first value in the arguments array is the program to run. */
|
|
382
|
+
declare const exec: Exec;
|
|
410
383
|
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
384
|
+
/** Alias for `exec(args, { captureOutput: true })` */
|
|
385
|
+
declare function $(args: Array<string> | string): {
|
|
386
|
+
stdout: string;
|
|
387
|
+
stderr: string;
|
|
388
|
+
};
|
|
414
389
|
|
|
415
390
|
/**
|
|
416
391
|
* Options for {@link glob}.
|
|
@@ -431,10 +406,15 @@ declare type GlobOptions = {
|
|
|
431
406
|
* function here, like so:
|
|
432
407
|
*
|
|
433
408
|
* ```js
|
|
434
|
-
* glob(
|
|
409
|
+
* glob(["./*.js"], { trace: console.log });
|
|
435
410
|
* ```
|
|
436
411
|
*/
|
|
437
412
|
trace?: (...args: Array<any>) => void;
|
|
413
|
+
|
|
414
|
+
/**
|
|
415
|
+
* Directory to interpret glob patterns relative to. Defaults to `pwd()`.
|
|
416
|
+
*/
|
|
417
|
+
dir?: string;
|
|
438
418
|
};
|
|
439
419
|
|
|
440
420
|
/**
|
|
@@ -444,24 +424,15 @@ declare type GlobOptions = {
|
|
|
444
424
|
* options.
|
|
445
425
|
*/
|
|
446
426
|
declare function glob(
|
|
447
|
-
|
|
448
|
-
patterns: Array<string>,
|
|
427
|
+
patterns: string | Array<string>,
|
|
449
428
|
options?: GlobOptions
|
|
450
429
|
): Array<string>;
|
|
451
430
|
|
|
452
|
-
// ---------------
|
|
453
|
-
// --- console ---
|
|
454
|
-
// ---------------
|
|
455
|
-
|
|
456
431
|
/**
|
|
457
432
|
* Print one or more values to stdout.
|
|
458
433
|
*/
|
|
459
434
|
declare const echo: typeof console.log;
|
|
460
435
|
|
|
461
|
-
// ---------------
|
|
462
|
-
// --- strings ---
|
|
463
|
-
// ---------------
|
|
464
|
-
|
|
465
436
|
/**
|
|
466
437
|
* Remove ANSI control characters from a string.
|
|
467
438
|
*/
|
|
@@ -472,6 +443,11 @@ declare function stripAnsi(input: string): string;
|
|
|
472
443
|
*/
|
|
473
444
|
declare function quote(input: string): string;
|
|
474
445
|
|
|
446
|
+
/**
|
|
447
|
+
* Clear the contents and scrollback buffer of the tty by printing special characters into stdout.
|
|
448
|
+
*/
|
|
449
|
+
declare function clear(): void;
|
|
450
|
+
|
|
475
451
|
// Colors
|
|
476
452
|
|
|
477
453
|
/** Wrap a string with the ANSI control characters that will make it print as black text. */
|
|
@@ -533,10 +509,354 @@ declare function hidden(input: string | number): string;
|
|
|
533
509
|
/** Wrap a string with the ANSI control characters that will make it print with a horizontal line through its center. */
|
|
534
510
|
declare function strikethrough(input: string | number): string;
|
|
535
511
|
|
|
512
|
+
declare type TypedArray =
|
|
513
|
+
| Int8Array
|
|
514
|
+
| Uint8Array
|
|
515
|
+
| Uint8ClampedArray
|
|
516
|
+
| Int16Array
|
|
517
|
+
| Uint16Array
|
|
518
|
+
| Int32Array
|
|
519
|
+
| Uint32Array
|
|
520
|
+
| Float32Array
|
|
521
|
+
| Float64Array;
|
|
522
|
+
declare type TypedArrayConstructor =
|
|
523
|
+
| Int8ArrayConstructor
|
|
524
|
+
| Uint8ArrayConstructor
|
|
525
|
+
| Uint8ClampedArrayConstructor
|
|
526
|
+
| Int16ArrayConstructor
|
|
527
|
+
| Uint16ArrayConstructor
|
|
528
|
+
| Int32ArrayConstructor
|
|
529
|
+
| Uint32ArrayConstructor
|
|
530
|
+
| Float32ArrayConstructor
|
|
531
|
+
| Float64ArrayConstructor;
|
|
532
|
+
|
|
533
|
+
declare const is: {
|
|
534
|
+
string(value: any): value is string;
|
|
535
|
+
String(value: any): value is string;
|
|
536
|
+
number(value: any): value is number;
|
|
537
|
+
Number(value: any): value is number;
|
|
538
|
+
boolean(value: any): value is boolean;
|
|
539
|
+
Boolean(value: any): value is boolean;
|
|
540
|
+
bigint(value: any): value is bigint;
|
|
541
|
+
BigInt(value: any): value is BigInt;
|
|
542
|
+
symbol(value: any): value is symbol;
|
|
543
|
+
Symbol(value: any): value is symbol;
|
|
544
|
+
null(value: any): value is null;
|
|
545
|
+
undefined(value: any): value is undefined;
|
|
546
|
+
void(value: any): value is null | undefined;
|
|
547
|
+
object(value: any): value is {
|
|
548
|
+
[key: string]: unknown;
|
|
549
|
+
[key: number]: unknown;
|
|
550
|
+
[key: symbol]: unknown;
|
|
551
|
+
};
|
|
552
|
+
Object(value: any): value is {
|
|
553
|
+
[key: string]: unknown;
|
|
554
|
+
[key: number]: unknown;
|
|
555
|
+
[key: symbol]: unknown;
|
|
556
|
+
};
|
|
557
|
+
Array(value: any): value is unknown[];
|
|
558
|
+
function(value: any): value is Function & {
|
|
559
|
+
[key: string]: unknown;
|
|
560
|
+
[key: number]: unknown;
|
|
561
|
+
[key: symbol]: unknown;
|
|
562
|
+
};
|
|
563
|
+
Function(value: any): value is Function & {
|
|
564
|
+
[key: string]: unknown;
|
|
565
|
+
[key: number]: unknown;
|
|
566
|
+
[key: symbol]: unknown;
|
|
567
|
+
};
|
|
568
|
+
tagged(value: any, tag: string): boolean;
|
|
569
|
+
instanceOf<T>(value: any, klass: new (...args: any) => T): value is T;
|
|
570
|
+
Error(value: any): value is Error;
|
|
571
|
+
Infinity(value: any): value is number;
|
|
572
|
+
NegativeInfinity(value: any): value is number;
|
|
573
|
+
NaN(value: any): value is number;
|
|
574
|
+
Date(value: any): value is Date;
|
|
575
|
+
RegExp(value: any): value is RegExp;
|
|
576
|
+
Map(value: any): value is Map<unknown, unknown>;
|
|
577
|
+
Set(value: any): value is Set<unknown>;
|
|
578
|
+
WeakMap(value: any): value is Map<unknown, unknown>;
|
|
579
|
+
WeakSet(value: any): value is Set<unknown>;
|
|
580
|
+
ArrayBuffer(value: any): value is ArrayBuffer;
|
|
581
|
+
SharedArrayBuffer(value: any): value is SharedArrayBuffer;
|
|
582
|
+
DataView(value: any): value is DataView;
|
|
583
|
+
TypedArray(value: any): value is TypedArray;
|
|
584
|
+
Int8Array(value: any): value is Int8Array;
|
|
585
|
+
Uint8Array(value: any): value is Uint8Array;
|
|
586
|
+
Uint8ClampedArray(value: any): value is Uint8ClampedArray;
|
|
587
|
+
Int16Array(value: any): value is Int16Array;
|
|
588
|
+
Uint16Array(value: any): value is Uint16Array;
|
|
589
|
+
Int32Array(value: any): value is Int32Array;
|
|
590
|
+
Uint32Array(value: any): value is Uint32Array;
|
|
591
|
+
Float32Array(value: any): value is Float32Array;
|
|
592
|
+
Float64Array(value: any): value is Float64Array;
|
|
593
|
+
Promise(value: any): value is Promise<unknown>;
|
|
594
|
+
Generator(value: any): value is Generator<unknown, any, unknown>;
|
|
595
|
+
GeneratorFunction(value: any): value is GeneratorFunction;
|
|
596
|
+
AsyncFunction(value: any): value is ((...args: any) => Promise<unknown>) & {
|
|
597
|
+
[key: string]: unknown;
|
|
598
|
+
[key: number]: unknown;
|
|
599
|
+
[key: symbol]: unknown;
|
|
600
|
+
};
|
|
601
|
+
AsyncGenerator(value: any): value is AsyncGenerator<unknown, any, unknown>;
|
|
602
|
+
AsyncGeneratorFunction(value: any): value is AsyncGeneratorFunction;
|
|
603
|
+
|
|
604
|
+
FILE(value: any): value is FILE;
|
|
605
|
+
|
|
606
|
+
JSX: {
|
|
607
|
+
/** Returns whether `value` is a JSX Element object as created via JSX syntax. */
|
|
608
|
+
Element(value: any): value is JSX.Element;
|
|
609
|
+
/** Returns whether `value` is a JSX fragment element as created via JSX syntax. */
|
|
610
|
+
Fragment(value: any): value is JSX.Fragment;
|
|
611
|
+
};
|
|
612
|
+
};
|
|
613
|
+
|
|
614
|
+
/**
|
|
615
|
+
* The data source of a pipe operation; either an in-memory object, or a
|
|
616
|
+
* file stream.
|
|
617
|
+
*
|
|
618
|
+
* - Use `maxLength` to limit how much data to read.
|
|
619
|
+
* - Use `until` to stop reading once a certain byte or character has been
|
|
620
|
+
* read.
|
|
621
|
+
* - Use `path` or `fd` to open a file.
|
|
622
|
+
*/
|
|
623
|
+
declare type PipeSource =
|
|
624
|
+
| { data: string; maxLength?: number; until?: string | byte }
|
|
625
|
+
| ArrayBuffer
|
|
626
|
+
| { data: ArrayBuffer; maxLength?: number; until?: string | byte }
|
|
627
|
+
| SharedArrayBuffer
|
|
628
|
+
| { data: SharedArrayBuffer; maxLength?: number; until?: string | byte }
|
|
629
|
+
| TypedArray
|
|
630
|
+
| { data: TypedArray; maxLength?: number; until?: string | byte }
|
|
631
|
+
| DataView
|
|
632
|
+
| { data: DataView; maxLength?: number; until?: string | byte }
|
|
633
|
+
| FILE
|
|
634
|
+
| {
|
|
635
|
+
data: FILE;
|
|
636
|
+
maxLength?: number;
|
|
637
|
+
until?: string | byte;
|
|
638
|
+
}
|
|
639
|
+
| { path: string; maxLength?: number; until?: string | byte }
|
|
640
|
+
| { fd: number; maxLength?: number; until?: string | byte };
|
|
641
|
+
|
|
642
|
+
/**
|
|
643
|
+
* The target destination of a pipe operation; either an in-memory object, or a
|
|
644
|
+
* file stream.
|
|
645
|
+
*
|
|
646
|
+
* - Use `intoExisting` to put data into an existing object or file handle.
|
|
647
|
+
* - Use `intoNew` to put data into a new object.
|
|
648
|
+
* - Use `path` or `fd` to create a new file handle and put data into it.
|
|
649
|
+
*/
|
|
650
|
+
export type PipeDestination =
|
|
651
|
+
| ArrayBuffer
|
|
652
|
+
| SharedArrayBuffer
|
|
653
|
+
| DataView
|
|
654
|
+
| TypedArray
|
|
655
|
+
| FILE
|
|
656
|
+
| ArrayBufferConstructor
|
|
657
|
+
| SharedArrayBufferConstructor
|
|
658
|
+
| DataViewConstructor
|
|
659
|
+
| TypedArrayConstructor
|
|
660
|
+
| StringConstructor
|
|
661
|
+
| { path: string }
|
|
662
|
+
| { fd: number };
|
|
663
|
+
|
|
664
|
+
/**
|
|
665
|
+
* Copy data from one source into the given target. Returns the number of bytes
|
|
666
|
+
* written, and the target that data was written into.
|
|
667
|
+
*/
|
|
668
|
+
declare function pipe<Dest extends PipeDestination>(
|
|
669
|
+
from: PipeSource,
|
|
670
|
+
to: Dest
|
|
671
|
+
): {
|
|
672
|
+
bytesTransferred: number;
|
|
673
|
+
target: Dest extends
|
|
674
|
+
| ArrayBuffer
|
|
675
|
+
| SharedArrayBuffer
|
|
676
|
+
| DataView
|
|
677
|
+
| FILE
|
|
678
|
+
| { path: string }
|
|
679
|
+
| { fd: number }
|
|
680
|
+
? Dest
|
|
681
|
+
: Dest extends
|
|
682
|
+
| ArrayBufferConstructor
|
|
683
|
+
| SharedArrayBufferConstructor
|
|
684
|
+
| DataViewConstructor
|
|
685
|
+
| TypedArrayConstructor
|
|
686
|
+
| DataViewConstructor
|
|
687
|
+
? Dest["prototype"]
|
|
688
|
+
: Dest extends StringConstructor
|
|
689
|
+
? string
|
|
690
|
+
: never;
|
|
691
|
+
};
|
|
692
|
+
|
|
693
|
+
/**
|
|
694
|
+
* Returns the absolute path to the root folder of the git/hg repo.
|
|
695
|
+
*
|
|
696
|
+
* This is done by running `git rev-parse --show-toplevel` and `hg root`.
|
|
697
|
+
*
|
|
698
|
+
* If `relativeTo` is provided, the git and hg commands will be executed in
|
|
699
|
+
* that folder instead of in `pwd()`.
|
|
700
|
+
*/
|
|
701
|
+
declare function repoRoot(relativeTo?: string): string;
|
|
702
|
+
|
|
703
|
+
/**
|
|
704
|
+
* Returns whether the provided path is ignored by git.
|
|
705
|
+
*/
|
|
706
|
+
declare function isGitignored(path: string): boolean;
|
|
707
|
+
|
|
708
|
+
/**
|
|
709
|
+
* Configures the default value of `trace` in functions which receive `trace`
|
|
710
|
+
* as an option.
|
|
711
|
+
*
|
|
712
|
+
* - If called with `true`, the default value of `trace` in all functions which
|
|
713
|
+
* receive a `trace` option will be changed to `console.error`.
|
|
714
|
+
* - If called with `false`, the default value of `trace` in all functions which
|
|
715
|
+
* receive a `trace` option will be changed to `undefined`.
|
|
716
|
+
* - If called with any other value, the provided value will be used as the
|
|
717
|
+
* default value of `trace` in all functions which receive a `trace` option.
|
|
718
|
+
*
|
|
719
|
+
* If you would like to make your own functions use the default value of
|
|
720
|
+
* `trace` as set by this function (in order to get the same behavior as
|
|
721
|
+
* yavascript API functions which do so), call `traceAll.getDefaultTrace()` to
|
|
722
|
+
* get the value which should be used as the default value.
|
|
723
|
+
*/
|
|
724
|
+
declare const traceAll: ((
|
|
725
|
+
trace: boolean | undefined | ((...args: Array<any>) => void)
|
|
726
|
+
) => void) & {
|
|
727
|
+
getDefaultTrace(): ((...args: Array<any>) => void) | undefined;
|
|
728
|
+
};
|
|
729
|
+
|
|
730
|
+
declare namespace JSX {
|
|
731
|
+
/**
|
|
732
|
+
* A string containing the expression that should be called to create JSX
|
|
733
|
+
* elements.
|
|
734
|
+
*
|
|
735
|
+
* Defaults to "JSX.createElement".
|
|
736
|
+
*
|
|
737
|
+
* If changed, any JSX code loaded afterwards will use a different
|
|
738
|
+
* expression.
|
|
739
|
+
*
|
|
740
|
+
* Note that if you change this, you need to verify that the following
|
|
741
|
+
* expression always evaluates to `true` (by changing {@link is.JSX.Element}
|
|
742
|
+
* and {@link is.JSX.Fragment}):
|
|
743
|
+
* ```jsx
|
|
744
|
+
* is.JSX.Element(<a />) && is.JSX.Fragment(<></>)
|
|
745
|
+
* ```
|
|
746
|
+
*
|
|
747
|
+
* Failure to uphold this guarantee indicates a bug.
|
|
748
|
+
*/
|
|
749
|
+
export let pragma: string;
|
|
750
|
+
|
|
751
|
+
/**
|
|
752
|
+
* A string containing the expression that should be used as the first
|
|
753
|
+
* parameter when creating JSX fragment elements.
|
|
754
|
+
*
|
|
755
|
+
* Defaults to "JSX.Fragment".
|
|
756
|
+
*
|
|
757
|
+
* If changed, any JSX code loaded afterwards will use a different
|
|
758
|
+
* expression.
|
|
759
|
+
*
|
|
760
|
+
* Note that if you change this, you need to verify that the following
|
|
761
|
+
* expression always evaluates to `true` (by changing {@link is.JSX.Element}
|
|
762
|
+
* and {@link is.JSX.Fragment}):
|
|
763
|
+
* ```jsx
|
|
764
|
+
* is.JSX.Element(<a />) && is.JSX.Fragment(<></>)
|
|
765
|
+
* ```
|
|
766
|
+
*
|
|
767
|
+
* Failure to uphold this guarantee indicates a bug.
|
|
768
|
+
*/
|
|
769
|
+
export let pragmaFrag: string;
|
|
770
|
+
|
|
771
|
+
export const Element: unique symbol;
|
|
772
|
+
|
|
773
|
+
export interface Element<
|
|
774
|
+
Props = { [key: string | symbol | number]: any },
|
|
775
|
+
Type = any
|
|
776
|
+
> {
|
|
777
|
+
$$typeof: typeof Element;
|
|
778
|
+
type: Type;
|
|
779
|
+
props: Props;
|
|
780
|
+
key: string | number | null;
|
|
781
|
+
}
|
|
782
|
+
|
|
783
|
+
/**
|
|
784
|
+
* The value which gets passed into the JSX element constructor (as
|
|
785
|
+
* determined by {@link JSX.pragma}) when JSX fragment syntax is used (unless
|
|
786
|
+
* {@link JSX.pragmaFrag} is changed).
|
|
787
|
+
*/
|
|
788
|
+
export const Fragment: unique symbol;
|
|
789
|
+
|
|
790
|
+
export type Fragment = Element<{}, typeof Fragment>;
|
|
791
|
+
|
|
792
|
+
/**
|
|
793
|
+
* The JSX element constructor, which gets invoked whenever JSX syntax is
|
|
794
|
+
* used (unless {@link JSX.pragma} is changed).
|
|
795
|
+
*/
|
|
796
|
+
export const createElement: {
|
|
797
|
+
<Type extends string | typeof Fragment | ((...args: any) => any)>(
|
|
798
|
+
type: Type
|
|
799
|
+
): Element<{}, Type>;
|
|
800
|
+
<
|
|
801
|
+
Type extends string | typeof Fragment | ((...args: any) => any),
|
|
802
|
+
Props extends { [key: string | number | symbol]: any }
|
|
803
|
+
>(
|
|
804
|
+
type: Type,
|
|
805
|
+
props: Props
|
|
806
|
+
): Element<Props, Type>;
|
|
807
|
+
|
|
808
|
+
<
|
|
809
|
+
Type extends string | typeof Fragment | ((...args: any) => any),
|
|
810
|
+
Props extends { [key: string | number | symbol]: any },
|
|
811
|
+
Children extends Array<any>
|
|
812
|
+
>(
|
|
813
|
+
type: Type,
|
|
814
|
+
props: Props,
|
|
815
|
+
...children: Children
|
|
816
|
+
): Element<Props & { children: Children }, Type>;
|
|
817
|
+
|
|
818
|
+
<
|
|
819
|
+
Type extends string | typeof Fragment | ((...args: any) => any),
|
|
820
|
+
Children extends Array<any>
|
|
821
|
+
>(
|
|
822
|
+
type: Type,
|
|
823
|
+
...children: Children
|
|
824
|
+
): Element<{ children: Children }, Type>;
|
|
825
|
+
};
|
|
826
|
+
}
|
|
827
|
+
|
|
828
|
+
// prettier-ignore
|
|
829
|
+
/** Any integer in the range [0, 255]. */
|
|
830
|
+
declare type byte =
|
|
831
|
+
| 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15
|
|
832
|
+
| 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31
|
|
833
|
+
| 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47
|
|
834
|
+
| 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63
|
|
835
|
+
| 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79
|
|
836
|
+
| 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95
|
|
837
|
+
| 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111
|
|
838
|
+
| 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127
|
|
839
|
+
| 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143
|
|
840
|
+
| 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159
|
|
841
|
+
| 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175
|
|
842
|
+
| 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191
|
|
843
|
+
| 192 | 193 | 194 | 195 | 196 | 197 | 198 | 199 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207
|
|
844
|
+
| 208 | 209 | 210 | 211 | 212 | 213 | 214 | 215 | 216 | 217 | 218 | 219 | 220 | 221 | 222 | 223
|
|
845
|
+
| 224 | 225 | 226 | 227 | 228 | 229 | 230 | 231 | 232 | 233 | 234 | 235 | 236 | 237 | 238 | 239
|
|
846
|
+
| 240 | 241 | 242 | 243 | 244 | 245 | 246 | 247 | 248 | 249 | 250 | 251 | 252 | 253 | 254 | 255;
|
|
847
|
+
|
|
848
|
+
// Convenience aliases to provide parity with TypeScript types.
|
|
849
|
+
declare var number: NumberConstructor;
|
|
850
|
+
declare var string: StringConstructor;
|
|
851
|
+
declare var boolean: BooleanConstructor;
|
|
852
|
+
declare var bigint: BigIntConstructor;
|
|
853
|
+
declare var symbol: SymbolConstructor;
|
|
854
|
+
|
|
855
|
+
// ==========================================
|
|
536
856
|
// ------------------------------------------
|
|
537
857
|
// QuickJS APIs, which YavaScript builds upon
|
|
538
858
|
// ------------------------------------------
|
|
539
|
-
|
|
859
|
+
// ==========================================
|
|
540
860
|
// Definitions of the globals and modules added by quickjs-libc
|
|
541
861
|
|
|
542
862
|
/**
|
|
@@ -569,6 +889,91 @@ declare var console: {
|
|
|
569
889
|
info: typeof print;
|
|
570
890
|
};
|
|
571
891
|
|
|
892
|
+
/** An object representing a file handle. */
|
|
893
|
+
declare interface FILE {
|
|
894
|
+
/**
|
|
895
|
+
* Human-readable description of where this FILE points.
|
|
896
|
+
*
|
|
897
|
+
* If `target` is a number, the FILE was opened with fdopen, and `target` is
|
|
898
|
+
* the fd. Otherwise, `target` will be an arbitrary string that describes the
|
|
899
|
+
* file; it may be the absolute path to the file, the relative path to the
|
|
900
|
+
* file at time of its opening, or some other string like "stdin" or
|
|
901
|
+
* "tmpfile".
|
|
902
|
+
*
|
|
903
|
+
* You should *not* use this property for anything other than logging and
|
|
904
|
+
* debugging. It is *only* provided for debugging and/or troubleshooting
|
|
905
|
+
* purposes. The value of this property could change at any time when
|
|
906
|
+
* upgrading yavascript, even if upgrading by a minor or patch release.
|
|
907
|
+
*/
|
|
908
|
+
target: string | number;
|
|
909
|
+
|
|
910
|
+
/**
|
|
911
|
+
* Close the file handle. Note that for files other than stdin/stdout/stderr,
|
|
912
|
+
* the file will be closed automatically when the `FILE` object is
|
|
913
|
+
* garbage-collected.
|
|
914
|
+
*/
|
|
915
|
+
close(): void;
|
|
916
|
+
|
|
917
|
+
/** Outputs the string with the UTF-8 encoding. */
|
|
918
|
+
puts(str: string): void;
|
|
919
|
+
|
|
920
|
+
/**
|
|
921
|
+
* Formatted printf.
|
|
922
|
+
*
|
|
923
|
+
* 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.
|
|
924
|
+
*/
|
|
925
|
+
printf(fmt: string, ...args: Array<any>): void;
|
|
926
|
+
|
|
927
|
+
/** Flush the buffered file. Wrapper for C `fflush`. */
|
|
928
|
+
flush(): void;
|
|
929
|
+
|
|
930
|
+
/** Sync the buffered file to disk. Wrapper for C `fsync`. */
|
|
931
|
+
sync(): void;
|
|
932
|
+
|
|
933
|
+
/**
|
|
934
|
+
* Seek to a given file position (whence is `std.SEEK_*`).
|
|
935
|
+
*
|
|
936
|
+
* `offset` can be a number or a bigint.
|
|
937
|
+
*/
|
|
938
|
+
seek(offset: number, whence: number): void;
|
|
939
|
+
|
|
940
|
+
/** Return the current file position. */
|
|
941
|
+
tell(): number;
|
|
942
|
+
|
|
943
|
+
/** Return the current file position as a bigint. */
|
|
944
|
+
tello(): BigInt;
|
|
945
|
+
|
|
946
|
+
/** Return true if end of file. */
|
|
947
|
+
eof(): boolean;
|
|
948
|
+
|
|
949
|
+
/** Return the associated OS handle. */
|
|
950
|
+
fileno(): number;
|
|
951
|
+
|
|
952
|
+
/** Read `length` bytes from the file to the ArrayBuffer `buffer` at byte position `position` (wrapper to the libc `fread`). Returns the number of bytes read, or `0` if the end of the file has been reached. */
|
|
953
|
+
read(buffer: ArrayBuffer, position: number, length: number): number;
|
|
954
|
+
|
|
955
|
+
/** Write `length` bytes from the ArrayBuffer `buffer` at byte position `position` into the file (wrapper to the libc `fwrite`). Returns the number of bytes written. */
|
|
956
|
+
write(buffer: ArrayBuffer, position: number, length: number): number;
|
|
957
|
+
|
|
958
|
+
/**
|
|
959
|
+
* Return the next line from the file, assuming UTF-8 encoding, excluding the trailing line feed or EOF.
|
|
960
|
+
*
|
|
961
|
+
* If the end of the file has been reached, then `null` will be returned instead of a string.
|
|
962
|
+
*
|
|
963
|
+
* Note: Although the trailing line feed has been removed, a carriage return (`\r`) may still be present.
|
|
964
|
+
*/
|
|
965
|
+
getline(): string | null;
|
|
966
|
+
|
|
967
|
+
/** Read `maxSize` bytes from the file and return them as a string assuming UTF-8 encoding. If `maxSize` is not present, the file is read up its end. */
|
|
968
|
+
readAsString(maxSize?: number): string;
|
|
969
|
+
|
|
970
|
+
/** Return the next byte from the file. Return -1 if the end of file is reached. */
|
|
971
|
+
getByte(): number;
|
|
972
|
+
|
|
973
|
+
/** Write one byte to the file. */
|
|
974
|
+
putByte(value: number): void;
|
|
975
|
+
}
|
|
976
|
+
|
|
572
977
|
declare module "std" {
|
|
573
978
|
/**
|
|
574
979
|
* Exit the process with the provided status code.
|
|
@@ -626,6 +1031,14 @@ declare module "std" {
|
|
|
626
1031
|
*/
|
|
627
1032
|
export function getFileNameFromStack(stackLevels: number): string;
|
|
628
1033
|
|
|
1034
|
+
/**
|
|
1035
|
+
* Return a boolean indicating whether the provided value is a FILE object.
|
|
1036
|
+
*
|
|
1037
|
+
* @param value - The value to check.
|
|
1038
|
+
* @returns Whether the value was a `FILE` or not.
|
|
1039
|
+
*/
|
|
1040
|
+
export function isFILE(value: any): boolean;
|
|
1041
|
+
|
|
629
1042
|
/**
|
|
630
1043
|
* Open a file (wrapper to the libc `fopen()`).
|
|
631
1044
|
* Return the FILE object.
|
|
@@ -825,68 +1238,6 @@ declare module "std" {
|
|
|
825
1238
|
* - octal (0o prefix) and hexadecimal (0x prefix) numbers
|
|
826
1239
|
*/
|
|
827
1240
|
export function parseExtJSON(str: string): any;
|
|
828
|
-
|
|
829
|
-
/** An object representing a file handle. */
|
|
830
|
-
export class FILE {
|
|
831
|
-
/** Close the file. */
|
|
832
|
-
close(): void;
|
|
833
|
-
|
|
834
|
-
/** Outputs the string with the UTF-8 encoding. */
|
|
835
|
-
puts(str: string): void;
|
|
836
|
-
|
|
837
|
-
/**
|
|
838
|
-
* Formatted printf.
|
|
839
|
-
*
|
|
840
|
-
* 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.
|
|
841
|
-
*/
|
|
842
|
-
printf(fmt: string, ...args: Array<any>): void;
|
|
843
|
-
|
|
844
|
-
/** Flush the buffered file. Wrapper for C `fflush`. */
|
|
845
|
-
flush(): void;
|
|
846
|
-
|
|
847
|
-
/** Sync the buffered file to disk. Wrapper for C `fsync`. */
|
|
848
|
-
sync(): void;
|
|
849
|
-
|
|
850
|
-
/**
|
|
851
|
-
* Seek to a given file position (whence is `std.SEEK_*`).
|
|
852
|
-
*
|
|
853
|
-
* `offset` can be a number or a bigint.
|
|
854
|
-
*/
|
|
855
|
-
seek(
|
|
856
|
-
offset: number,
|
|
857
|
-
whence: typeof SEEK_SET | typeof SEEK_CUR | typeof SEEK_END
|
|
858
|
-
): void;
|
|
859
|
-
|
|
860
|
-
/** Return the current file position. */
|
|
861
|
-
tell(): number;
|
|
862
|
-
|
|
863
|
-
/** Return the current file position as a bigint. */
|
|
864
|
-
tello(): BigInt;
|
|
865
|
-
|
|
866
|
-
/** Return true if end of file. */
|
|
867
|
-
eof(): boolean;
|
|
868
|
-
|
|
869
|
-
/** Return the associated OS handle. */
|
|
870
|
-
fileno(): number;
|
|
871
|
-
|
|
872
|
-
/** Read `length` bytes from the file to the ArrayBuffer `buffer` at byte position `position` (wrapper to the libc `fread`). Returns the number of bytes read, or `0` if the end of the file has been reached. */
|
|
873
|
-
read(buffer: ArrayBuffer, position: number, length: number): number;
|
|
874
|
-
|
|
875
|
-
/** Write `length` bytes from the ArrayBuffer `buffer` at byte position `position` into the file (wrapper to the libc `fwrite`). Returns the number of bytes written. */
|
|
876
|
-
write(buffer: ArrayBuffer, position: number, length: number): number;
|
|
877
|
-
|
|
878
|
-
/** Return the next line from the file, assuming UTF-8 encoding, excluding the trailing line feed. */
|
|
879
|
-
getline(): string;
|
|
880
|
-
|
|
881
|
-
/** Read `maxSize` bytes from the file and return them as a string assuming UTF-8 encoding. If `maxSize` is not present, the file is read up its end. */
|
|
882
|
-
readAsString(maxSize?: number): string;
|
|
883
|
-
|
|
884
|
-
/** Return the next byte from the file. Return -1 if the end of file is reached. */
|
|
885
|
-
getByte(): number;
|
|
886
|
-
|
|
887
|
-
/** Write one byte to the file. */
|
|
888
|
-
putByte(value: number): void;
|
|
889
|
-
}
|
|
890
1241
|
}
|
|
891
1242
|
|
|
892
1243
|
declare module "os" {
|
|
@@ -1151,6 +1502,24 @@ declare module "os" {
|
|
|
1151
1502
|
|
|
1152
1503
|
/** Constant for the `options` argument of `waitpid`. */
|
|
1153
1504
|
export var WNOHANG: number;
|
|
1505
|
+
/** Constant for the `options` argument of `waitpid`. */
|
|
1506
|
+
export var WUNTRACED: number;
|
|
1507
|
+
|
|
1508
|
+
/** Function to be used to interpret the 'status' return value of `waitpid`. */
|
|
1509
|
+
export function WEXITSTATUS(status: number): number;
|
|
1510
|
+
/** Function to be used to interpret the 'status' return value of `waitpid`. */
|
|
1511
|
+
export function WTERMSIG(status: number): number;
|
|
1512
|
+
/** Function to be used to interpret the 'status' return value of `waitpid`. */
|
|
1513
|
+
export function WSTOPSIG(status: number): number;
|
|
1514
|
+
|
|
1515
|
+
/** Function to be used to interpret the 'status' return value of `waitpid`. */
|
|
1516
|
+
export function WIFEXITED(status: number): boolean;
|
|
1517
|
+
/** Function to be used to interpret the 'status' return value of `waitpid`. */
|
|
1518
|
+
export function WIFSIGNALED(status: number): boolean;
|
|
1519
|
+
/** Function to be used to interpret the 'status' return value of `waitpid`. */
|
|
1520
|
+
export function WIFSTOPPED(status: number): boolean;
|
|
1521
|
+
/** Function to be used to interpret the 'status' return value of `waitpid`. */
|
|
1522
|
+
export function WIFCONTINUED(status: number): boolean;
|
|
1154
1523
|
|
|
1155
1524
|
/** `dup` Unix system call. */
|
|
1156
1525
|
export function dup(fd: number): number;
|
|
@@ -1368,3 +1737,118 @@ declare interface InspectFunction {
|
|
|
1368
1737
|
*/
|
|
1369
1738
|
declare var inspect: InspectFunction;
|
|
1370
1739
|
|
|
1740
|
+
/**
|
|
1741
|
+
* A class which represents a module namespace object. Note, however, that
|
|
1742
|
+
* instances of this class cannot be constructed manually, and must instead be
|
|
1743
|
+
* obtained from `import * as`, `import()`, `std.importModule`, or `require`.
|
|
1744
|
+
*
|
|
1745
|
+
* The static properties on `Module` let you configure the module loader
|
|
1746
|
+
* (import/export/require). You can use these properties to add support for
|
|
1747
|
+
* importing new filetypes.
|
|
1748
|
+
*/
|
|
1749
|
+
declare class Module {
|
|
1750
|
+
/** A module namespace object has arbitrary exports. */
|
|
1751
|
+
[key: string | number | symbol]: any;
|
|
1752
|
+
|
|
1753
|
+
/**
|
|
1754
|
+
* Module objects are not constructable.
|
|
1755
|
+
*
|
|
1756
|
+
* You must instead obtain them using import or require.
|
|
1757
|
+
*/
|
|
1758
|
+
private constructor();
|
|
1759
|
+
|
|
1760
|
+
/**
|
|
1761
|
+
* Returns true if `target` is a module namespace object.
|
|
1762
|
+
*/
|
|
1763
|
+
static [Symbol.hasInstance](target: any): target is Module;
|
|
1764
|
+
|
|
1765
|
+
/**
|
|
1766
|
+
* A list of filetype extensions that may be omitted from an import specifier
|
|
1767
|
+
* string.
|
|
1768
|
+
*
|
|
1769
|
+
* Defaults to `[".js"]`. You can add more strings to this array to
|
|
1770
|
+
* make the engine search for additional files when resolving a
|
|
1771
|
+
* require/import.
|
|
1772
|
+
*
|
|
1773
|
+
* See the doc comment on {@link require} for more information.
|
|
1774
|
+
*
|
|
1775
|
+
* NOTE: If you add a new extension to this array, you will likely also want
|
|
1776
|
+
* to add to {@link Module.compilers}.
|
|
1777
|
+
*/
|
|
1778
|
+
static searchExtensions: Array<string>;
|
|
1779
|
+
|
|
1780
|
+
/**
|
|
1781
|
+
* User-defined functions which will handle getting the JavaScript code
|
|
1782
|
+
* associated with a module.
|
|
1783
|
+
*
|
|
1784
|
+
* The key for each property in this object should be a file extension
|
|
1785
|
+
* string with a leading dot, eg `".jsx"`. The value for each property should
|
|
1786
|
+
* be a function which receives the filepath to a module, and should
|
|
1787
|
+
* synchronously load that file, then return a string containing JavaScript
|
|
1788
|
+
* code that corresponds to that module. In many cases, these functions will
|
|
1789
|
+
* compile the contents of the file from one format into JavaScript.
|
|
1790
|
+
*
|
|
1791
|
+
* By adding to this object, you can make it possible to import non-js
|
|
1792
|
+
* filetypes; compile-to-JS languages like JSX, TypeScript, and CoffeeScript
|
|
1793
|
+
* can be compiled at import time, and asset files like .txt files or .png
|
|
1794
|
+
* files can be converted into an appropriate data structure at import time.
|
|
1795
|
+
*
|
|
1796
|
+
* As an example, to make it possible to import .txt files, you might do:
|
|
1797
|
+
* ```js
|
|
1798
|
+
* import * as std from "std";
|
|
1799
|
+
*
|
|
1800
|
+
* Module.compilers[".txt"] = (filename) => {
|
|
1801
|
+
* const content = std.loadFile(filename);
|
|
1802
|
+
* return `export default ${JSON.stringify(content)}`;
|
|
1803
|
+
* }
|
|
1804
|
+
* ```
|
|
1805
|
+
* (leveraging `JSON.stringify`'s ability to escape quotes).
|
|
1806
|
+
*
|
|
1807
|
+
* Then, later in your code, you can do:
|
|
1808
|
+
* ```js
|
|
1809
|
+
* import names from "./names.txt";
|
|
1810
|
+
* ```
|
|
1811
|
+
*
|
|
1812
|
+
* And `names` will be a string containing the contents of names.txt.
|
|
1813
|
+
*
|
|
1814
|
+
* NOTE: When adding to this object, you may also wish to add to
|
|
1815
|
+
* {@link Module.searchExtensions}.
|
|
1816
|
+
*/
|
|
1817
|
+
static compilers: {
|
|
1818
|
+
[extensionWithDot: string]: (filename: string) => string;
|
|
1819
|
+
};
|
|
1820
|
+
}
|
|
1821
|
+
|
|
1822
|
+
/**
|
|
1823
|
+
* Synchronously import a module.
|
|
1824
|
+
*
|
|
1825
|
+
* `source` will be resolved relative to the calling file.
|
|
1826
|
+
*
|
|
1827
|
+
* If `source` does not have a file extension, and a file without an extension
|
|
1828
|
+
* cannot be found, the engine will check for files with the extensions in
|
|
1829
|
+
* {@link Module.searchExtensions}, and use one of those if present. This
|
|
1830
|
+
* behavior also happens when using normal `import` statements.
|
|
1831
|
+
*
|
|
1832
|
+
* For example, if you write:
|
|
1833
|
+
*
|
|
1834
|
+
* ```js
|
|
1835
|
+
* import something from "./somewhere";
|
|
1836
|
+
* ```
|
|
1837
|
+
*
|
|
1838
|
+
* but there's no file named `somewhere` in the same directory as the file
|
|
1839
|
+
* where that import appears, and `Module.searchExtensions` is the default
|
|
1840
|
+
* value:
|
|
1841
|
+
*
|
|
1842
|
+
* ```js
|
|
1843
|
+
* [".js"]
|
|
1844
|
+
* ```
|
|
1845
|
+
*
|
|
1846
|
+
* then the engine will look for `somewhere.js`. If that doesn't exist, the
|
|
1847
|
+
* engine will look for `somewhere/index.js`. If *that* doesn't exist, an error
|
|
1848
|
+
* will be thrown.
|
|
1849
|
+
*
|
|
1850
|
+
* If you add more extensions to `Module.searchExtensions`, then the engine
|
|
1851
|
+
* will use those, too. It will search in the same order as the strings appear
|
|
1852
|
+
* in the `Module.searchExtensions` array.
|
|
1853
|
+
*/
|
|
1854
|
+
declare var require: (source: string) => Module;
|