You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
@@ -1193,7 +1191,7 @@ export async function requireAuth(config: {
1193
1191
}): Promise<string>{
1194
1192
constloggedIn=awaitloginOrRefreshIfRequired();
1195
1193
if(!loggedIn){
1196
-
if(!isInteractive()||CI.isCI()){
1194
+
if(isNonInteractiveOrCI()){
1197
1195
thrownewUserError(
1198
1196
"In a non-interactive environment, it's necessary to set a CLOUDFLARE_API_TOKEN environment variable for wrangler to work. Please go to https://developers.cloudflare.com/fundamentals/api/get-started/create-token/ for instructions on how to create an api token, and assign its value to CLOUDFLARE_API_TOKEN."
0 commit comments