diff options
author | Ruy Adorno <ruyadorno@hotmail.com> | 2021-03-23 00:48:26 +0300 |
---|---|---|
committer | Ruy Adorno <ruyadorno@hotmail.com> | 2021-03-23 00:48:26 +0300 |
commit | 15ee1aec3675bc026fc360f81b04bae4db84d942 (patch) | |
tree | 7f0b72d9c73e2cf40aa1c3b06ff23b96925022b3 | |
parent | 93a061d737dc769663652368e8586e4202267b9e (diff) |
fix: yes config
`npm exec <pkg>` was failing for packages not available in the local or
global scope due to the default value of the `yes` config having been
changed to `false` during the latest config refactor. That caused
`npm exec` to throw with a `canceled` error message since the current
implementation expects the default value to be falsy but not `false`.
This change reinstates the previous default config value for `yes` and
changes the implementation to throw with a proper error object in order
to get a stack trace when running with `--loglevel=verbose`.
-rw-r--r-- | lib/exec.js | 4 | ||||
-rw-r--r-- | lib/utils/config/definitions.js | 4 | ||||
-rw-r--r-- | tap-snapshots/test-lib-utils-config-describe-all.js-TAP.test.js | 4 | ||||
-rw-r--r-- | test/lib/exec.js | 4 |
4 files changed, 8 insertions, 8 deletions
diff --git a/lib/exec.js b/lib/exec.js index 25ddeb3bd..0a61de7c1 100644 --- a/lib/exec.js +++ b/lib/exec.js @@ -193,7 +193,7 @@ class Exec extends BaseCommand { if (!this.npm.config.get('yes')) { // set -n to always say no if (this.npm.config.get('yes') === false) - throw 'canceled' + throw new Error('canceled') if (!process.stdin.isTTY || ciDetect()) { this.npm.log.warn('exec', `The following package${ @@ -209,7 +209,7 @@ class Exec extends BaseCommand { }Ok to proceed? ` const confirm = await read({ prompt, default: 'y' }) if (confirm.trim().toLowerCase().charAt(0) !== 'y') - throw 'canceled' + throw new Error('canceled') } } await arb.reify({ ...this.npm.flatOptions, add }) diff --git a/lib/utils/config/definitions.js b/lib/utils/config/definitions.js index 9a7c0092f..a6ecbcd0c 100644 --- a/lib/utils/config/definitions.js +++ b/lib/utils/config/definitions.js @@ -2044,8 +2044,8 @@ define('workspaces', { }) define('yes', { - default: false, - type: Boolean, + default: null, + type: [null, Boolean], short: 'y', description: ` Automatically answer "yes" to any prompts that npm might print on diff --git a/tap-snapshots/test-lib-utils-config-describe-all.js-TAP.test.js b/tap-snapshots/test-lib-utils-config-describe-all.js-TAP.test.js index 10cc2b238..8323e793e 100644 --- a/tap-snapshots/test-lib-utils-config-describe-all.js-TAP.test.js +++ b/tap-snapshots/test-lib-utils-config-describe-all.js-TAP.test.js @@ -1222,8 +1222,8 @@ workspaces. #### \`yes\` -* Default: false -* Type: Boolean +* Default: null +* Type: null or Boolean Automatically answer "yes" to any prompts that npm might print on the command line. diff --git a/test/lib/exec.js b/test/lib/exec.js index 7104795f6..bcfe75577 100644 --- a/test/lib/exec.js +++ b/test/lib/exec.js @@ -945,7 +945,7 @@ t.test('abort if prompt rejected', t => { _from: 'bar@', } exec.exec(['foobar'], er => { - t.equal(er, 'canceled', 'should be canceled') + t.match(er, /canceled/, 'should be canceled') t.strictSame(MKDIRPS, [installDir], 'need to make install dir') t.match(ARB_CTOR, [{ path }]) t.strictSame(ARB_REIFY, [], 'no install performed') @@ -1060,7 +1060,7 @@ t.test('abort if -n provided', t => { _from: 'bar@', } exec.exec(['foobar'], er => { - t.equal(er, 'canceled', 'should be canceled') + t.match(er, /canceled/, 'should be canceled') t.strictSame(MKDIRPS, [installDir], 'need to make install dir') t.match(ARB_CTOR, [{ path }]) t.strictSame(ARB_REIFY, [], 'no install performed') |