Skip to content

Commit 9b90325

Browse files
committed
feat: revert $.stdout to piped after all async ops are done
1 parent 74a9de0 commit 9b90325

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

README.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,16 @@ console.log(`Hello from ${$.blue.bold("dzx")}!`);
3434
const branch = await $`git branch --show-current`;
3535
await $`dep deploy --branch=${branch}`;
3636

37+
// Print command output to stdout. Will be reverted to "piped" after all async ops are done.
38+
$.stdout = "inherit";
3739
await Promise.all([
3840
$`deno lint`,
3941
$`deno fmt --check`,
4042
$`deno test --allow-all`,
4143
]);
4244

4345
const name = "foo bar";
44-
await $`mkdir ./tmp/${name}`; // params will be quoted if required: /tmp/'foo bar'
46+
await $`mkdir ./tmp/${name}`; // Params will be quoted if required: /tmp/'foo bar'.
4547

4648
cd("tmp/foo bar");
4749
console.log(Deno.cwd()); // ./tmp/foo bar
@@ -234,7 +236,8 @@ script.
234236
- **$.verbose:** Enable debugging output (log shell commands and execution
235237
time).
236238
- **$.stdout:** Change stdout mode of `` $`command` ``. Can be `"inherit"`,
237-
`"piped"`, `"null"` or `number`. Default: `"piped"`
239+
`"piped"`, `"null"` or `number`. Will be reverted to default after all async
240+
ops are done. Default: `"piped"`
238241
- **$.throwErrors:** Throw errors instead of calling `Deno.exit`.
239242
- **$.startTime:** The execution start time in ms.
240243
- **$.time:** The time left since execution start (now() - $.startTime).

src/runtime/exec.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,13 @@ import { ProcessError } from "./process_error.ts";
22
import { ProcessOutput } from "./process_output.ts";
33
import { quote } from "./quote.ts";
44

5+
let runningProcesses = 0;
6+
57
export async function exec(
68
pieces: TemplateStringsArray,
79
...args: Array<string | number>
810
): Promise<ProcessOutput> {
11+
runningProcesses++;
912
const cmd = quote(pieces, ...args);
1013

1114
if ($.verbose) {
@@ -28,6 +31,10 @@ export async function exec(
2831
read(process.stderr, stderr, combined),
2932
]);
3033

34+
if (--runningProcesses === 0) {
35+
$.stdout = "piped";
36+
}
37+
3138
if (status.success) {
3239
return new ProcessOutput({
3340
stdout: stdout.join(""),

0 commit comments

Comments
 (0)