fix missing json output for theme info command when dev and theme flags are missing#6905
fix missing json output for theme info command when dev and theme flags are missing#6905
Conversation
|
🤖 Code Review · #projects-dev-ai for questions ✅ Complete - No issues 📋 History✅ 1 findings → ✅ No issues |
070e0fa to
d198b78
Compare
|
These findings are in files not modified by this PR and cannot be posted as inline comments.
|
| json?: boolean | ||
| } | ||
|
|
||
| interface DevInfo { |
There was a problem hiding this comment.
Could we rename this to ThemeEnvironmentInfo?
| const store = getThemeStore() | ||
| return { | ||
| store: store ?? 'Not configured', | ||
| development_theme_id: store ? getDevelopmentTheme() ?? null : null, |
There was a problem hiding this comment.
This took me a minute to understand. If you don't want to make it more verbose can we wrap the first part in () so like development_theme_id: store ? (getDevelopmentTheme() ?? null) : null, ? That way you can more easily ready that it's getDevelopmentTheme that may return null OR that if store isn't found we don't want to run that method and skip right to null as well.
| renderInfo(formattedInfo) | ||
| } else { | ||
| const infoMessage = await fetchDevInfo({cliVersion: this.config.version}) | ||
| if (flags.json) { |
There was a problem hiding this comment.
It looks like we're calling flags.json twice now. Can you look into merging that logic?
WHY are these changes introduced?
Fixes #1064 : Theme info not outputting json with the --json flag
I identified that when running
shopify theme info --jsonwithout a--themeor--developmentflag, execution goes to the else branch, which had no JSON handling. TheJSON.stringifylogic only existed in theifbranch (which requires--themeor--development)The
elsebranch had no--jsonhandling at all, so the flag was silently ignored.WHAT is this pull request doing?
I could have chosen to jsonify the existing info message, but this was formulated for the tabular data to output the formatted box in the terminal and looks messy and is more difficult to parse. It would have looked like this:
Click to expand
Output:
I chose to make a new, more easily parse-able json object (following the pattern of the if branch, where a clean object is also created specifically to be consumed by
JSON.stringify). I built a new Interface and function to populate the object inpackages/theme/src/cli/services/info.ts, then consumed it in theelsebranch inpackages/theme/src/cli/commands/theme/info.tsI wrote a new unittest to verify that the JSON conversion is working correctly.
All existing tests pass.
How to test your changes?
while on main, run
shopify theme info --json, should see no json and formulated tabular info like this:then pull down my branch locally,

p build,run
shopify-dev theme info --jsonsee the nice JSON formatting!
Measuring impact
How do we know this change was effective? Please choose one: