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