Skip to content

Commit 7750c0c

Browse files
committed
fix issue for undefined sessions in theme commands
1 parent 29ed218 commit 7750c0c

7 files changed

Lines changed: 21 additions & 11 deletions

File tree

.changeset/goofy-colts-sink.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@shopify/theme': patch
3+
---
4+
5+
Fix issue where certain theme commands were failing to have sessions created

packages/cli/oclif.manifest.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6326,6 +6326,7 @@
63266326
"hiddenAliases": [
63276327
],
63286328
"id": "theme:init",
6329+
"multiEnvironmentsFlags": null,
63296330
"pluginAlias": "@shopify/cli",
63306331
"pluginName": "@shopify/cli",
63316332
"pluginType": "core",
@@ -6363,6 +6364,7 @@
63636364
"hiddenAliases": [
63646365
],
63656366
"id": "theme:language-server",
6367+
"multiEnvironmentsFlags": null,
63666368
"pluginAlias": "@shopify/cli",
63676369
"pluginName": "@shopify/cli",
63686370
"pluginType": "core",
@@ -6705,6 +6707,7 @@
67056707
"hiddenAliases": [
67066708
],
67076709
"id": "theme:package",
6710+
"multiEnvironmentsFlags": null,
67086711
"pluginAlias": "@shopify/cli",
67096712
"pluginName": "@shopify/cli",
67106713
"pluginType": "core",

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {themeFlags} from '../../flags.js'
2-
import ThemeCommand from '../../utilities/theme-command.js'
2+
import ThemeCommand, {RequiredFlags} from '../../utilities/theme-command.js'
33
import {
44
cloneRepoAndCheckoutLatestTag,
55
cloneRepo,
@@ -57,6 +57,8 @@ export default class Init extends ThemeCommand {
5757
}),
5858
}
5959

60+
static multiEnvironmentsFlags: RequiredFlags = null
61+
6062
async command(flags: InitFlags, _adminSession: AdminSession, _multiEnvironment: boolean, args: InitArgs) {
6163
const name = args.name || (await this.promptName(flags.path))
6264
const repoUrl = flags['clone-url']

packages/theme/src/cli/commands/theme/language-server.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import ThemeCommand from '../../utilities/theme-command.js'
1+
import ThemeCommand, {RequiredFlags} from '../../utilities/theme-command.js'
22
import {globalFlags} from '@shopify/cli-kit/node/cli'
33
import {startServer} from '@shopify/theme-language-server-node'
44

@@ -13,6 +13,8 @@ export default class LanguageServer extends ThemeCommand {
1313
...globalFlags,
1414
}
1515

16+
static multiEnvironmentsFlags: RequiredFlags = null
17+
1618
async command() {
1719
startServer()
1820
}

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {themeFlags} from '../../flags.js'
2-
import ThemeCommand from '../../utilities/theme-command.js'
2+
import ThemeCommand, {RequiredFlags} from '../../utilities/theme-command.js'
33
import {packageTheme} from '../../services/package.js'
44
import {globalFlags} from '@shopify/cli-kit/node/cli'
55
import {InferredFlags} from '@oclif/core/interfaces'
@@ -23,6 +23,8 @@ export default class Package extends ThemeCommand {
2323
path: themeFlags.path,
2424
}
2525

26+
static multiEnvironmentsFlags: RequiredFlags = null
27+
2628
async command(flags: PackageFlags) {
2729
await packageTheme(flags.path)
2830
}

packages/theme/src/cli/utilities/theme-command.test.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -137,9 +137,6 @@ class TestThemeCommandWithoutStoreRequired extends ThemeCommand {
137137
env: 'SHOPIFY_FLAG_PATH',
138138
default: 'current/working/directory',
139139
}),
140-
password: Flags.string({
141-
env: 'SHOPIFY_FLAG_PASSWORD',
142-
}),
143140
store: Flags.string({
144141
env: 'SHOPIFY_FLAG_STORE',
145142
}),
@@ -267,7 +264,7 @@ describe('ThemeCommand', () => {
267264
expect(ensureAuthenticatedThemes).not.toHaveBeenCalled()
268265
})
269266

270-
test('single environment provided with store - creates session when store is provided even if not required', async () => {
267+
test('single environment provided with store - does not create session when command does not require auth', async () => {
271268
// Given
272269
const environmentConfig = {path: '/some/path', store: 'store.myshopify.com'}
273270
vi.mocked(loadEnvironment).mockResolvedValue(environmentConfig)
@@ -279,9 +276,9 @@ describe('ThemeCommand', () => {
279276
await command.run()
280277

281278
// Then
282-
expect(ensureAuthenticatedThemes).toHaveBeenCalledOnce()
279+
expect(ensureAuthenticatedThemes).not.toHaveBeenCalled()
283280
expect(command.commandCalls).toHaveLength(1)
284-
expect(command.commandCalls[0]?.session).toEqual(mockSession)
281+
expect(command.commandCalls[0]?.session).toBeUndefined()
285282
})
286283

287284
test('multiple environments provided - uses renderConcurrent for parallel execution', async () => {

packages/theme/src/cli/utilities/theme-command.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,7 @@ export default abstract class ThemeCommand extends Command {
8888
throw new AbortError(`Please provide a valid environment.`)
8989
}
9090

91-
const shouldCreateSession = commandRequiresAuth && (storeIsRequired || flags.store)
92-
const session = shouldCreateSession ? await this.createSession(flags) : undefined
91+
const session = commandRequiresAuth ? await this.createSession(flags) : undefined
9392
const commandName = this.constructor.name.toLowerCase()
9493

9594
recordEvent(`theme-command:${commandName}:single-env:authenticated`)

0 commit comments

Comments
 (0)