@@ -14,7 +14,7 @@ commands; remove each entry when converted, and never add new finite commands to
1414## Define the result beside the domain service
1515
1616Keep the schema beside the service that produces the result. One Zod schema supplies runtime validation, the inferred
17- TypeScript type, JSON encoding, and the type shown in command help.
17+ TypeScript type, JSON encoding, and the JSON Schema shown in command help.
1818
1919``` ts
2020import {defineJsonOutputSchema , type InferJsonOutputSchema } from ' @shopify/cli-kit/node/json-output-schema'
@@ -34,8 +34,8 @@ export const widgetListJsonOutputSchema = defineJsonOutputSchema({
3434export type WidgetListResult = InferJsonOutputSchema <typeof widgetListJsonOutputSchema >
3535` ` `
3636
37- Add nested object schemas to ` definitions ` so generated help gives them stable names. Use ` . passthrough () ` only when
38- the public result deliberately permits additional keys.
37+ Optionally add nested object schemas to ` definitions ` to give them stable names and references in JSON Schema.
38+ Use ` . passthrough () ` only when the public result deliberately permits additional keys.
3939
4040## Connect the command and encoder
4141
@@ -75,8 +75,8 @@ Presenters continue to own terminal text, output channels, files, and exit behav
7575on terminal rendering (including React/Ink), Oclif, filesystem output, or CLI errors.
7676
7777Events are separate from finite results. Progress events can drive spinners or status messages while the command is
78- running, but they aren't fields in the final JSON result. Errors continue through the standard CLI error path and
79- stderr; don't encode failures as successful result shapes merely to support ` --json ` .
78+ running, but they aren't fields in the final JSON result. Errors continue through the standard CLI error path;
79+ don't encode failures as successful result shapes merely to support ` --json ` .
8080
8181## Preserve compatibility
8282
@@ -104,6 +104,22 @@ The lint rule only exempts paths in that list; a `jsonOutputSupport` property al
104104This exemption is only for commands whose lifetime or output is inherently streaming. A finite operation remains a
105105finite command even when it emits progress events, writes a file, or has no interesting return value.
106106
107+ ## Plugin authors
108+
109+ Plugins must adopt the result contract and control their output before their commands can be used reliably in JSON
110+ mode. Inheriting ` --json-schema ` or enabling ` SHOPIFY_FLAG_JSON=1 ` doesn't convert all plugin output automatically.
111+
112+ - Oclif ` init ` hooks run before the command's error handling. A hook that renders a warning and calls ` process.exit(1) `
113+ bypasses the JSON fatal error path and can leave stdout empty. Put command validation in the command lifecycle and
114+ throw an ` AbortError ` so CLI Kit can encode the failure.
115+ - In the command event context, ` outputInfo ` , ` outputWarn ` , and ` outputDebug ` use diagnostic events in JSON mode when
116+ using their default logger. Banners such as ` renderSuccess ` and ` renderWarning ` still render terminal text to stderr;
117+ they aren't automatically converted to events. Use ` emitCommandEvent ` from ` @shopify/cli-kit/node/command-events `
118+ for diagnostics, and keep human-only banners in the text presenter.
119+ - Third-party loggers and child processes aren't automatically converted or silenced. Use ` jsonOutputEnabled() ` from
120+ ` @shopify/cli-kit/node/environment ` to silence or capture their output in JSON mode. Reserve stdout for the encoded
121+ result or fatal error document, and send diagnostics through the event helpers to stderr.
122+
107123## Test a new command
108124
109125Tests should verify:
@@ -115,5 +131,9 @@ Tests should verify:
115131- errors and exit behavior; and
116132- prompt behavior independently from ` --json ` and ` --no-input ` .
117133
118- Command help includes the generated TypeScript contract automatically through ` jsonOutputSchema ` . Run the manifest,
134+ Command help includes the result's JSON Schema automatically through ` jsonOutputSchema ` . ` --json-schema ` prints one
135+ JSON Schema (draft-07) accepting a result, a fatal error document, or a side event. The ` Result ` , ` Error ` , and ` Event `
136+ definitions describe these separately; results and fatal errors go to stdout, and side events go to stderr.
137+
138+ Both outputs come from the same Zod definitions used to validate and encode results. Run the manifest,
119139README, and code-documentation refresh commands required by CI after changing command metadata.
0 commit comments