Skip to content

skip exec confirmation prompt in ci #2047

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
2 changes: 1 addition & 1 deletion tap-snapshots/test-lib-utils-flat-options.js-TAP.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ Object {
"omit": Array [],
"otp": "otp",
"package": "package",
"packageLock": "package-lock",
"packageLock": true,
"packageLockOnly": "package-lock-only",
"parseable": undefined,
"preferDedupe": undefined,
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