yavascript 0.0.2 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,43 @@
1
+ # yavascript
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
+ YavaScript is a bash-like script runner which is distributed as a single
6
+ statically-linked binary. Scripts are written in JavaScript. There are global
7
+ APIs available for all the things you'd normally want to do in a bash script,
8
+ such as:
9
+
10
+ - Running programs
11
+ - Accessing environment variables
12
+ - Reading and writing file contents
13
+ - Checking if files/folders exist
14
+ - Removing files/folders
15
+ - Reading and changing the current working directory
16
+ - Using globs to get large lists of files
17
+ - Printing stylized text to the terminal
18
+
19
+ Additionally, since it's JavaScript, you get some other features that are
20
+ either not present in bash or are cumbersome to use in bash, namely:
21
+
22
+ - Arrays (lists) and Objects (key/value dictionaries)
23
+ - Working with path strings
24
+ - Working with JSON
25
+ - Cross-file import/export using ECMAScript Modules
26
+ - Splitting strings on delimeters
27
+ - Pretty-printing of objects
28
+ - Getting the path to the currently-running script (via import.meta.url or `__filename`)
29
+ - Getting the absolute path to the root folder of the current git/mercurial repo (repoRoot function)
30
+
31
+ To view the APIs, consult the file yavascript.d.ts which was distributed with
32
+ this program, or online at https://github.com/suchipi/yavascript/blob/main/yavascript.d.ts.
33
+ This file contains TypeScript type definitions which can be given to your IDE
34
+ to assist you when writing scripts.
35
+
36
+ YavaScript is powered by a fork of the QuickJS JavaScript Engine, originally
37
+ written by Fabrice Bellard. QuickJS is a small, fast JavaScript engine
38
+ supporting the ES2020 specification.
39
+
40
+ - Original QuickJS engine: https://bellard.org/quickjs/
41
+ - The fork we use: https://github.com/suchipi/quickjs/
42
+
43
+ YavaScript is written with <3 by Lily Scott.
Binary file
Binary file
Binary file
@@ -2,9 +2,25 @@ var path = require("path");
2
2
 
3
3
  var binaryPath;
4
4
  if (process.platform === "win32") {
5
- binaryPath = path.resolve(__dirname, "..", "bin", "win32", "yavascript.exe");
5
+ binaryPath = path.resolve(
6
+ __dirname,
7
+ "..",
8
+ "bin",
9
+ "windows",
10
+ "yavascript.exe"
11
+ );
6
12
  } else if (process.platform === "darwin") {
7
- binaryPath = path.resolve(__dirname, "..", "bin", "darwin", "yavascript");
13
+ if (process.arch.startsWith("arm")) {
14
+ binaryPath = path.resolve(
15
+ __dirname,
16
+ "..",
17
+ "bin",
18
+ "darwin-arm",
19
+ "yavascript"
20
+ );
21
+ } else {
22
+ binaryPath = path.resolve(__dirname, "..", "bin", "darwin", "yavascript");
23
+ }
8
24
  } else if (process.platform === "linux") {
9
25
  binaryPath = path.resolve(__dirname, "..", "bin", "linux", "yavascript");
10
26
  } else {
package/package.json CHANGED
@@ -1,9 +1,10 @@
1
1
  {
2
2
  "name": "yavascript",
3
- "version": "0.0.2",
3
+ "version": "0.0.3",
4
4
  "main": "lib/index.js",
5
5
  "bin": "lib/cli.js",
6
6
  "types": "yavascript.d.ts",
7
7
  "author": "Lily Scott <me@suchipi.com>",
8
- "license": "MIT"
8
+ "license": "MIT",
9
+ "repository": "suchipi/yavascript"
9
10
  }
package/yavascript.d.ts CHANGED
@@ -3,8 +3,28 @@
3
3
  // YavaScript APIs
4
4
  // ---------------
5
5
 
6
+ /** The name of the current file (whether script or module). Alias for `os.realpath(std.getFileNameFromStack())`. */
7
+ declare const __filename: string;
8
+
9
+ /** The name of the directory the current file is inside of. */
10
+ declare const __dirname: string;
11
+
12
+ /**
13
+ * An object representing the process's environment variables. You can read
14
+ * from it to read environment variables, write into it to set environment
15
+ * variables, and/or delete properties from it to unset environment variables.
16
+ * Any value you write will be coerced into a string.
17
+ */
6
18
  declare const env: { [key: string]: string | undefined };
7
19
 
20
+ type BaseExecOptions = {
21
+ /** Sets the current working directory for the child process. */
22
+ cwd?: string;
23
+
24
+ /** Sets environment variables within the process. */
25
+ env?: { [key: string | number]: string | number | boolean };
26
+ };
27
+
8
28
  interface Exec {
9
29
  (args: Array<string>): void;
10
30
 
@@ -12,7 +32,7 @@ interface Exec {
12
32
 
13
33
  (
14
34
  args: Array<string>,
15
- options: {
35
+ options: BaseExecOptions & {
16
36
  /**
17
37
  * Whether an Error should be thrown when the process exits with a nonzero
18
38
  * status code.
@@ -32,7 +52,7 @@ interface Exec {
32
52
 
33
53
  (
34
54
  args: Array<string>,
35
- options: {
55
+ options: BaseExecOptions & {
36
56
  /**
37
57
  * Whether an Error should be thrown when the process exits with a nonzero
38
58
  * status code.
@@ -52,7 +72,7 @@ interface Exec {
52
72
 
53
73
  (
54
74
  args: Array<string>,
55
- options: {
75
+ options: BaseExecOptions & {
56
76
  /**
57
77
  * Whether an Error should be thrown when the process exits with a nonzero
58
78
  * status code.
@@ -65,7 +85,7 @@ interface Exec {
65
85
 
66
86
  (
67
87
  args: Array<string>,
68
- options: {
88
+ options: BaseExecOptions & {
69
89
  /**
70
90
  * Whether an Error should be thrown when the process exits with a nonzero
71
91
  * status code.
@@ -85,7 +105,7 @@ interface Exec {
85
105
 
86
106
  (
87
107
  args: Array<string>,
88
- options: {
108
+ options: BaseExecOptions & {
89
109
  /**
90
110
  * If true, stdout and stderr will be collected into strings and returned
91
111
  * instead of being printed to the screen.
@@ -98,7 +118,7 @@ interface Exec {
98
118
 
99
119
  (
100
120
  args: Array<string>,
101
- options: {
121
+ options: BaseExecOptions & {
102
122
  /**
103
123
  * Whether an Error should be thrown when the process exits with a nonzero
104
124
  * status code.
@@ -114,11 +134,10 @@ interface Exec {
114
134
  /** Run a child process using the provided arguments. The first value in the arguments array is the program to run. */
115
135
  declare const exec: Exec;
116
136
 
117
- /** Alias for `exec(args, { captureOutput: true, failOnNonZeroStatus: false })` */
137
+ /** Alias for `exec(args, { captureOutput: true })` */
118
138
  declare function $(args: Array<string>): {
119
139
  stdout: string;
120
140
  stderr: string;
121
- status: number;
122
141
  };
123
142
 
124
143
  /** Read the contents of a file from disk, as a string. */
@@ -142,6 +161,69 @@ declare function cd(path: string): void;
142
161
  /** Return the process's current working directory. */
143
162
  declare function pwd(): string;
144
163
 
164
+ /** Removes the final component from a path string. */
165
+ declare function dirname(path: string): string;
166
+
167
+ /**
168
+ * The separator character the host operative system uses between path
169
+ * components, ie. the slashes in a filepath. On windows, it's a backslash, and
170
+ * on all other OSes, it's a forward slash.
171
+ */
172
+ declare const OS_PATH_SEPARATOR: "/" | "\\";
173
+
174
+ /**
175
+ * Create a path string from one or more path or path component strings.
176
+ *
177
+ * Trailing slashes and duplicate path separators will be removed. Any slashes
178
+ * or backslashes that do not match the requested path separator character
179
+ * (which defaults to {@link OS_PATH_SEPARATOR}) will be converted to the
180
+ * requested path separator. If multiple strings are passed, they will be
181
+ * joined together using the requested path separator.
182
+ *
183
+ * This function does not resolve `..` or `.`. Use {@link realpath} for that.
184
+ *
185
+ * To request a path separator other than {@link OS_PATH_SEPARATOR}, pass an
186
+ * object like `{ separator: "/" }` as the final argument to `makePath`.
187
+ *
188
+ * @param parts strings containing path components that should be present in
189
+ * the returned path string.
190
+ */
191
+ declare function makePath(
192
+ ...parts: Array<string | { separator: string }>
193
+ ): string;
194
+
195
+ /**
196
+ * Returns the absolute path to the root folder of the git/hg repo.
197
+ *
198
+ * This is done by running `git rev-parse --show-toplevel` and `hg root`.
199
+ *
200
+ * If `relativeTo` is provided, the git and hg commands will be executed in that
201
+ */
202
+ declare function repoRoot(relativeTo?: string): string;
203
+
204
+ /**
205
+ * Returns whether the provided path is ignored by git.
206
+ */
207
+ declare function isGitignored(path: string): boolean
208
+
209
+ /**
210
+ * Return the contents of a directory, as absolute paths. `.` and `..` are
211
+ * omitted.
212
+ *
213
+ * Use the `relativePaths` option to get relative paths instead (relative to
214
+ * the parent directory).
215
+ */
216
+ declare function ls(
217
+ dir?: string,
218
+ options?: { relativePaths?: boolean }
219
+ ): Array<string>;
220
+
221
+ /** Get the absolute path given a relative path. Symlinks are also resolved. */
222
+ declare function realpath(path: string): string;
223
+
224
+ /** Read a symlink. */
225
+ declare function readlink(path: string): string;
226
+
145
227
  /**
146
228
  * Search the filesystem for files matching the specified glob patterns. Uses [minimatch](https://www.npmjs.com/package/minimatch) with its default options.
147
229
  *
@@ -301,6 +383,15 @@ declare module "std" {
301
383
  */
302
384
  export function loadFile(filename: string): string;
303
385
 
386
+ /**
387
+ * Read the script of module filename from an active stack frame, then return it as a string.
388
+ *
389
+ * If there isn't a valid filename for the specified stack frame, an error will be thrown.
390
+ *
391
+ * @param stackLevels - How many levels up the stack to search for a filename. Defaults to 0, which uses the current stack frame.
392
+ */
393
+ export function getFileNameFromStack(stackLevels: number): string;
394
+
304
395
  /**
305
396
  * Open a file (wrapper to the libc `fopen()`).
306
397
  * Return the FILE object.