diff --git a/.changeset/fifty-plants-ask.md b/.changeset/fifty-plants-ask.md new file mode 100644 index 00000000000..734b41ca69f --- /dev/null +++ b/.changeset/fifty-plants-ask.md @@ -0,0 +1,5 @@ +--- +'@shopify/theme': patch +--- + +Abort theme command when an invalid environment is passed in so it doesn't fall back to cached store data diff --git a/packages/theme/src/cli/utilities/theme-command.test.ts b/packages/theme/src/cli/utilities/theme-command.test.ts index 19dba7939e2..c4492d8d8e1 100644 --- a/packages/theme/src/cli/utilities/theme-command.test.ts +++ b/packages/theme/src/cli/utilities/theme-command.test.ts @@ -191,6 +191,18 @@ describe('ThemeCommand', () => { }) }) + test('single environment provided but not found in TOML - throws AbortError', async () => { + // Given + vi.mocked(loadEnvironment).mockResolvedValue(undefined) + + await CommandConfig.load() + const command = new TestThemeCommand(['--environment', 'notreal'], CommandConfig) + + // When/Then + await expect(command.run()).rejects.toThrow(AbortError) + await expect(command.run()).rejects.toThrow('Please provide a valid environment.') + }) + test('multiple environments provided - uses renderConcurrent for parallel execution', async () => { // Given vi.mocked(loadEnvironment) diff --git a/packages/theme/src/cli/utilities/theme-command.ts b/packages/theme/src/cli/utilities/theme-command.ts index 575bda490e3..b03a3fa5159 100644 --- a/packages/theme/src/cli/utilities/theme-command.ts +++ b/packages/theme/src/cli/utilities/theme-command.ts @@ -79,6 +79,10 @@ export default abstract class ThemeCommand extends Command { // Single environment or no environment if (environments.length <= 1) { + if (environments[0] && !flags.store) { + throw new AbortError(`Please provide a valid environment.`) + } + const session = commandRequiresAuth ? await this.createSession(flags) : undefined const commandName = this.constructor.name.toLowerCase()