diff --git a/.changeset/goofy-colts-sink.md b/.changeset/goofy-colts-sink.md new file mode 100644 index 0000000000..1a6a37423b --- /dev/null +++ b/.changeset/goofy-colts-sink.md @@ -0,0 +1,5 @@ +--- +'@shopify/theme': patch +--- + +Fix issue where certain theme commands were failing to have sessions created diff --git a/packages/cli/oclif.manifest.json b/packages/cli/oclif.manifest.json index bfc1c73c12..dd67769b09 100644 --- a/packages/cli/oclif.manifest.json +++ b/packages/cli/oclif.manifest.json @@ -6326,6 +6326,7 @@ "hiddenAliases": [ ], "id": "theme:init", + "multiEnvironmentsFlags": null, "pluginAlias": "@shopify/cli", "pluginName": "@shopify/cli", "pluginType": "core", @@ -6363,6 +6364,7 @@ "hiddenAliases": [ ], "id": "theme:language-server", + "multiEnvironmentsFlags": null, "pluginAlias": "@shopify/cli", "pluginName": "@shopify/cli", "pluginType": "core", @@ -6705,6 +6707,7 @@ "hiddenAliases": [ ], "id": "theme:package", + "multiEnvironmentsFlags": null, "pluginAlias": "@shopify/cli", "pluginName": "@shopify/cli", "pluginType": "core", diff --git a/packages/theme/src/cli/commands/theme/init.ts b/packages/theme/src/cli/commands/theme/init.ts index 51dd74c6f1..a97206bf85 100644 --- a/packages/theme/src/cli/commands/theme/init.ts +++ b/packages/theme/src/cli/commands/theme/init.ts @@ -1,5 +1,5 @@ import {themeFlags} from '../../flags.js' -import ThemeCommand from '../../utilities/theme-command.js' +import ThemeCommand, {RequiredFlags} from '../../utilities/theme-command.js' import { cloneRepoAndCheckoutLatestTag, cloneRepo, @@ -57,6 +57,8 @@ export default class Init extends ThemeCommand { }), } + static multiEnvironmentsFlags: RequiredFlags = null + async command(flags: InitFlags, _adminSession: AdminSession, _multiEnvironment: boolean, args: InitArgs) { const name = args.name || (await this.promptName(flags.path)) const repoUrl = flags['clone-url'] diff --git a/packages/theme/src/cli/commands/theme/language-server.ts b/packages/theme/src/cli/commands/theme/language-server.ts index 3dfe5d57e5..25f644a8aa 100644 --- a/packages/theme/src/cli/commands/theme/language-server.ts +++ b/packages/theme/src/cli/commands/theme/language-server.ts @@ -1,4 +1,4 @@ -import ThemeCommand from '../../utilities/theme-command.js' +import ThemeCommand, {RequiredFlags} from '../../utilities/theme-command.js' import {globalFlags} from '@shopify/cli-kit/node/cli' import {startServer} from '@shopify/theme-language-server-node' @@ -13,6 +13,8 @@ export default class LanguageServer extends ThemeCommand { ...globalFlags, } + static multiEnvironmentsFlags: RequiredFlags = null + async command() { startServer() } diff --git a/packages/theme/src/cli/commands/theme/package.ts b/packages/theme/src/cli/commands/theme/package.ts index f69abe5926..aaf1303518 100644 --- a/packages/theme/src/cli/commands/theme/package.ts +++ b/packages/theme/src/cli/commands/theme/package.ts @@ -1,5 +1,5 @@ import {themeFlags} from '../../flags.js' -import ThemeCommand from '../../utilities/theme-command.js' +import ThemeCommand, {RequiredFlags} from '../../utilities/theme-command.js' import {packageTheme} from '../../services/package.js' import {globalFlags} from '@shopify/cli-kit/node/cli' import {InferredFlags} from '@oclif/core/interfaces' @@ -23,6 +23,8 @@ export default class Package extends ThemeCommand { path: themeFlags.path, } + static multiEnvironmentsFlags: RequiredFlags = null + async command(flags: PackageFlags) { await packageTheme(flags.path) } diff --git a/packages/theme/src/cli/utilities/theme-command.test.ts b/packages/theme/src/cli/utilities/theme-command.test.ts index 15a71e6aae..60bbb828e4 100644 --- a/packages/theme/src/cli/utilities/theme-command.test.ts +++ b/packages/theme/src/cli/utilities/theme-command.test.ts @@ -137,9 +137,6 @@ class TestThemeCommandWithoutStoreRequired extends ThemeCommand { env: 'SHOPIFY_FLAG_PATH', default: 'current/working/directory', }), - password: Flags.string({ - env: 'SHOPIFY_FLAG_PASSWORD', - }), store: Flags.string({ env: 'SHOPIFY_FLAG_STORE', }), @@ -267,7 +264,7 @@ describe('ThemeCommand', () => { expect(ensureAuthenticatedThemes).not.toHaveBeenCalled() }) - test('single environment provided with store - creates session when store is provided even if not required', async () => { + test('single environment provided with store - does not create session when command does not require auth', async () => { // Given const environmentConfig = {path: '/some/path', store: 'store.myshopify.com'} vi.mocked(loadEnvironment).mockResolvedValue(environmentConfig) @@ -279,9 +276,9 @@ describe('ThemeCommand', () => { await command.run() // Then - expect(ensureAuthenticatedThemes).toHaveBeenCalledOnce() + expect(ensureAuthenticatedThemes).not.toHaveBeenCalled() expect(command.commandCalls).toHaveLength(1) - expect(command.commandCalls[0]?.session).toEqual(mockSession) + expect(command.commandCalls[0]?.session).toBeUndefined() }) test('multiple environments provided - uses renderConcurrent for parallel execution', async () => { diff --git a/packages/theme/src/cli/utilities/theme-command.ts b/packages/theme/src/cli/utilities/theme-command.ts index 52dc617199..930b858581 100644 --- a/packages/theme/src/cli/utilities/theme-command.ts +++ b/packages/theme/src/cli/utilities/theme-command.ts @@ -88,8 +88,7 @@ export default abstract class ThemeCommand extends Command { throw new AbortError(`Please provide a valid environment.`) } - const shouldCreateSession = commandRequiresAuth && (storeIsRequired || flags.store) - const session = shouldCreateSession ? await this.createSession(flags) : undefined + const session = commandRequiresAuth ? await this.createSession(flags) : undefined const commandName = this.constructor.name.toLowerCase() recordEvent(`theme-command:${commandName}:single-env:authenticated`)