Skip to content

Commit 79b908e

Browse files
author
Mark Molinaro
committed
Ergonomics change to support awaiting stdout/stdin
1 parent 46ba584 commit 79b908e

2 files changed

Lines changed: 8 additions & 2 deletions

File tree

execr.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ type AnyKey<T> = T & {
66
[key: string]: T
77
};
88

9+
type AsyncifiedObject<T> = {
10+
[P in keyof T]: Promise<T[P]>
11+
}
912
type AnyFunction = (...args: any) => any;
1013
type Tail<T extends any[]> =
1114
((...args: T) => void) extends ((firstArg: any, ...restOfArgs: infer R) => void) ? R : never;
@@ -25,7 +28,7 @@ type ExecResult = {
2528
stderr: string,
2629
}
2730

28-
type AttachedPromise<T> = Promise<T> & { _child: ChildProcess }
31+
type AttachedPromise<T> = Promise<T> & AsyncifiedObject<T> & { _child: ChildProcess }
2932
type ExecFunction = (...args: ExecParameters) => ExecResult;
3033
type ExecAsyncFunction = (...args: ExecParameters) => AttachedPromise<ExecResult>;
3134

@@ -93,6 +96,9 @@ function execAsync(
9396
}) as AttachedPromise<ExecResult>;
9497

9598
promise._child = childProcess;
99+
promise.status = promise.then(result => result.status);
100+
promise.stdout = promise.then(result => result.stdout);
101+
promise.stderr = promise.then(result => result.stderr);
96102
return promise;
97103
}
98104

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@markjm/execr",
3-
"version": "1.5.0",
3+
"version": "1.6.0",
44
"description": "Utility to streamline exec calls",
55
"main": "execr.js",
66
"types": "execr.d.ts",

0 commit comments

Comments
 (0)