From dd7958f03eb3305d21a2bfb845e6d8d34b44482a Mon Sep 17 00:00:00 2001 From: Luke Karrys Date: Fri, 10 May 2024 12:57:54 -0700 Subject: [PATCH 1/2] fix: require stdout to be a TTY for progress Progress is shown on stderr but looks weird when stdout is piped to another command. So we should only show it by default if both streams are TTYs. --- workspaces/config/lib/definitions/definitions.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/workspaces/config/lib/definitions/definitions.js b/workspaces/config/lib/definitions/definitions.js index 57ab171611838..2978aa4b55dac 100644 --- a/workspaces/config/lib/definitions/definitions.js +++ b/workspaces/config/lib/definitions/definitions.js @@ -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', { From 466ffaea042220bccef05bb109efc962660d9f54 Mon Sep 17 00:00:00 2001 From: Luke Karrys Date: Fri, 10 May 2024 13:05:37 -0700 Subject: [PATCH 2/2] fixup! fix: require stdout to be a TTY for progress --- workspaces/config/test/definitions/definitions.js | 1 + 1 file changed, 1 insertion(+) diff --git a/workspaces/config/test/definitions/definitions.js b/workspaces/config/test/definitions/definitions.js index 913e14e5c78f2..1b77bd0e811bf 100644 --- a/workspaces/config/test/definitions/definitions.js +++ b/workspaces/config/test/definitions/definitions.js @@ -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, })