Skip to content

Commit 46c7f79

Browse files
committed
skip the prompt when in a known ci environment
PR-URL: #2047 Credit: @nlf Close: #2047 Reviewed-by: @ruyadorno
1 parent d8ac707 commit 46c7f79

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

lib/exec.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ const readPackageJson = require('read-package-json-fast')
5555
const Arborist = require('@npmcli/arborist')
5656
const runScript = require('@npmcli/run-script')
5757
const { resolve, delimiter } = require('path')
58+
const ciDetect = require('@npmcli/ci-detect')
5859
const crypto = require('crypto')
5960
const pacote = require('pacote')
6061
const npa = require('npm-package-arg')
@@ -161,7 +162,7 @@ const exec = async args => {
161162
if (npm.flatOptions.yes === false)
162163
throw 'canceled'
163164

164-
if (!isTTY)
165+
if (!isTTY || ciDetect())
165166
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(', ')}`)
166167
else {
167168
const addList = add.map(a => ` ${a.replace(/@$/, '')}`)

test/lib/exec.js

+15
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,12 @@ const read = (options, cb) => {
8080

8181
const PATH = require('../../lib/utils/path.js')
8282

83+
let CI_NAME = 'travis-ci'
84+
8385
const exec = requireInject('../../lib/exec.js', {
8486
'@npmcli/arborist': Arborist,
8587
'@npmcli/run-script': runScript,
88+
'@npmcli/ci-detect': () => CI_NAME,
8689
'../../lib/npm.js': npm,
8790
pacote,
8891
read,
@@ -531,9 +534,11 @@ t.test('prompt when installs are needed if not already present and shell is a TT
531534
t.teardown(() => {
532535
process.stdout.isTTY = stdoutTTY
533536
process.stdin.isTTY = stdinTTY
537+
CI_NAME = 'travis-ci'
534538
})
535539
process.stdout.isTTY = true
536540
process.stdin.isTTY = true
541+
CI_NAME = false
537542

538543
const packages = ['foo', 'bar']
539544
READ_RESULT = 'yolo'
@@ -598,9 +603,11 @@ t.test('skip prompt when installs are needed if not already present and shell is
598603
t.teardown(() => {
599604
process.stdout.isTTY = stdoutTTY
600605
process.stdin.isTTY = stdinTTY
606+
CI_NAME = 'travis-ci'
601607
})
602608
process.stdout.isTTY = false
603609
process.stdin.isTTY = false
610+
CI_NAME = false
604611

605612
const packages = ['foo', 'bar']
606613
READ_RESULT = 'yolo'
@@ -663,9 +670,11 @@ t.test('skip prompt when installs are needed if not already present and shell is
663670
t.teardown(() => {
664671
process.stdout.isTTY = stdoutTTY
665672
process.stdin.isTTY = stdinTTY
673+
CI_NAME = 'travis-ci'
666674
})
667675
process.stdout.isTTY = false
668676
process.stdin.isTTY = false
677+
CI_NAME = false
669678

670679
const packages = ['foo']
671680
READ_RESULT = 'yolo'
@@ -720,9 +729,11 @@ t.test('abort if prompt rejected', async t => {
720729
t.teardown(() => {
721730
process.stdout.isTTY = stdoutTTY
722731
process.stdin.isTTY = stdinTTY
732+
CI_NAME = 'travis-ci'
723733
})
724734
process.stdout.isTTY = true
725735
process.stdin.isTTY = true
736+
CI_NAME = false
726737

727738
const packages = ['foo', 'bar']
728739
READ_RESULT = 'no, why would I want such a thing??'
@@ -776,9 +787,11 @@ t.test('abort if prompt false', async t => {
776787
t.teardown(() => {
777788
process.stdout.isTTY = stdoutTTY
778789
process.stdin.isTTY = stdinTTY
790+
CI_NAME = 'travis-ci'
779791
})
780792
process.stdout.isTTY = true
781793
process.stdin.isTTY = true
794+
CI_NAME = false
782795

783796
const packages = ['foo', 'bar']
784797
READ_ERROR = 'canceled'
@@ -832,9 +845,11 @@ t.test('abort if -n provided', async t => {
832845
t.teardown(() => {
833846
process.stdout.isTTY = stdoutTTY
834847
process.stdin.isTTY = stdinTTY
848+
CI_NAME = 'travis-ci'
835849
})
836850
process.stdout.isTTY = true
837851
process.stdin.isTTY = true
852+
CI_NAME = false
838853

839854
const packages = ['foo', 'bar']
840855

0 commit comments

Comments
 (0)