From de4f34fe4d51bc7263ee5ce3c7a8da6e6e2a4540 Mon Sep 17 00:00:00 2001 From: Gonzalo Riestra Date: Tue, 26 Nov 2024 09:36:30 +0100 Subject: [PATCH 1/2] Print log messages to stderr --- packages/app/src/cli/services/logs.ts | 6 +++--- packages/cli-kit/src/public/node/output.ts | 14 ++++++-------- packages/theme/src/cli/services/console.ts | 4 ++-- packages/ui-extensions-dev-console/src/App.tsx | 2 +- 4 files changed, 12 insertions(+), 14 deletions(-) diff --git a/packages/app/src/cli/services/logs.ts b/packages/app/src/cli/services/logs.ts index 5d833805866..992677a4ef4 100644 --- a/packages/app/src/cli/services/logs.ts +++ b/packages/app/src/cli/services/logs.ts @@ -8,7 +8,7 @@ import {getAppConfigurationFileName} from '../models/app/loader.js' import {DeveloperPlatformClient} from '../utilities/developer-platform-client.js' import {Organization, OrganizationApp, OrganizationStore} from '../models/organization.js' import {AbortError} from '@shopify/cli-kit/node/error' -import {consoleLog} from '@shopify/cli-kit/node/output' +import {consoleLog, consoleWarn} from '@shopify/cli-kit/node/output' import {renderInfo} from '@shopify/cli-kit/node/ui' import {basename} from '@shopify/cli-kit/node/path' @@ -67,7 +67,7 @@ export async function logs(commandOptions: LogsOptions) { if (commandOptions.format === 'json') { consoleLog(JSON.stringify({subscribedToStores: commandOptions.storeFqdns})) - consoleLog(JSON.stringify({message: 'Waiting for app logs...'})) + consoleWarn(JSON.stringify({message: 'Waiting for app logs...'})) await renderJsonLogs({ options: { variables, @@ -77,7 +77,7 @@ export async function logs(commandOptions: LogsOptions) { storeNameById: logsConfig.storeNameById, }) } else { - consoleLog('Waiting for app logs...\n') + consoleWarn('Waiting for app logs...\n') await renderLogs({ options: { variables, diff --git a/packages/cli-kit/src/public/node/output.ts b/packages/cli-kit/src/public/node/output.ts index 4f1ea228b2d..17702050d7a 100644 --- a/packages/cli-kit/src/public/node/output.ts +++ b/packages/cli-kit/src/public/node/output.ts @@ -245,9 +245,7 @@ export function collectLog(key: string, content: OutputMessage): void { } export const clearCollectedLogs = (): void => { - // console.log('clearCollectLogs') collectedLogs = {} - // console.log(collectedLogs) } /** @@ -258,7 +256,7 @@ export const clearCollectedLogs = (): void => { * @param content - The content to be output to the user. * @param logger - The logging function to use to output to the user. */ -export function outputInfo(content: OutputMessage, logger: Logger = consoleLog): void { +export function outputInfo(content: OutputMessage, logger: Logger = consoleWarn): void { const message = stringifyMessage(content) if (isUnitTest()) collectLog('info', content) outputWhereAppropriate('info', logger, message) @@ -300,7 +298,7 @@ export function outputCompleted(content: OutputMessage, logger: Logger = console * @param content - The content to be output to the user. * @param logger - The logging function to use to output to the user. */ -export function outputDebug(content: OutputMessage, logger: Logger = consoleLog): void { +export function outputDebug(content: OutputMessage, logger: Logger = consoleWarn): void { if (isUnitTest()) collectLog('debug', content) const message = colors.gray(stringifyMessage(content)) outputWhereAppropriate('debug', logger, `${new Date().toISOString()}: ${message}`) @@ -324,7 +322,7 @@ export function outputWarn(content: OutputMessage, logger: Logger = consoleWarn) * Prints a new line in the terminal. */ export function outputNewline(): void { - console.log() + console.warn() } /** @@ -366,7 +364,7 @@ export interface OutputProcess { } /** - * Prints a log message in the console. + * Prints a log message in the console to stdout. * * @param message - The message to print. */ @@ -375,7 +373,7 @@ export function consoleLog(message: string): void { } /** - * Prints an error message in the console. + * Prints an error message in the console to stderr. * * @param message - The message to print. */ @@ -384,7 +382,7 @@ export function consoleError(message: string): void { } /** - * Prints a warning message in the console. + * Prints a warning message in the console to stderr. * * @param message - The message to print. */ diff --git a/packages/theme/src/cli/services/console.ts b/packages/theme/src/cli/services/console.ts index f35d98bcbd6..0f9c6e5dddf 100644 --- a/packages/theme/src/cli/services/console.ts +++ b/packages/theme/src/cli/services/console.ts @@ -4,7 +4,7 @@ import {ensureValidPassword} from '../utilities/theme-environment/storefront-pas import {replLoop} from '../utilities/repl/repl.js' import {initializeDevServerSession} from '../utilities/theme-environment/dev-server-session.js' import {AdminSession} from '@shopify/cli-kit/node/session' -import {consoleLog} from '@shopify/cli-kit/node/output' +import {consoleWarn} from '@shopify/cli-kit/node/output' export async function ensureReplEnv(adminSession: AdminSession, storePasswordFlag?: string) { const themeId = await findOrCreateReplTheme(adminSession) @@ -33,7 +33,7 @@ export async function initializeRepl( themeAccessPassword?: string, storefrontPassword?: string, ) { - consoleLog('Welcome to Shopify Liquid console\n(press Ctrl + C to exit)') + consoleWarn('Welcome to Shopify Liquid console\n(press Ctrl + C to exit)') const session = await initializeDevServerSession(themeId, adminSession, themeAccessPassword, storefrontPassword) diff --git a/packages/ui-extensions-dev-console/src/App.tsx b/packages/ui-extensions-dev-console/src/App.tsx index 26351d66fe1..6915e72c191 100644 --- a/packages/ui-extensions-dev-console/src/App.tsx +++ b/packages/ui-extensions-dev-console/src/App.tsx @@ -29,7 +29,7 @@ const i18nManager = new I18nManager({ locale: 'en', onError(error) { // eslint-disable-next-line no-console - console.log(error) + console.error(error) }, }) From bd3d042abe734d140ce98f238fbfef4f582afb65 Mon Sep 17 00:00:00 2001 From: Gonzalo Riestra Date: Tue, 26 Nov 2024 09:37:37 +0100 Subject: [PATCH 2/2] Add changeset --- .changeset/silent-years-smash.md | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 .changeset/silent-years-smash.md diff --git a/.changeset/silent-years-smash.md b/.changeset/silent-years-smash.md new file mode 100644 index 00000000000..7ed33d90ab8 --- /dev/null +++ b/.changeset/silent-years-smash.md @@ -0,0 +1,8 @@ +--- +'@shopify/ui-extensions-dev-console-app': patch +'@shopify/cli-kit': patch +'@shopify/theme': patch +'@shopify/app': patch +--- + +Print all log messages to stderr instead of stdout