Skip to content

Commit 6f64148

Browse files
committed
fix: require stdout to be a TTY for progress (#7507)
1 parent 8add914 commit 6f64148

File tree

3 files changed

+7
-3
lines changed

3 files changed

+7
-3
lines changed

tap-snapshots/test/lib/docs.js.test.cjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1262,7 +1262,7 @@ a semver. Like the \`rc\` in \`1.2.0-rc.8\`.
12621262
* Type: Boolean
12631263
12641264
When set to \`true\`, npm will display a progress bar during time intensive
1265-
operations, if \`process.stderr\` is a TTY.
1265+
operations, if \`process.stderr\` and \`process.stdout\` are a TTY.
12661266
12671267
Set to \`false\` to suppress the progress bar.
12681268

workspaces/config/lib/definitions/definitions.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1549,13 +1549,16 @@ const definitions = {
15491549
type: Boolean,
15501550
description: `
15511551
When set to \`true\`, npm will display a progress bar during time
1552-
intensive operations, if \`process.stderr\` is a TTY.
1552+
intensive operations, if \`process.stderr\` and \`process.stdout\` are a TTY.
15531553
15541554
Set to \`false\` to suppress the progress bar.
15551555
`,
15561556
flatten (key, obj, flatOptions) {
15571557
flatOptions.progress = !obj.progress ? false
1558-
: !!process.stderr.isTTY && process.env.TERM !== 'dumb'
1558+
// progress is only written to stderr but we disable it unless stdout is a tty
1559+
// also. This prevents the progress from appearing when piping output to another
1560+
// command which doesn't break anything, but does look very odd to users.
1561+
: !!process.stderr.isTTY && !!process.stdout.isTTY && process.env.TERM !== 'dumb'
15591562
},
15601563
}),
15611564
provenance: new Definition('provenance', {

workspaces/config/test/definitions/definitions.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,7 @@ t.test('color', t => {
396396
t.test('progress', t => {
397397
const setEnv = ({ tty, term } = {}) => mockGlobals(t, {
398398
'process.stderr.isTTY': tty,
399+
'process.stdout.isTTY': tty,
399400
'process.env.TERM': term,
400401
})
401402

0 commit comments

Comments
 (0)