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 3 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
18 changes: 18 additions & 0 deletions test/lib/exec.js
Original file line number Diff line number Diff line change
Expand Up @@ -528,12 +528,15 @@ t.test('positional args and --call together is an error', t => {
t.test('prompt when installs are needed if not already present and shell is a TTY', async t => {
const stdoutTTY = process.stdout.isTTY
const stdinTTY = process.stdin.isTTY
const travisEnv = process.env.TRAVIS
t.teardown(() => {
process.stdout.isTTY = stdoutTTY
process.stdin.isTTY = stdinTTY
process.env.TRAVIS = travisEnv
})
process.stdout.isTTY = true
process.stdin.isTTY = true
delete process.env.TRAVIS

const packages = ['foo', 'bar']
READ_RESULT = 'yolo'
Expand Down Expand Up @@ -595,12 +598,15 @@ t.test('prompt when installs are needed if not already present and shell is a TT
t.test('skip prompt when installs are needed if not already present and shell is not a tty (multiple packages)', async t => {
const stdoutTTY = process.stdout.isTTY
const stdinTTY = process.stdin.isTTY
const travisEnv = process.env.TRAVIS
t.teardown(() => {
process.stdout.isTTY = stdoutTTY
process.stdin.isTTY = stdinTTY
process.env.TRAVIS = travisEnv
})
process.stdout.isTTY = false
process.stdin.isTTY = false
delete process.env.TRAVIS

const packages = ['foo', 'bar']
READ_RESULT = 'yolo'
Expand Down Expand Up @@ -660,12 +666,15 @@ t.test('skip prompt when installs are needed if not already present and shell is
t.test('skip prompt when installs are needed if not already present and shell is not a tty (single package)', async t => {
const stdoutTTY = process.stdout.isTTY
const stdinTTY = process.stdin.isTTY
const travisEnv = process.env.TRAVIS
t.teardown(() => {
process.stdout.isTTY = stdoutTTY
process.stdin.isTTY = stdinTTY
process.env.TRAVIS = travisEnv
})
process.stdout.isTTY = false
process.stdin.isTTY = false
delete process.env.TRAVIS

const packages = ['foo']
READ_RESULT = 'yolo'
Expand Down Expand Up @@ -717,12 +726,15 @@ t.test('skip prompt when installs are needed if not already present and shell is
t.test('abort if prompt rejected', async t => {
const stdoutTTY = process.stdout.isTTY
const stdinTTY = process.stdin.isTTY
const travisEnv = process.env.TRAVIS
t.teardown(() => {
process.stdout.isTTY = stdoutTTY
process.stdin.isTTY = stdinTTY
process.env.TRAVIS = travisEnv
})
process.stdout.isTTY = true
process.stdin.isTTY = true
delete process.env.TRAVIS

const packages = ['foo', 'bar']
READ_RESULT = 'no, why would I want such a thing??'
Expand Down Expand Up @@ -773,12 +785,15 @@ t.test('abort if prompt rejected', async t => {
t.test('abort if prompt false', async t => {
const stdoutTTY = process.stdout.isTTY
const stdinTTY = process.stdin.isTTY
const travisEnv = process.env.TRAVIS
t.teardown(() => {
process.stdout.isTTY = stdoutTTY
process.stdin.isTTY = stdinTTY
process.env.TRAVIS = travisEnv
})
process.stdout.isTTY = true
process.stdin.isTTY = true
delete process.env.TRAVIS

const packages = ['foo', 'bar']
READ_ERROR = 'canceled'
Expand Down Expand Up @@ -829,12 +844,15 @@ t.test('abort if prompt false', async t => {
t.test('abort if -n provided', async t => {
const stdoutTTY = process.stdout.isTTY
const stdinTTY = process.stdin.isTTY
const travisEnv = process.env.TRAVIS
t.teardown(() => {
process.stdout.isTTY = stdoutTTY
process.stdin.isTTY = stdinTTY
process.env.TRAVIS = travisEnv
})
process.stdout.isTTY = true
process.stdin.isTTY = true
delete process.env.TRAVIS

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

Expand Down