-
Notifications
You must be signed in to change notification settings - Fork 774
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
spinner: do not print escape sequences to non-tty output (#7133)
The workers-sdk defines an `isInteractive` test which (incorrectly) does not check whether stdout is a TTY. This means that when piping output to a file or to another process, UI elements like the spinner write ANSI escape sequences to stdout where they are not properly interpreted. Wrangler has its own separate interactivity test that does check that stdout is a TTY. This commit updates workers-sdk to use the `isInteractive` test from Wrangler (which checks that both stdin and stdout are TTYs) and then updates Wrangler to use this function. This both eliminates code duplication and also fixes the problem mentioned above where escape sequences are written to non-TTY outputs. In addition, the `logOutput` function that the spinner uses (which uses code from the 3rd party `log-output` library) _unconditionally_ assumes that stdout is a TTY (it doesn't even check!) and always emits escape sequences. So when we are running non-interactively, we must use the `logRaw` function to avoid emitting escape sequences. While making this change, I also addressed the TODO on the `isNonInteractiveOrCI` function by using that function throughout the wrangler codebase.
- Loading branch information
Showing
13 changed files
with
74 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"wrangler": patch | ||
--- | ||
|
||
Do not emit escape sequences when stdout is not a TTY |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { grayBar, leftT, spinner } from "@cloudflare/cli/interactive"; | ||
import { collectCLIOutput } from "./helpers/collect-cli-output"; | ||
import { useMockIsTTY } from "./helpers/mock-istty"; | ||
|
||
describe("cli", () => { | ||
describe("spinner", () => { | ||
const std = collectCLIOutput(); | ||
const { setIsTTY } = useMockIsTTY(); | ||
test("does not animate when stdout is not a TTY", async () => { | ||
setIsTTY(false); | ||
const s = spinner(); | ||
const startMsg = "Start message"; | ||
s.start(startMsg); | ||
const stopMsg = "Stop message"; | ||
s.stop(stopMsg); | ||
expect(std.out).toEqual( | ||
`${leftT} ${startMsg}\n${grayBar} ${stopMsg}\n${grayBar}\n` | ||
); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters