Skip to content

Commit f09a951

Browse files
authored
Merge pull request #5599 from Shopify/fix-shopify-flag-environment
Fixed issue with Shopify flag not being set correctly in the environm…
2 parents 2578ab0 + 8cefc3f commit f09a951

File tree

3 files changed

+34
-2
lines changed

3 files changed

+34
-2
lines changed

Diff for: .changeset/rude-bottles-jog.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@shopify/theme': patch
3+
---
4+
5+
Fixed an issue where CLI would not apply the SHOPIFY_FLAG_ENVIRONMENT flag

Diff for: packages/cli-kit/src/public/node/base-command.test.ts

+24
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,30 @@ describe('applying environments', async () => {
202202
`)
203203
})
204204

205+
runTestInTmpDir(
206+
'base Command does not apply environment specified via environment variable',
207+
async (tmpDir: string) => {
208+
// Given
209+
const environmentName = 'validEnvironmentWithPassword'
210+
const flagName = 'SHOPIFY_FLAG_ENVIRONMENT'
211+
vi.stubEnv(flagName, environmentName)
212+
213+
const outputMock = mockAndCaptureOutput()
214+
outputMock.clear()
215+
216+
// When
217+
await MockCommand.run(['--path', tmpDir])
218+
219+
// Then
220+
expect(testResult.environment).toEqual([])
221+
expect(testResult.password).toBeUndefined()
222+
expect(testResult.someString).toBeUndefined()
223+
expect(testResult.path).toEqual(resolvePath(tmpDir))
224+
expect(testResult.someStringWithDefault).toEqual('default stringy')
225+
expect(outputMock.info()).toEqual('')
226+
},
227+
)
228+
205229
runTestInTmpDir('searches up recursively from path by default', async (tmpDir: string) => {
206230
// Given
207231
const subdir = joinPath(tmpDir, 'somedir', '--environment', 'validEnvironment')

Diff for: packages/theme/src/cli/utilities/theme-command.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -51,15 +51,18 @@ export default abstract class ThemeCommand extends Command {
5151
const {flags} = await this.parse(klass)
5252

5353
// Single environment
54-
if (!Array.isArray(flags.environment)) {
54+
if (!flags.environment) {
5555
const session = await this.ensureAuthenticated(flags)
5656
await this.command(flags, session)
5757
return
5858
}
5959

6060
// Synchronously authenticate all environments
6161
const sessions: {[storeFqdn: string]: AdminSession} = {}
62-
const environments = flags.environment
62+
// OCLIF parses flags.environment as an array when using the --environment & -e flag but
63+
// as a string when using the direct environment variable SHOPIFY_FLAG_ENVIRONMENT
64+
// This handles both cases
65+
const environments = Array.isArray(flags.environment) ? flags.environment : [flags.environment]
6366

6467
// Authenticate on all environments sequentially to avoid race conditions,
6568
// with authentication happening in parallel.

0 commit comments

Comments
 (0)