Skip to content

Commit af1e6d1

Browse files
committed
Prefer output* functions over console* functions
1 parent 8593dd2 commit af1e6d1

File tree

10 files changed

+42
-44
lines changed

10 files changed

+42
-44
lines changed

packages/app/src/cli/services/logs.test.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {
1111
testOrganizationStore,
1212
} from '../models/app/app.test-data.js'
1313
import {DeveloperPlatformClient} from '../utilities/developer-platform-client.js'
14-
import {consoleLog, consoleWarn} from '@shopify/cli-kit/node/output'
14+
import {outputInfo, outputResult} from '@shopify/cli-kit/node/output'
1515
import {AbortError} from '@shopify/cli-kit/node/error'
1616
import {describe, test, vi, expect, beforeEach} from 'vitest'
1717
import {renderInfo} from '@shopify/cli-kit/node/ui'
@@ -54,7 +54,7 @@ describe('logs', () => {
5454
})
5555

5656
// Then
57-
expect(consoleWarn).toHaveBeenCalledWith('{"message":"Waiting for app logs..."}')
57+
expect(outputInfo).toHaveBeenCalledWith('{"message":"Waiting for app logs..."}')
5858
expect(spy).toHaveBeenCalled()
5959
})
6060

@@ -78,7 +78,7 @@ describe('logs', () => {
7878
})
7979

8080
// Then
81-
expect(consoleWarn).toHaveBeenCalledWith('Waiting for app logs...\n')
81+
expect(outputInfo).toHaveBeenCalledWith('Waiting for app logs...\n')
8282
expect(spy).toHaveBeenCalled()
8383
})
8484

@@ -156,8 +156,8 @@ describe('logs', () => {
156156
const expectedStoreMap = new Map()
157157
expectedStoreMap.set('1', 'store-fqdn')
158158
expectedStoreMap.set('2', 'other-fqdn')
159-
expect(consoleLog).toHaveBeenCalledWith('{"subscribedToStores":["store-fqdn","other-fqdn"]}')
160-
expect(consoleWarn).toHaveBeenCalledWith('{"message":"Waiting for app logs..."}')
159+
expect(outputResult).toHaveBeenCalledWith('{"subscribedToStores":["store-fqdn","other-fqdn"]}')
160+
expect(outputInfo).toHaveBeenCalledWith('{"message":"Waiting for app logs..."}')
161161
expect(spy).toHaveBeenCalledWith({
162162
options: {
163163
developerPlatformClient: expect.anything(),
@@ -193,7 +193,7 @@ describe('logs', () => {
193193
const expectedStoreMap = new Map()
194194
expectedStoreMap.set('1', 'store-fqdn')
195195
expectedStoreMap.set('2', 'other-fqdn')
196-
expect(consoleWarn).toHaveBeenCalledWith('Waiting for app logs...\n')
196+
expect(outputInfo).toHaveBeenCalledWith('Waiting for app logs...\n')
197197
expect(spy).toHaveBeenCalledWith({
198198
options: {
199199
developerPlatformClient: expect.anything(),

packages/app/src/cli/services/logs.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {getAppConfigurationFileName} from '../models/app/loader.js'
88
import {DeveloperPlatformClient} from '../utilities/developer-platform-client.js'
99
import {Organization, OrganizationApp, OrganizationStore} from '../models/organization.js'
1010
import {AbortError} from '@shopify/cli-kit/node/error'
11-
import {consoleLog, consoleWarn} from '@shopify/cli-kit/node/output'
11+
import {outputInfo, outputResult} from '@shopify/cli-kit/node/output'
1212
import {renderInfo} from '@shopify/cli-kit/node/ui'
1313
import {basename} from '@shopify/cli-kit/node/path'
1414

@@ -66,8 +66,8 @@ export async function logs(commandOptions: LogsOptions) {
6666
}
6767

6868
if (commandOptions.format === 'json') {
69-
consoleLog(JSON.stringify({subscribedToStores: commandOptions.storeFqdns}))
70-
consoleWarn(JSON.stringify({message: 'Waiting for app logs...'}))
69+
outputResult(JSON.stringify({subscribedToStores: commandOptions.storeFqdns}))
70+
outputInfo(JSON.stringify({message: 'Waiting for app logs...'}))
7171
await renderJsonLogs({
7272
options: {
7373
variables,
@@ -77,7 +77,7 @@ export async function logs(commandOptions: LogsOptions) {
7777
storeNameById: logsConfig.storeNameById,
7878
})
7979
} else {
80-
consoleWarn('Waiting for app logs...\n')
80+
outputInfo('Waiting for app logs...\n')
8181
await renderLogs({
8282
options: {
8383
variables,

packages/app/src/cli/services/webhook/trigger.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {
1010
testOrganizationApp,
1111
} from '../../models/app/app.test-data.js'
1212
import {loadApp} from '../../models/app/loader.js'
13-
import {outputSuccess, consoleError} from '@shopify/cli-kit/node/output'
13+
import {outputSuccess, outputWarn} from '@shopify/cli-kit/node/output'
1414
import {describe, expect, vi, test, beforeEach} from 'vitest'
1515

1616
const samplePayload = '{ "sampleField": "SampleValue" }'
@@ -83,7 +83,7 @@ describe('webhookTriggerService', () => {
8383

8484
// Then
8585
expectCalls(aVersion, anOrganizationId)
86-
expect(consoleError).toHaveBeenCalledWith(`Request errors:\n · Some error\n · Another error`)
86+
expect(outputWarn).toHaveBeenCalledWith(`Request errors:\n · Some error\n · Another error`)
8787
})
8888

8989
test('Safe notification in case of unexpected request errors', async () => {
@@ -106,7 +106,7 @@ describe('webhookTriggerService', () => {
106106

107107
// Then
108108
expectCalls(aVersion, anOrganizationId)
109-
expect(consoleError).toHaveBeenCalledWith(`Request errors:\n${JSON.stringify(response.userErrors)}`)
109+
expect(outputWarn).toHaveBeenCalledWith(`Request errors:\n${JSON.stringify(response.userErrors)}`)
110110
})
111111

112112
test('notifies about real delivery being sent', async () => {
@@ -240,7 +240,7 @@ describe('webhookTriggerService', () => {
240240
anOrganizationId,
241241
)
242242
expect(triggerLocalWebhook).toHaveBeenCalledWith(aFullLocalAddress, samplePayload, sampleHeaders)
243-
expect(consoleError).toHaveBeenCalledWith('Localhost delivery failed')
243+
expect(outputWarn).toHaveBeenCalledWith('Localhost delivery failed')
244244
})
245245
})
246246

packages/app/src/cli/services/webhook/trigger.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {collectAddressAndMethod, collectApiVersion, collectCredentials, collectT
55
import {DeveloperPlatformClient} from '../../utilities/developer-platform-client.js'
66
import {AppLinkedInterface} from '../../models/app/app.js'
77
import {OrganizationApp} from '../../models/organization.js'
8-
import {consoleError, outputSuccess} from '@shopify/cli-kit/node/output'
8+
import {outputWarn, outputSuccess} from '@shopify/cli-kit/node/output'
99

1010
export interface WebhookTriggerInput {
1111
app: AppLinkedInterface
@@ -76,7 +76,7 @@ async function sendSample(options: WebhookTriggerOptions) {
7676
const sample = await getWebhookSample(options.developerPlatformClient, variables, options.organizationId)
7777

7878
if (!sample.success) {
79-
consoleError(`Request errors:\n${formatErrors(sample.userErrors)}`)
79+
outputWarn(`Request errors:\n${formatErrors(sample.userErrors)}`)
8080
return
8181
}
8282

@@ -88,7 +88,7 @@ async function sendSample(options: WebhookTriggerOptions) {
8888
return
8989
}
9090

91-
consoleError('Localhost delivery failed')
91+
outputWarn('Localhost delivery failed')
9292
return
9393
}
9494

packages/theme/src/cli/commands/theme/check.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import {
1515
import ThemeCommand from '../../utilities/theme-command.js'
1616
import {Flags} from '@oclif/core'
1717
import {globalFlags} from '@shopify/cli-kit/node/cli'
18-
import {outputResult, consoleError} from '@shopify/cli-kit/node/output'
18+
import {outputResult, outputDebug} from '@shopify/cli-kit/node/output'
1919
import {renderInfo, renderSuccess} from '@shopify/cli-kit/node/ui'
2020
import {themeCheckRun, LegacyIdentifiers} from '@shopify/theme-check-node'
2121
import {findPathUp} from '@shopify/cli-kit/node/fs'
@@ -146,11 +146,8 @@ export default class Check extends ThemeCommand {
146146

147147
export async function runThemeCheck(path: string, outputFormat: string, config?: string) {
148148
const {offenses, theme} = await themeCheckRun(path, config, (message) => {
149-
// We should replace this with outputDebug when it logs to STDERR by default.
150-
// We need this right now because the --verbose flags pollutes STDOUT
151-
// when used with --output=json with the current outputDebug defaults.
152149
if (process.env.SHOPIFY_TMP_FLAG_DEBUG) {
153-
consoleError(message)
150+
outputDebug(message)
154151
}
155152
})
156153

packages/theme/src/cli/services/console.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import {ensureValidPassword} from '../utilities/theme-environment/storefront-pas
44
import {replLoop} from '../utilities/repl/repl.js'
55
import {initializeDevServerSession} from '../utilities/theme-environment/dev-server-session.js'
66
import {AdminSession} from '@shopify/cli-kit/node/session'
7-
import {consoleWarn} from '@shopify/cli-kit/node/output'
7+
import {outputInfo} from '@shopify/cli-kit/node/output'
88

99
export async function ensureReplEnv(adminSession: AdminSession, storePasswordFlag?: string) {
1010
const themeId = await findOrCreateReplTheme(adminSession)
@@ -33,7 +33,7 @@ export async function initializeRepl(
3333
themeAccessPassword?: string,
3434
storefrontPassword?: string,
3535
) {
36-
consoleWarn('Welcome to Shopify Liquid console\n(press Ctrl + C to exit)')
36+
outputInfo('Welcome to Shopify Liquid console\n(press Ctrl + C to exit)')
3737

3838
const session = await initializeDevServerSession(themeId, adminSession, themeAccessPassword, storefrontPassword)
3939

packages/theme/src/cli/utilities/repl/presenter.test.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
import {presentValue} from './presenter.js'
2-
import {consoleWarn, outputContent, outputInfo, outputToken} from '@shopify/cli-kit/node/output'
2+
import {outputContent, outputInfo, outputToken} from '@shopify/cli-kit/node/output'
33
import {describe, expect, test, vi} from 'vitest'
44

55
vi.mock('@shopify/cli-kit/node/output')
66

77
describe('presentValue', () => {
8+
const cantBePrintedMessage =
9+
"Object can't be printed, but you can access its fields. Read more at https://shopify.dev/docs/api/liquid."
10+
811
test('should print a warning message if value has a JSON error', () => {
912
// Given
1013
const value = {error: 'json not allowed for this object'}
@@ -13,10 +16,8 @@ describe('presentValue', () => {
1316
presentValue(value)
1417

1518
// Then
16-
expect(consoleWarn).toHaveBeenCalledWith(
17-
"Object can't be printed, but you can access its fields. Read more at https://shopify.dev/docs/api/liquid.",
18-
)
19-
expect(outputInfo).not.toHaveBeenCalled()
19+
expect(outputInfo).toHaveBeenCalledOnce()
20+
expect(outputInfo).toHaveBeenCalledWith(cantBePrintedMessage)
2021
})
2122

2223
test('should print "null" if value is undefined', () => {
@@ -28,7 +29,7 @@ describe('presentValue', () => {
2829

2930
// Then
3031
expect(outputInfo).toHaveBeenCalledWith(outputContent`${outputToken.cyan('null')}`)
31-
expect(consoleWarn).not.toHaveBeenCalled()
32+
expect(outputInfo).not.toHaveBeenCalledWith(cantBePrintedMessage)
3233
})
3334

3435
test('should print "null" if value is null', () => {
@@ -40,7 +41,7 @@ describe('presentValue', () => {
4041

4142
// Then
4243
expect(outputInfo).toHaveBeenCalledWith(outputContent`${outputToken.cyan('null')}`)
43-
expect(consoleWarn).not.toHaveBeenCalled()
44+
expect(outputInfo).not.toHaveBeenCalledWith(cantBePrintedMessage)
4445
})
4546

4647
test('should print the formatted output if value is not undefined, null, or has a JSON error', () => {
@@ -53,6 +54,6 @@ describe('presentValue', () => {
5354

5455
// Then
5556
expect(outputInfo).toHaveBeenCalledWith(outputContent`${outputToken.cyan(formattedOutput)}`)
56-
expect(consoleWarn).not.toHaveBeenCalled()
57+
expect(outputInfo).not.toHaveBeenCalledWith(cantBePrintedMessage)
5758
})
5859
})

packages/theme/src/cli/utilities/repl/presenter.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import {consoleWarn, outputContent, outputInfo, outputToken} from '@shopify/cli-kit/node/output'
1+
import {outputContent, outputInfo, outputToken} from '@shopify/cli-kit/node/output'
22

33
export function presentValue(value?: unknown) {
44
if (hasJsonError(value)) {
5-
consoleWarn(
5+
outputInfo(
66
"Object can't be printed, but you can access its fields. Read more at https://shopify.dev/docs/api/liquid.",
77
)
88
return

packages/theme/src/cli/utilities/repl/repl.test.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import {evaluate} from './evaluator.js'
33
import {presentValue} from './presenter.js'
44
import {DevServerSession} from '../theme-environment/types.js'
55
import {describe, expect, test, vi} from 'vitest'
6-
import {consoleWarn} from '@shopify/cli-kit/node/output'
6+
import {outputInfo} from '@shopify/cli-kit/node/output'
77
import {createInterface} from 'readline'
88

99
vi.mock('@shopify/cli-kit/node/output')
@@ -25,37 +25,37 @@ describe('handleInput', () => {
2525
output: process.stdout,
2626
})
2727

28-
test('should call consoleWarn if input has {{ delimiter', async () => {
28+
test('should call outputInfo if input has {{ delimiter', async () => {
2929
// Given
3030
const inputValue = '{{ collections.first }}'
3131

3232
// When
3333
await handleInput(inputValue, themeSesssion, themeId, url, rl, [])
3434

3535
// Then
36-
expect(consoleWarn).toHaveBeenCalledWith(DELIMITER_WARNING_MESSAGE)
36+
expect(outputInfo).toHaveBeenCalledWith(DELIMITER_WARNING_MESSAGE)
3737
})
3838

39-
test('should call consoleWarn if input has {% delimiter', async () => {
39+
test('should call outputInfo if input has {% delimiter', async () => {
4040
// Given
4141
const inputValue = '{%'
4242

4343
// When
4444
await handleInput(inputValue, themeSesssion, themeId, url, rl, [])
4545

4646
// Then
47-
expect(consoleWarn).toHaveBeenCalledWith(DELIMITER_WARNING_MESSAGE)
47+
expect(outputInfo).toHaveBeenCalledWith(DELIMITER_WARNING_MESSAGE)
4848
})
4949

50-
test('should not call consoleWarn if {{ delimiter is wrapped in quotes', async () => {
50+
test('should not call outputInfo if {{ delimiter is wrapped in quotes', async () => {
5151
// Given
5252
const inputValue = '"{{ collections.first }}"'
5353

5454
// When
5555
await handleInput(inputValue, themeSesssion, themeId, url, rl, [])
5656

5757
// Then
58-
expect(consoleWarn).not.toHaveBeenCalled()
58+
expect(outputInfo).not.toHaveBeenCalled()
5959
})
6060

6161
test('should call evaluate, presentValue, and prompt readline if input is valid', async () => {
@@ -66,7 +66,7 @@ describe('handleInput', () => {
6666
await handleInput(inputValue, themeSesssion, themeId, url, rl, [])
6767

6868
// Then
69-
expect(consoleWarn).not.toHaveBeenCalled()
69+
expect(outputInfo).not.toHaveBeenCalled()
7070
expect(evaluate).toHaveBeenCalled()
7171
expect(presentValue).toHaveBeenCalled()
7272
})

packages/theme/src/cli/utilities/repl/repl.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import {evaluate, SessionItem} from './evaluator.js'
22
import {presentValue} from './presenter.js'
33
import {DevServerSession} from '../theme-environment/types.js'
44
import {AbortSilentError} from '@shopify/cli-kit/node/error'
5-
import {consoleWarn, outputContent, outputDebug, outputInfo, outputToken} from '@shopify/cli-kit/node/output'
5+
import {outputContent, outputDebug, outputInfo, outputToken} from '@shopify/cli-kit/node/output'
66
import {createInterface, Interface} from 'readline'
77

88
export const DELIMITER_WARNING =
@@ -38,7 +38,7 @@ export async function handleInput(
3838
) {
3939
try {
4040
if (hasDelimiter(inputValue)) {
41-
consoleWarn(DELIMITER_WARNING)
41+
outputInfo(DELIMITER_WARNING)
4242
return rl.prompt()
4343
}
4444
const evaluatedValue = await evaluate({snippet: inputValue, themeSession, themeId, url, replSession})

0 commit comments

Comments
 (0)