Skip to content

Commit

Permalink
skip the prompt when in a known ci environment
Browse files Browse the repository at this point in the history
PR-URL: #2047
Credit: @nlf
Close: #2047
Reviewed-by: @ruyadorno
  • Loading branch information
nlf committed Oct 27, 2020
1 parent d8ac707 commit 46c7f79
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/exec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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(/@$/, '')}`)
Expand Down
15 changes: 15 additions & 0 deletions test/lib/exec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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'
Expand Down Expand Up @@ -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'
Expand Down Expand Up @@ -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'
Expand Down Expand Up @@ -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??'
Expand Down Expand Up @@ -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'
Expand Down Expand Up @@ -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']

Expand Down

0 comments on commit 46c7f79

Please sign in to comment.