Skip to content

Commit a2b5dad

Browse files
committed
Use shared stderr prompt defaults and retain concurrent JSON output
1 parent cde37eb commit a2b5dad

6 files changed

Lines changed: 10 additions & 184 deletions

File tree

‎.changeset/cli-kit-json-ui-routing.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
'@shopify/cli-kit': patch
33
---
44

5-
Keep interactive prompts and concurrent process output on stderr in JSON mode.
5+
Send finite concurrent process output as JSON diagnostic and progress events on stderr.

‎packages/cli-kit/src/private/node/ui.tsx‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import {output} from './output.js'
2-
import {getUIOutputStream} from './ui/output-stream.js'
32
import {Logger, LogLevel} from '../../public/node/output.js'
43
import {isUnitTest} from '../../public/node/context/local.js'
54
import {treeKill} from '../../public/node/tree-kill.js'
@@ -69,7 +68,6 @@ export async function render(element: JSX.Element, options?: RenderOptions) {
6968
const {waitUntilExit} = inkRender(<InkLifecycleRoot>{element}</InkLifecycleRoot>, {
7069
patchConsole: !isUnitTest(),
7170
...options,
72-
stdout: getUIOutputStream(options?.stdout),
7371
})
7472
await waitUntilExit()
7573
}

‎packages/cli-kit/src/private/node/ui/output-stream.ts‎

Lines changed: 0 additions & 6 deletions
This file was deleted.

‎packages/cli-kit/src/public/node/system.ts‎

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import {platformAndArch} from './os.js'
88
import {shouldDisplayColors, outputDebug} from './output.js'
99
import {isCloudEnvironment} from './context/local.js'
1010
import {isInputDisabled} from './no-input.js'
11-
import {getUIOutputStream} from '../../private/node/ui/output-stream.js'
1211
import {execa, ExecaChildProcess} from 'execa'
1312
import supportsHyperlinks from 'supports-hyperlinks'
1413
import which from 'which'
@@ -342,16 +341,12 @@ export function terminalSupportsHyperlinks(): boolean {
342341
return supportsHyperlinks.stdout
343342
}
344343

345-
interface TerminalPromptingOptions {
346-
stdout?: NodeJS.WriteStream
347-
}
348-
349344
/**
350345
* Check if standard input and standard error are terminals that support prompting.
351346
*
352347
* @returns True if standard input and standard error support prompting.
353348
*/
354-
export function terminalSupportsPrompting(options: TerminalPromptingOptions = {}): boolean {
349+
export function terminalSupportsPrompting(): boolean {
355350
if (isInputDisabled() || isTruthy(process.env.CI)) {
356351
return false
357352
}

‎packages/cli-kit/src/public/node/ui.prompt-json.test.ts‎

Lines changed: 0 additions & 159 deletions
This file was deleted.

‎packages/cli-kit/src/public/node/ui.tsx‎

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ export async function renderSelectPrompt<T>(
294294
{renderOptions, isConfirmationPrompt, ...props}: RenderSelectPromptOptions<T>,
295295
uiDebugOptions: UIDebugOptions = defaultUIDebugOptions,
296296
): Promise<T> {
297-
throwInNonTTY({message: props.message, stdin: renderOptions?.stdin, stdout: renderOptions?.stdout}, uiDebugOptions)
297+
throwInNonTTY({message: props.message, stdin: renderOptions?.stdin}, uiDebugOptions)
298298

299299
return runWithTimer('cmd_all_timing_prompts_ms')(async () => {
300300
let selectedValue: T
@@ -429,7 +429,7 @@ export async function renderAutocompletePrompt<T>(
429429
{renderOptions, ...props}: RenderAutocompleteOptions<T>,
430430
uiDebugOptions: UIDebugOptions = defaultUIDebugOptions,
431431
): Promise<T> {
432-
throwInNonTTY({message: props.message, stdin: renderOptions?.stdin, stdout: renderOptions?.stdout}, uiDebugOptions)
432+
throwInNonTTY({message: props.message, stdin: renderOptions?.stdin}, uiDebugOptions)
433433

434434
// The default search filters in-memory choices synchronously, so it doesn't need
435435
// throttling. Skipping the throttle makes the keystroke-to-result latency feel
@@ -666,7 +666,7 @@ export async function renderTextPrompt(
666666
{renderOptions, ...props}: RenderTextPromptOptions,
667667
uiDebugOptions: UIDebugOptions = defaultUIDebugOptions,
668668
): Promise<string> {
669-
throwInNonTTY({message: props.message, stdin: renderOptions?.stdin, stdout: renderOptions?.stdout}, uiDebugOptions)
669+
throwInNonTTY({message: props.message, stdin: renderOptions?.stdin}, uiDebugOptions)
670670

671671
return runWithTimer('cmd_all_timing_prompts_ms')(async () => {
672672
let enteredText = ''
@@ -719,7 +719,7 @@ export async function renderDangerousConfirmationPrompt(
719719
{renderOptions, ...props}: RenderDangerousConfirmationPromptOptions,
720720
uiDebugOptions: UIDebugOptions = defaultUIDebugOptions,
721721
): Promise<boolean> {
722-
throwInNonTTY({message: props.message, stdin: renderOptions?.stdin, stdout: renderOptions?.stdout}, uiDebugOptions)
722+
throwInNonTTY({message: props.message, stdin: renderOptions?.stdin}, uiDebugOptions)
723723

724724
return runWithTimer('cmd_all_timing_prompts_ms')(async () => {
725725
let confirmed: boolean
@@ -772,23 +772,21 @@ export const keypress = async (stdin = process.stdin, uiDebugOptions: UIDebugOpt
772772

773773
interface IsTTYOptions {
774774
stdin?: NodeJS.ReadStream
775-
stdout?: NodeJS.WriteStream
776775
uiDebugOptions?: UIDebugOptions
777776
}
778777

779-
export function isTTY({stdin = undefined, stdout, uiDebugOptions = defaultUIDebugOptions}: IsTTYOptions = {}) {
778+
export function isTTY({stdin = undefined, uiDebugOptions = defaultUIDebugOptions}: IsTTYOptions = {}) {
780779
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing -- false should fall through to stdin/terminalSupportsPrompting
781-
return Boolean(uiDebugOptions.skipTTYCheck || stdin || terminalSupportsPrompting({stdout}))
780+
return Boolean(uiDebugOptions.skipTTYCheck || stdin || terminalSupportsPrompting())
782781
}
783782

784783
interface ThrowInNonTTYOptions {
785784
message: TokenItem
786785
stdin?: NodeJS.ReadStream
787-
stdout?: NodeJS.WriteStream
788786
}
789787

790-
function throwInNonTTY({message, stdin = undefined, stdout}: ThrowInNonTTYOptions, uiDebugOptions: UIDebugOptions) {
791-
if (isTTY({stdin, stdout, uiDebugOptions})) return
788+
function throwInNonTTY({message, stdin = undefined}: ThrowInNonTTYOptions, uiDebugOptions: UIDebugOptions) {
789+
if (isTTY({stdin, uiDebugOptions})) return
792790

793791
const promptText = tokenItemToString(message)
794792
const errorMessage = `Failed to prompt:

0 commit comments

Comments
 (0)