diff --git a/lib/exec.js b/lib/exec.js index cda884943998d..96eb8190053f5 100644 --- a/lib/exec.js +++ b/lib/exec.js @@ -55,6 +55,7 @@ const readPackageJson = require('read-package-json-fast') const Arborist = require('@npmcli/arborist') const runScript = require('@npmcli/run-script') const { resolve, delimiter } = require('path') +const ciDetect = require('@npmcli/ci-detect') const crypto = require('crypto') const pacote = require('pacote') const npa = require('npm-package-arg') @@ -161,7 +162,7 @@ const exec = async args => { if (npm.flatOptions.yes === false) throw 'canceled' - if (!isTTY) + if (!isTTY || ciDetect()) npm.log.warn('exec', `The following package${add.length === 1 ? ' was' : 's were'} not found and will be installed: ${add.map((pkg) => pkg.replace(/@$/, '')).join(', ')}`) else { const addList = add.map(a => ` ${a.replace(/@$/, '')}`) diff --git a/test/lib/exec.js b/test/lib/exec.js index ca8c2c1e7666f..97da01140edb0 100644 --- a/test/lib/exec.js +++ b/test/lib/exec.js @@ -80,9 +80,12 @@ const read = (options, cb) => { const PATH = require('../../lib/utils/path.js') +let CI_NAME = 'travis-ci' + const exec = requireInject('../../lib/exec.js', { '@npmcli/arborist': Arborist, '@npmcli/run-script': runScript, + '@npmcli/ci-detect': () => CI_NAME, '../../lib/npm.js': npm, pacote, read, @@ -531,9 +534,11 @@ t.test('prompt when installs are needed if not already present and shell is a TT t.teardown(() => { process.stdout.isTTY = stdoutTTY process.stdin.isTTY = stdinTTY + CI_NAME = 'travis-ci' }) process.stdout.isTTY = true process.stdin.isTTY = true + CI_NAME = false const packages = ['foo', 'bar'] READ_RESULT = 'yolo' @@ -598,9 +603,11 @@ t.test('skip prompt when installs are needed if not already present and shell is t.teardown(() => { process.stdout.isTTY = stdoutTTY process.stdin.isTTY = stdinTTY + CI_NAME = 'travis-ci' }) process.stdout.isTTY = false process.stdin.isTTY = false + CI_NAME = false const packages = ['foo', 'bar'] READ_RESULT = 'yolo' @@ -663,9 +670,11 @@ t.test('skip prompt when installs are needed if not already present and shell is t.teardown(() => { process.stdout.isTTY = stdoutTTY process.stdin.isTTY = stdinTTY + CI_NAME = 'travis-ci' }) process.stdout.isTTY = false process.stdin.isTTY = false + CI_NAME = false const packages = ['foo'] READ_RESULT = 'yolo' @@ -720,9 +729,11 @@ t.test('abort if prompt rejected', async t => { t.teardown(() => { process.stdout.isTTY = stdoutTTY process.stdin.isTTY = stdinTTY + CI_NAME = 'travis-ci' }) process.stdout.isTTY = true process.stdin.isTTY = true + CI_NAME = false const packages = ['foo', 'bar'] READ_RESULT = 'no, why would I want such a thing??' @@ -776,9 +787,11 @@ t.test('abort if prompt false', async t => { t.teardown(() => { process.stdout.isTTY = stdoutTTY process.stdin.isTTY = stdinTTY + CI_NAME = 'travis-ci' }) process.stdout.isTTY = true process.stdin.isTTY = true + CI_NAME = false const packages = ['foo', 'bar'] READ_ERROR = 'canceled' @@ -832,9 +845,11 @@ t.test('abort if -n provided', async t => { t.teardown(() => { process.stdout.isTTY = stdoutTTY process.stdin.isTTY = stdinTTY + CI_NAME = 'travis-ci' }) process.stdout.isTTY = true process.stdin.isTTY = true + CI_NAME = false const packages = ['foo', 'bar']