From e0097657599d161b6052b0c15d8fd813f38382ca Mon Sep 17 00:00:00 2001 From: Peter Andrew <37611509+peterchu999@users.noreply.github.com> Date: Mon, 20 Jul 2020 06:58:53 +0700 Subject: [PATCH] Add `allowNonzeroExitCode` option (#176) Co-authored-by: Sindre Sorhus --- index.d.ts | 9 +++++++++ index.js | 3 ++- readme.md | 9 +++++++++ 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/index.d.ts b/index.d.ts index 3546af1..0210235 100644 --- a/index.d.ts +++ b/index.d.ts @@ -42,6 +42,15 @@ declare namespace open { @default false */ readonly url?: boolean; + + /** + Allow the opened app to exit with nonzero exit code when the `wait` option is `true`. + + We do not recommend setting this option. The convention for success is exit code zero. + + @default false + */ + readonly allowNonzeroExitCode?: boolean; } } diff --git a/index.js b/index.js index 67b3c29..3bf5373 100644 --- a/index.js +++ b/index.js @@ -29,6 +29,7 @@ module.exports = async (target, options) => { wait: false, background: false, url: false, + allowNonzeroExitCode: false, ...options }; @@ -148,7 +149,7 @@ module.exports = async (target, options) => { subprocess.once('error', reject); subprocess.once('close', exitCode => { - if (exitCode > 0) { + if (options.allowNonzeroExitCode && exitCode > 0) { reject(new Error(`Exited with code ${exitCode}`)); return; } diff --git a/readme.md b/readme.md index 4669e86..19299e5 100644 --- a/readme.md +++ b/readme.md @@ -102,6 +102,15 @@ We do not recommend using it on targets that are not URLs. Especially useful when dealing with the [double-quotes on Windows](#double-quotes-on-windows) caveat. +##### allowNonzeroExitCode + +Type: `boolean`\ +Default: `false` + +Allow the opened app to exit with nonzero exit code when the `wait` option is `true`. + +We do not recommend setting this option. The convention for success is exit code zero. + ## Caveats ### Double-quotes on Windows