Skip to content

Commit 5a8a218

Browse files
authored
breaking(runtime): remove $s shorthand for statusCode (#75)
1 parent ff9910e commit 5a8a218

File tree

7 files changed

+19
-70
lines changed

7 files changed

+19
-70
lines changed

README.md

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -200,23 +200,6 @@ notes.
200200
}
201201
```
202202

203-
- `` $s`command` ``: Executes a shell command and _only returns its exit code_
204-
(without throwing an error)
205-
206-
```ts
207-
const trueStatus = await $s`true`);
208-
console.log(trueStatus); // -> 0
209-
```
210-
211-
If the executed program returns a non-zero exit code, no error will be thrown.
212-
Either the non-zero code will be the return value, or a `1` will be returned
213-
by default.
214-
215-
```ts
216-
const falseStatus = await $s`false`);
217-
console.log(falseStatus); // -> 1
218-
```
219-
220203
- `` $o`command` ``: Executes a shell command and _only returns its trimmed
221204
stdout_ (without throwing an error)
222205

src/runtime/exec.ts

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -19,26 +19,6 @@ export function exec(
1919
});
2020
}
2121

22-
/**
23-
* Run a command and return only its exit code
24-
*
25-
* If the command throws an error or fails in some way,
26-
* this method will not re-throw that error. It will
27-
* either return the exit code from the process, or `1`
28-
* if no exit code is produced (due to an error)
29-
*
30-
* If you want assurance that a failure in the child process
31-
* will throw an error, use `$`
32-
* @see $
33-
*/
34-
export const statusOnly = async (
35-
pieces: TemplateStringsArray,
36-
...args: Array<string | number | ProcessOutput>
37-
): Promise<number> =>
38-
await exec(pieces, ...args)
39-
.then((o) => (o instanceof ProcessOutput ? o.status.code : 0))
40-
.catch((e) => (e instanceof ProcessError ? e.status.code : 1));
41-
4222
/**
4323
* Run a command and return only its trimmed stdout
4424
*

src/runtime/mod.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
export { async, flags, fs, io, log, path, streams } from "./deps.ts";
2-
export { $, $e, $o, $s } from "./shell.ts";
2+
export { $, $e, $o } from "./shell.ts";
33
export { cd } from "./cd.ts";
44
export { quote } from "./quote.ts";
55
export { ProcessError } from "./process_error.ts";

src/runtime/process.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,21 @@ export class Process implements Promise<ProcessOutput> {
7070
return this;
7171
}
7272

73+
/**
74+
* Execute the shell command and _only returns its exit code_.
75+
* This calls internally `.noThrow` to catch the error and return the exit code.
76+
*
77+
* ```ts
78+
* const trueStatus = await $`true`.statusCode;
79+
* console.log(trueStatus); // -> 0
80+
*
81+
* const falseStatus = await $`false`.statusCode;
82+
* console.log(falseStatus); // -> 1
83+
*
84+
* const exitStatus = await $`exit 2`.statusCode;
85+
* console.log(exitStatus); // -> 2
86+
* ```
87+
*/
7388
get statusCode(): Promise<number> {
7489
return this.noThrow.#resolve().then(({ status }) => status.code);
7590
}

src/runtime/shell.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { colors, shq } from "./deps.ts";
2-
import { exec, statusOnly, stderrOnly, stdoutOnly } from "./exec.ts";
2+
import { exec, stderrOnly, stdoutOnly } from "./exec.ts";
33

44
export type $ = typeof exec & typeof colors & {
55
get mainModule(): string;
@@ -18,7 +18,6 @@ export type $ = typeof exec & typeof colors & {
1818
};
1919

2020
export const $: $ = exec as $;
21-
export const $s: typeof statusOnly = statusOnly;
2221
export const $o: typeof stdoutOnly = stdoutOnly;
2322
export const $e: typeof stderrOnly = stderrOnly;
2423

test.ts

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,25 +7,14 @@ import {
77
assertStringIncludes,
88
} from "./dev_deps.ts";
99

10-
import { $, $e, $o, $s, cd, path, ProcessError } from "./mod.ts";
10+
import { $, $e, $o, cd, path, ProcessError } from "./mod.ts";
1111

1212
Deno.test("$ works", async () => {
1313
const result = await $`echo hello`;
1414

1515
assertEquals(result.stdout, "hello\n");
1616
});
1717

18-
Deno.test("$s works", async () => {
19-
const result1 = await $s`echo hello`;
20-
assertEquals(result1, 0);
21-
22-
const result2 = await $s`echo hello >&2`;
23-
assertEquals(result2, 0);
24-
25-
const result3 = await $s`echo hello; exit 1;`;
26-
assertEquals(result3, 1);
27-
});
28-
2918
Deno.test("$o works", async () => {
3019
const result1 = await $o`echo hello`;
3120
assertEquals(result1, "hello");
@@ -185,7 +174,7 @@ Deno.test({
185174
// @TODO: tests are flaky on github actions.
186175
// Test runner is green but throws: No such file or directory (os error 2)
187176
// But they don't fail while uncommenting all other tests.
188-
// Locally all tests pass.
177+
// Locally all tests pass.
189178
Deno.test({
190179
name: "$ should have a pid",
191180
ignore: !!Deno.env.get("CI"),

types.d.ts

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import type {
22
$ as _$,
33
$e as _$e,
44
$o as _$o,
5-
$s as _$s,
65
async as _async,
76
cd as _cd,
87
flags as _flags,
@@ -47,20 +46,6 @@ declare global {
4746
*/
4847
const $: _$;
4948

50-
/**
51-
* Run a command and return only its exit code.
52-
*
53-
* If the command throws an error or fails in some way,
54-
* this method will not re-throw that error. It will
55-
* either return the exit code from the process, or `1`
56-
* if no exit code is produced (due to an error).
57-
*
58-
* If you want assurance that a failure in the child process
59-
* will throw an error, use `$`.
60-
* @see $
61-
*/
62-
const $s: typeof _$s;
63-
6449
/**
6550
* Run a command and return only its trimmed stdout.
6651
*
@@ -151,7 +136,6 @@ declare global {
151136
interface Window {
152137
// dzx
153138
$: _$;
154-
$s: typeof _$s;
155139
$o: typeof _$o;
156140
$e: typeof _$e;
157141
cd: typeof _cd;
@@ -170,7 +154,6 @@ declare global {
170154
interface WorkerGlobalScope {
171155
// dzx
172156
$: _$;
173-
$s: typeof _$s;
174157
$o: typeof _$o;
175158
$e: typeof _$e;
176159
cd: typeof _cd;

0 commit comments

Comments
 (0)