Skip to content

Commit e009765

Browse files
peterchu999sindresorhus
andauthoredJul 19, 2020
Add allowNonzeroExitCode option (#176)
Co-authored-by: Sindre Sorhus <sindresorhus@gmail.com>
1 parent 72d9ddb commit e009765

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed
 

‎index.d.ts

+9
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,15 @@ declare namespace open {
4242
@default false
4343
*/
4444
readonly url?: boolean;
45+
46+
/**
47+
Allow the opened app to exit with nonzero exit code when the `wait` option is `true`.
48+
49+
We do not recommend setting this option. The convention for success is exit code zero.
50+
51+
@default false
52+
*/
53+
readonly allowNonzeroExitCode?: boolean;
4554
}
4655
}
4756

‎index.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ module.exports = async (target, options) => {
2929
wait: false,
3030
background: false,
3131
url: false,
32+
allowNonzeroExitCode: false,
3233
...options
3334
};
3435

@@ -148,7 +149,7 @@ module.exports = async (target, options) => {
148149
subprocess.once('error', reject);
149150

150151
subprocess.once('close', exitCode => {
151-
if (exitCode > 0) {
152+
if (options.allowNonzeroExitCode && exitCode > 0) {
152153
reject(new Error(`Exited with code ${exitCode}`));
153154
return;
154155
}

‎readme.md

+9
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,15 @@ We do not recommend using it on targets that are not URLs.
102102

103103
Especially useful when dealing with the [double-quotes on Windows](#double-quotes-on-windows) caveat.
104104

105+
##### allowNonzeroExitCode
106+
107+
Type: `boolean`\
108+
Default: `false`
109+
110+
Allow the opened app to exit with nonzero exit code when the `wait` option is `true`.
111+
112+
We do not recommend setting this option. The convention for success is exit code zero.
113+
105114
## Caveats
106115

107116
### Double-quotes on Windows

0 commit comments

Comments
 (0)
Please sign in to comment.