Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/json-success-diagnostics.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@shopify/cli': patch
'@shopify/cli-kit': patch
---

Route success banners through JSON diagnostics.
6 changes: 3 additions & 3 deletions docs/cli/json-output.md
Original file line number Diff line number Diff line change
Expand Up @@ -300,9 +300,9 @@ mode. Inheriting `--json-schema` or enabling `SHOPIFY_FLAG_JSON=1` doesn't conve
bypasses the JSON fatal error path and can leave stdout empty. Put command validation in the command lifecycle and
throw an `AbortError` so CLI Kit can encode the failure.
- In the command event context, `outputInfo`, `outputWarn`, and `outputDebug` use diagnostic events in JSON mode when
using their default logger. `renderInfo` and `renderWarning` also emit diagnostic events on stderr in JSON mode,
retaining their banners in text mode. Their messages include the alert's body, next steps, references, links, and
custom sections. `renderSuccess` and `renderError` still render terminal text; keep these banners in text presenters.
using their default logger. `renderInfo`, `renderWarning`, and `renderSuccess` also emit diagnostic events on stderr
in JSON mode, retaining their banners in text mode. Their messages include the alert's body, next steps, references,
links, and custom sections. `renderError` still renders terminal text; keep this banner in text presenters.
- Third-party loggers and child processes aren't automatically converted or silenced. Use `jsonOutputEnabled()` from
`@shopify/cli-kit/node/environment` to silence or capture their output in JSON mode. Reserve stdout for the encoded
result or fatal error document, and send diagnostics through the event helpers to stderr.
Expand Down
2 changes: 1 addition & 1 deletion packages/cli-kit/src/private/node/ui/alert.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export function alert(options: AlertOptions) {
renderOptions,
} = options

if ((type === 'info' || type === 'warning') && commandEventOutputMode() === 'json') {
if ((type === 'info' || type === 'warning' || type === 'success') && commandEventOutputMode() === 'json') {
const message = alertMessage(options)
if (type === 'warning') outputWarn(message)
else outputInfo(message)
Expand Down
23 changes: 14 additions & 9 deletions packages/cli-kit/src/public/node/ui.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -247,11 +247,12 @@ describe('renderWarning', async () => {
})
})

describe('info and warning diagnostics', () => {
describe('alert diagnostics', () => {
test.each([
{renderAlert: renderInfo, level: 'info'},
{renderAlert: renderWarning, level: 'warning'},
] as const)('writes $level alerts as JSON on stderr with --json', async ({renderAlert, level}) => {
{renderAlert: renderInfo, type: 'info', level: 'info'},
{renderAlert: renderWarning, type: 'warning', level: 'warning'},
{renderAlert: renderSuccess, type: 'success', level: 'info'},
] as const)('writes $type alerts as JSON on stderr with --json', async ({renderAlert, level}) => {
await withCapturedStandardStreams(({stdout, stderr}) => {
runWithCommandEventsForCommand(['--json'], () => {
renderAlert({headline: 'Scan directory ignored', body: ['Use', {command: '--no-git-ignore'}]})
Expand Down Expand Up @@ -317,17 +318,21 @@ describe('info and warning diagnostics', () => {
})
})

test.each([renderInfo, renderWarning])('does not emit a diagnostic for an empty alert', (renderAlert) => {
const sink = vi.fn()
test.each([renderInfo, renderWarning, renderSuccess])(
'does not emit a diagnostic for an empty alert',
(renderAlert) => {
const sink = vi.fn()

runWithCommandEvents({outputMode: 'json', sink}, () => renderAlert({}))
runWithCommandEvents({outputMode: 'json', sink}, () => renderAlert({}))

expect(sink).not.toHaveBeenCalled()
})
expect(sink).not.toHaveBeenCalled()
},
)

test.each([
{renderAlert: renderInfo, banner: 'info'},
{renderAlert: renderWarning, banner: 'warning'},
{renderAlert: renderSuccess, banner: 'success'},
])('keeps the $banner banner on stderr in text mode', async ({renderAlert, banner}) => {
await withCapturedStandardStreams(({stdout, stderr}) => {
runWithCommandEvents({outputMode: 'text'}, () => renderAlert({headline: 'Title', body: 'Body'}))
Expand Down
Loading