From d198b78d4819428bf8c5b9f87c5ad803be05354c Mon Sep 17 00:00:00 2001 From: FKauwe Date: Fri, 27 Feb 2026 09:47:01 -0800 Subject: [PATCH] fix missing json output for theme info command when dev and theme flags are missing --- .changeset/silver-clouds-smell.md | 5 +++++ packages/theme/src/cli/commands/theme/info.ts | 5 ++++- packages/theme/src/cli/services/info.test.ts | 21 +++++++++++++++++- packages/theme/src/cli/services/info.ts | 22 +++++++++++++++++++ 4 files changed, 51 insertions(+), 2 deletions(-) create mode 100644 .changeset/silver-clouds-smell.md diff --git a/.changeset/silver-clouds-smell.md b/.changeset/silver-clouds-smell.md new file mode 100644 index 00000000000..221b85d9f47 --- /dev/null +++ b/.changeset/silver-clouds-smell.md @@ -0,0 +1,5 @@ +--- +'@shopify/cli': patch +--- + +fix missing json output for theme info when no theme or dev flag is present diff --git a/packages/theme/src/cli/commands/theme/info.ts b/packages/theme/src/cli/commands/theme/info.ts index 56a36833fa3..328eeb2ed57 100644 --- a/packages/theme/src/cli/commands/theme/info.ts +++ b/packages/theme/src/cli/commands/theme/info.ts @@ -1,5 +1,5 @@ import {themeFlags} from '../../flags.js' -import {fetchThemeInfo, fetchDevInfo, formatThemeInfo} from '../../services/info.js' +import {fetchThemeInfo, fetchDevInfo, formatThemeInfo, devInfoJSON} from '../../services/info.js' import ThemeCommand from '../../utilities/theme-command.js' import {Flags} from '@oclif/core' import {AdminSession} from '@shopify/cli-kit/node/session' @@ -50,6 +50,9 @@ export default class Info extends ThemeCommand { renderInfo(formattedInfo) } else { const infoMessage = await fetchDevInfo({cliVersion: this.config.version}) + if (flags.json) { + return outputResult(JSON.stringify(devInfoJSON({cliVersion: this.config.version}), null, 2)) + } renderInfo({customSections: infoMessage}) } recordTiming('theme-command:info') diff --git a/packages/theme/src/cli/services/info.test.ts b/packages/theme/src/cli/services/info.test.ts index f7f95b1bc6e..23ae5bf54ac 100644 --- a/packages/theme/src/cli/services/info.test.ts +++ b/packages/theme/src/cli/services/info.test.ts @@ -1,10 +1,12 @@ -import {themeInfoJSON, fetchThemeInfo} from './info.js' +import {themeInfoJSON, fetchThemeInfo, devInfoJSON} from './info.js' +import {getDevelopmentTheme, getThemeStore} from './local-storage.js' import {findOrSelectTheme} from '../utilities/theme-selector.js' import {DevelopmentThemeManager} from '../utilities/development-theme-manager.js' import {themePreviewUrl, themeEditorUrl} from '@shopify/cli-kit/node/themes/urls' import {Theme} from '@shopify/cli-kit/node/themes/types' import {describe, vi, test, expect} from 'vitest' +vi.mock('./local-storage.js') vi.mock('../utilities/development-theme-manager.js') vi.mock('../utilities/theme-selector.js', () => { return {findOrSelectTheme: vi.fn()} @@ -47,6 +49,23 @@ describe('info', () => { expect(output).toHaveProperty('theme.editor_url', expect.stringContaining(session.storeFqdn)) }) + test('generate dev info JSON when no theme or dev flag provided', () => { + // Given + vi.mocked(getThemeStore).mockReturnValue('my-shop.myshopify.com') + vi.mocked(getDevelopmentTheme).mockReturnValue(undefined) + + // When + const output = devInfoJSON({cliVersion: '3.91.0'}) + + // Then + expect(output).toHaveProperty('store', 'my-shop.myshopify.com') + expect(output).toHaveProperty('development_theme_id', null) + expect(output).toHaveProperty('cli_version', '3.91.0') + expect(output).toHaveProperty('os', expect.stringContaining('-')) + expect(output).toHaveProperty('shell', process.env.SHELL ?? 'unknown') + expect(output).toHaveProperty('node_version', process.version) + }) + test('fetch theme info by id', async () => { // Given vi.mocked(findOrSelectTheme).mockResolvedValue(theme) diff --git a/packages/theme/src/cli/services/info.ts b/packages/theme/src/cli/services/info.ts index ab7c752cc7d..98f5e0e8790 100644 --- a/packages/theme/src/cli/services/info.ts +++ b/packages/theme/src/cli/services/info.ts @@ -28,6 +28,15 @@ interface ThemeInfoOptions { json?: boolean } +interface DevInfo { + store: string + development_theme_id: string | null + cli_version: string + os: string + shell: string + node_version: string +} + export function themeInfoJSON(theme: Theme, adminSession: AdminSession): ThemeInfo { return { theme: { @@ -41,6 +50,19 @@ export function themeInfoJSON(theme: Theme, adminSession: AdminSession): ThemeIn } } +export function devInfoJSON(config: {cliVersion: string}): DevInfo { + const {platform, arch} = platformAndArch() + const store = getThemeStore() + return { + store: store ?? 'Not configured', + development_theme_id: store ? getDevelopmentTheme() ?? null : null, + cli_version: config.cliVersion, + os: `${platform}-${arch}`, + shell: process.env.SHELL ?? 'unknown', + node_version: process.version, + } +} + export async function fetchThemeInfo( adminSession: AdminSession, options: ThemeInfoOptions,