Skip to content

Commit

Permalink
fix: require stdout to be a TTY for progress (#7507)
Browse files Browse the repository at this point in the history
  • Loading branch information
lukekarrys committed May 11, 2024
1 parent 8add914 commit 6f64148
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
2 changes: 1 addition & 1 deletion tap-snapshots/test/lib/docs.js.test.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -1262,7 +1262,7 @@ a semver. Like the \`rc\` in \`1.2.0-rc.8\`.
* Type: Boolean
When set to \`true\`, npm will display a progress bar during time intensive
operations, if \`process.stderr\` is a TTY.
operations, if \`process.stderr\` and \`process.stdout\` are a TTY.
Set to \`false\` to suppress the progress bar.
Expand Down
7 changes: 5 additions & 2 deletions workspaces/config/lib/definitions/definitions.js
Original file line number Diff line number Diff line change
Expand Up @@ -1549,13 +1549,16 @@ const definitions = {
type: Boolean,
description: `
When set to \`true\`, npm will display a progress bar during time
intensive operations, if \`process.stderr\` is a TTY.
intensive operations, if \`process.stderr\` and \`process.stdout\` are a TTY.
Set to \`false\` to suppress the progress bar.
`,
flatten (key, obj, flatOptions) {
flatOptions.progress = !obj.progress ? false
: !!process.stderr.isTTY && process.env.TERM !== 'dumb'
// progress is only written to stderr but we disable it unless stdout is a tty
// also. This prevents the progress from appearing when piping output to another
// command which doesn't break anything, but does look very odd to users.
: !!process.stderr.isTTY && !!process.stdout.isTTY && process.env.TERM !== 'dumb'
},
}),
provenance: new Definition('provenance', {
Expand Down
1 change: 1 addition & 0 deletions workspaces/config/test/definitions/definitions.js
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,7 @@ t.test('color', t => {
t.test('progress', t => {
const setEnv = ({ tty, term } = {}) => mockGlobals(t, {
'process.stderr.isTTY': tty,
'process.stdout.isTTY': tty,
'process.env.TERM': term,
})

Expand Down

0 comments on commit 6f64148

Please sign in to comment.