Skip to content

Commit fa5ce96

Browse files
committed
feat: add reject option
1 parent 53dc7d9 commit fa5ce96

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

src/index.d.ts

+4
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,15 @@ import { ChildProcess, SpawnOptions } from 'child_process';
22

33
interface ExtendOptions extends SpawnOptions {
44
json?: boolean;
5+
reject?: boolean;
56
}
67

78
interface ResolvedSubprocess extends Omit<ChildProcess, 'stdout' | 'stderr'> {
89
stdout: string;
910
stderr: string;
11+
exitCode: number;
12+
/** Only exists if `reject` was false and the child process exited with a non-zero code. */
13+
error?: Error;
1014
}
1115

1216
export interface SubprocessPromise extends Promise<ResolvedSubprocess>, ChildProcess {}

src/index.js

+8-3
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,14 @@ const extend = defaults => (input, args, options) => {
5858
get: parse(stdout, opts)
5959
})
6060
Object.defineProperty(childProcess, 'stderr', { get: parse(stderr) })
61-
return exitCode === 0
62-
? resolve(childProcess)
63-
: reject(createChildProcessError({ cmd, cmdArgs, childProcess }))
61+
if (exitCode !== 0) {
62+
const error = createChildProcessError({ cmd, cmdArgs, childProcess })
63+
if (opts.reject !== false) {
64+
return reject(error)
65+
}
66+
childProcess.error = error
67+
}
68+
return resolve(childProcess)
6469
})
6570
})
6671

0 commit comments

Comments
 (0)