From 18e3f6c2af4be6a904969b603b2c209965f31ee0 Mon Sep 17 00:00:00 2001 From: rbshop Date: Mon, 14 Oct 2024 12:13:06 +0100 Subject: [PATCH 1/7] Remove deprecated --worker cli flag --- packages/cli/oclif.manifest.json | 10 ---------- packages/cli/src/commands/hydrogen/dev.ts | 1 - packages/cli/src/commands/hydrogen/preview.ts | 1 - 3 files changed, 12 deletions(-) diff --git a/packages/cli/oclif.manifest.json b/packages/cli/oclif.manifest.json index 3d5ae2e224..fb4e2cd139 100644 --- a/packages/cli/oclif.manifest.json +++ b/packages/cli/oclif.manifest.json @@ -669,11 +669,6 @@ "allowNo": false, "type": "boolean" }, - "worker": { - "hidden": true, - "name": "worker", - "type": "boolean" - }, "legacy-runtime": { "description": "[Classic Remix Compiler] Runs the app in a Node.js sandbox instead of an Oxygen worker.", "env": "SHOPIFY_HYDROGEN_FLAG_LEGACY_RUNTIME", @@ -1323,11 +1318,6 @@ "multiple": false, "type": "option" }, - "worker": { - "hidden": true, - "name": "worker", - "type": "boolean" - }, "legacy-runtime": { "description": "Runs the app in a Node.js sandbox instead of an Oxygen worker.", "env": "SHOPIFY_HYDROGEN_FLAG_LEGACY_RUNTIME", diff --git a/packages/cli/src/commands/hydrogen/dev.ts b/packages/cli/src/commands/hydrogen/dev.ts index 504c0ce14e..2f2268b373 100644 --- a/packages/cli/src/commands/hydrogen/dev.ts +++ b/packages/cli/src/commands/hydrogen/dev.ts @@ -99,7 +99,6 @@ export default class Dev extends Command { }), // For the classic compiler: - worker: deprecated('--worker', {isBoolean: true}), ...overrideFlag(commonFlags.legacyRuntime, { 'legacy-runtime': { description: diff --git a/packages/cli/src/commands/hydrogen/preview.ts b/packages/cli/src/commands/hydrogen/preview.ts index ceb2fec09a..5e77b63348 100644 --- a/packages/cli/src/commands/hydrogen/preview.ts +++ b/packages/cli/src/commands/hydrogen/preview.ts @@ -33,7 +33,6 @@ export default class Preview extends Command { static flags = { ...commonFlags.path, ...commonFlags.port, - worker: deprecated('--worker', {isBoolean: true}), ...commonFlags.legacyRuntime, ...commonFlags.env, ...commonFlags.envBranch, From b8810137c661d797de9faae3256bb74458d3d010 Mon Sep 17 00:00:00 2001 From: rbshop Date: Mon, 14 Oct 2024 12:47:00 +0100 Subject: [PATCH 2/7] Remove deprecated --env-branch cli flag --- packages/cli/oclif.manifest.json | 65 +--------------- .../cli/src/commands/hydrogen/deploy.test.ts | 77 ------------------- packages/cli/src/commands/hydrogen/deploy.ts | 15 +--- packages/cli/src/commands/hydrogen/dev.ts | 4 - .../src/commands/hydrogen/env/pull.test.ts | 20 ----- .../cli/src/commands/hydrogen/env/pull.ts | 14 +--- packages/cli/src/commands/hydrogen/preview.ts | 4 - packages/cli/src/lib/classic-compiler/dev.ts | 4 - .../cli/src/lib/environment-variables.test.ts | 18 +---- packages/cli/src/lib/environment-variables.ts | 42 +++------- packages/cli/src/lib/flags.ts | 15 ---- 11 files changed, 17 insertions(+), 261 deletions(-) diff --git a/packages/cli/oclif.manifest.json b/packages/cli/oclif.manifest.json index fb4e2cd139..7d1d1e4b80 100644 --- a/packages/cli/oclif.manifest.json +++ b/packages/cli/oclif.manifest.json @@ -340,26 +340,11 @@ }, "env": { "description": "Specifies the environment to perform the operation using its handle. Fetch the handle using the `env list` command.", - "exclusive": [ - "env-branch" - ], "name": "env", "hasDynamicHelp": false, "multiple": false, "type": "option" }, - "env-branch": { - "deprecated": { - "to": "env", - "message": "--env-branch is deprecated. Use --env instead." - }, - "description": "Specifies the environment to perform the operation using its Git branch name.", - "env": "SHOPIFY_HYDROGEN_ENVIRONMENT_BRANCH", - "name": "env-branch", - "hasDynamicHelp": false, - "multiple": false, - "type": "option" - }, "env-file": { "description": "Path to an environment file to override existing environment variables for the deployment.", "name": "env-file", @@ -369,7 +354,7 @@ "type": "option" }, "preview": { - "description": "Deploys to the Preview environment. Overrides --env-branch and Git metadata.", + "description": "Deploys to the Preview environment. Overrides Git metadata.", "name": "preview", "required": false, "allowNo": false, @@ -594,26 +579,11 @@ }, "env": { "description": "Specifies the environment to perform the operation using its handle. Fetch the handle using the `env list` command.", - "exclusive": [ - "env-branch" - ], "name": "env", "hasDynamicHelp": false, "multiple": false, "type": "option" }, - "env-branch": { - "deprecated": { - "to": "env", - "message": "--env-branch is deprecated. Use --env instead." - }, - "description": "Specifies the environment to perform the operation using its Git branch name.", - "env": "SHOPIFY_HYDROGEN_ENVIRONMENT_BRANCH", - "name": "env-branch", - "hasDynamicHelp": false, - "multiple": false, - "type": "option" - }, "env-file": { "description": "Path to an environment file to override existing environment variables. Defaults to the '.env' located in your project path `--path`.", "name": "env-file", @@ -740,26 +710,11 @@ "flags": { "env": { "description": "Specifies the environment to perform the operation using its handle. Fetch the handle using the `env list` command.", - "exclusive": [ - "env-branch" - ], "name": "env", "hasDynamicHelp": false, "multiple": false, "type": "option" }, - "env-branch": { - "deprecated": { - "to": "env", - "message": "--env-branch is deprecated. Use --env instead." - }, - "description": "Specifies the environment to perform the operation using its Git branch name.", - "env": "SHOPIFY_HYDROGEN_ENVIRONMENT_BRANCH", - "name": "env-branch", - "hasDynamicHelp": false, - "multiple": false, - "type": "option" - }, "env-file": { "description": "Path to an environment file to override existing environment variables. Defaults to the '.env' located in your project path `--path`.", "name": "env-file", @@ -811,9 +766,6 @@ "flags": { "env": { "description": "Specifies the environment to perform the operation using its handle. Fetch the handle using the `env list` command.", - "exclusive": [ - "env-branch" - ], "name": "env", "hasDynamicHelp": false, "multiple": false, @@ -1327,26 +1279,11 @@ }, "env": { "description": "Specifies the environment to perform the operation using its handle. Fetch the handle using the `env list` command.", - "exclusive": [ - "env-branch" - ], "name": "env", "hasDynamicHelp": false, "multiple": false, "type": "option" }, - "env-branch": { - "deprecated": { - "to": "env", - "message": "--env-branch is deprecated. Use --env instead." - }, - "description": "Specifies the environment to perform the operation using its Git branch name.", - "env": "SHOPIFY_HYDROGEN_ENVIRONMENT_BRANCH", - "name": "env-branch", - "hasDynamicHelp": false, - "multiple": false, - "type": "option" - }, "env-file": { "description": "Path to an environment file to override existing environment variables. Defaults to the '.env' located in your project path `--path`.", "name": "env-file", diff --git a/packages/cli/src/commands/hydrogen/deploy.test.ts b/packages/cli/src/commands/hydrogen/deploy.test.ts index ad5d091453..e57a50ebe6 100644 --- a/packages/cli/src/commands/hydrogen/deploy.test.ts +++ b/packages/cli/src/commands/hydrogen/deploy.test.ts @@ -271,61 +271,6 @@ describe('deploy', () => { expect(vi.mocked(renderSuccess)).toHaveBeenCalled; }); - it('calls createDeploy against an environment selected by envBranch', async () => { - vi.mocked(getOxygenDeploymentData).mockResolvedValue({ - oxygenDeploymentToken: 'some-encoded-token', - environments: [ - { - name: 'Production', - handle: 'production', - branch: 'main', - type: 'PRODUCTION', - }, - {name: 'Preview', handle: 'preview', branch: null, type: 'PREVIEW'}, - {name: 'Staging', handle: 'staging', branch: 'stage-1', type: 'CUSTOM'}, - ], - }); - - await runDeploy({ - ...deployParams, - envBranch: 'stage-1', - }); - - expect(vi.mocked(createDeploy)).toHaveBeenCalledWith({ - config: { - ...expectedConfig, - environmentTag: 'stage-1', - }, - hooks: expectedHooks, - logger: deploymentLogger, - }); - expect(vi.mocked(renderSuccess)).toHaveBeenCalled; - }); - - it('calls createDeploy against an envBranch in CI', async () => { - vi.mocked(ciPlatform).mockReturnValue({ - isCI: true, - name: 'github', - metadata: {}, - }); - - await runDeploy({ - ...deployParams, - token: 'some-token', - envBranch: 'stage-1', - }); - - expect(vi.mocked(createDeploy)).toHaveBeenCalledWith({ - config: { - ...expectedConfig, - environmentTag: 'stage-1', - }, - hooks: expectedHooks, - logger: deploymentLogger, - }); - expect(vi.mocked(renderSuccess)).toHaveBeenCalled; - }); - it("errors when the env provided doesn't match any environment", async () => { await expect( runDeploy({ @@ -335,15 +280,6 @@ describe('deploy', () => { ).rejects.toThrowError('Environment not found'); }); - it("errors when the envBranch provided doesn't match any environment", async () => { - await expect( - runDeploy({ - ...deployParams, - envBranch: 'fake-branch', - }), - ).rejects.toThrowError('Environment not found'); - }); - it('errors when env is provided while running in CI', async () => { vi.mocked(ciPlatform).mockReturnValue({ isCI: true, @@ -799,19 +735,6 @@ describe('deploy', () => { message: expect.any(String), }); }); - - it('renders a user confirmation on deploy when production environment branch is provided', async () => { - await runDeploy({ - ...deployParams, - envBranch: 'main', - }); - - expect(renderConfirmationPrompt).toHaveBeenCalledWith({ - confirmationMessage: 'Yes, confirm deploy', - cancellationMessage: 'No, cancel deploy', - message: expect.any(String), - }); - }); }); describe('user provides a preview environment', () => { diff --git a/packages/cli/src/commands/hydrogen/deploy.ts b/packages/cli/src/commands/hydrogen/deploy.ts index fec7014f18..4acff026a7 100644 --- a/packages/cli/src/commands/hydrogen/deploy.ts +++ b/packages/cli/src/commands/hydrogen/deploy.ts @@ -72,7 +72,6 @@ export default class Deploy extends Command { static flags: any = { ...commonFlags.entry, ...commonFlags.env, - ...commonFlags.envBranch, ...overrideFlag(commonFlags.envFile, { 'env-file': { description: @@ -82,7 +81,7 @@ export default class Deploy extends Command { }), preview: Flags.boolean({ description: - 'Deploys to the Preview environment. Overrides --env-branch and Git metadata.', + 'Deploys to the Preview environment. Overrides Git metadata.', required: false, default: false, }), @@ -197,7 +196,6 @@ interface OxygenDeploymentOptions { buildCommand?: string; defaultEnvironment: boolean; env?: string; - envBranch?: string; environmentFile?: string; force: boolean; noVerify: boolean; @@ -246,7 +244,6 @@ export async function runDeploy( buildCommand, defaultEnvironment, env: envHandle, - envBranch, environmentFile, force: forceOnUncommitedChanges, noVerify, @@ -357,10 +354,6 @@ export async function runDeploy( ); } - if (isCI && envBranch) { - userProvidedEnvironmentTag = envBranch; - } - if (!isCI) { deploymentData = await getOxygenDeploymentData({ root, @@ -382,11 +375,6 @@ export async function runDeploy( if (userProvidedEnvironmentTag === null) { isPreview = true; } - } else if (envBranch) { - userProvidedEnvironmentTag = findEnvironmentByBranchOrThrow( - deploymentData.environments || [], - envBranch, - ).branch; } } @@ -405,7 +393,6 @@ export async function runDeploy( !isCI && !defaultEnvironment && !envHandle && - !envBranch && deploymentData?.environments ) { if (deploymentData.environments.length > 1) { diff --git a/packages/cli/src/commands/hydrogen/dev.ts b/packages/cli/src/commands/hydrogen/dev.ts index 2f2268b373..e8d09b2be9 100644 --- a/packages/cli/src/commands/hydrogen/dev.ts +++ b/packages/cli/src/commands/hydrogen/dev.ts @@ -76,7 +76,6 @@ export default class Dev extends Command { ...commonFlags.debug, ...commonFlags.inspectorPort, ...commonFlags.env, - ...commonFlags.envBranch, ...commonFlags.envFile, 'disable-version-check': Flags.boolean({ description: 'Skip the version check when running `hydrogen dev`', @@ -159,7 +158,6 @@ type DevOptions = { disableVirtualRoutes?: boolean; disableVersionCheck?: boolean; disableDepsOptimizer?: boolean; - envBranch?: string; env?: string; debug?: boolean; sourcemap?: boolean; @@ -179,7 +177,6 @@ export async function runDev({ codegenConfigPath, disableVirtualRoutes, disableDepsOptimizer = false, - envBranch, env: envHandle, debug = false, disableVersionCheck = false, @@ -206,7 +203,6 @@ export async function runDev({ const envPromise = backgroundPromise.then(({fetchRemote, localVariables}) => getAllEnvironmentVariables({ root, - envBranch, envHandle, fetchRemote, localVariables, diff --git a/packages/cli/src/commands/hydrogen/env/pull.test.ts b/packages/cli/src/commands/hydrogen/env/pull.test.ts index d86ac82b5c..8a12f1a29e 100644 --- a/packages/cli/src/commands/hydrogen/env/pull.test.ts +++ b/packages/cli/src/commands/hydrogen/env/pull.test.ts @@ -107,18 +107,6 @@ describe('pullVariables', () => { }); }); - it('calls getStorefrontEnvVariables when branch is provided', async () => { - await inTemporaryDirectory(async (tmpDir) => { - await runEnvPull({path: tmpDir, envBranch: 'main', envFile}); - - expect(getStorefrontEnvVariables).toHaveBeenCalledWith( - ADMIN_SESSION, - SHOPIFY_CONFIG.storefront.id, - 'production', - ); - }); - }); - it('throws error if handle does not map to any environment', async () => { await inTemporaryDirectory(async (tmpDir) => { await expect( @@ -126,14 +114,6 @@ describe('pullVariables', () => { ).rejects.toThrowError('Environment not found'); }); }); - - it('throws error if branch does not map to any environment', async () => { - await inTemporaryDirectory(async (tmpDir) => { - await expect( - runEnvPull({path: tmpDir, envBranch: 'fake', envFile}), - ).rejects.toThrowError('Environment not found'); - }); - }); }); it('writes environment variables to a .env file by default', async () => { diff --git a/packages/cli/src/commands/hydrogen/env/pull.ts b/packages/cli/src/commands/hydrogen/env/pull.ts index 5ed48b956f..b42ae542c5 100644 --- a/packages/cli/src/commands/hydrogen/env/pull.ts +++ b/packages/cli/src/commands/hydrogen/env/pull.ts @@ -36,7 +36,6 @@ export default class EnvPull extends Command { static flags = { ...commonFlags.env, - ...commonFlags.envBranch, ...commonFlags.envFile, ...commonFlags.path, ...commonFlags.force, @@ -50,7 +49,6 @@ export default class EnvPull extends Command { interface EnvPullOptions { env?: string; - envBranch?: string; envFile: string; force?: boolean; path?: string; @@ -58,7 +56,6 @@ interface EnvPullOptions { export async function runEnvPull({ env: envHandle, - envBranch, path: root = process.cwd(), envFile, force, @@ -79,18 +76,11 @@ export async function runEnvPull({ config.storefront = linkedStorefront; - if (envHandle || envBranch) { + if (envHandle) { const environments = (await getStorefrontEnvironments(session, config.storefront.id)) ?.environments || []; - if (envHandle) { - findEnvironmentOrThrow(environments, envHandle); - } else if (envBranch) { - envHandle = findEnvironmentByBranchOrThrow( - environments, - envBranch, - ).handle; - } + findEnvironmentOrThrow(environments, envHandle); } const storefront = await getStorefrontEnvVariables( diff --git a/packages/cli/src/commands/hydrogen/preview.ts b/packages/cli/src/commands/hydrogen/preview.ts index 5e77b63348..8790a7cc80 100644 --- a/packages/cli/src/commands/hydrogen/preview.ts +++ b/packages/cli/src/commands/hydrogen/preview.ts @@ -35,7 +35,6 @@ export default class Preview extends Command { ...commonFlags.port, ...commonFlags.legacyRuntime, ...commonFlags.env, - ...commonFlags.envBranch, ...commonFlags.envFile, ...commonFlags.inspectorPort, ...commonFlags.debug, @@ -98,7 +97,6 @@ type PreviewOptions = { directory?: string; legacyRuntime?: boolean; env?: string; - envBranch?: string; inspectorPort?: number; debug: boolean; verbose?: boolean; @@ -115,7 +113,6 @@ export async function runPreview({ directory, legacyRuntime = false, env: envHandle, - envBranch, inspectorPort, debug, verbose, @@ -190,7 +187,6 @@ export async function runPreview({ { root, fetchRemote, - envBranch, envHandle, envFile, }, diff --git a/packages/cli/src/lib/classic-compiler/dev.ts b/packages/cli/src/lib/classic-compiler/dev.ts index 7c41715203..d7cc115e16 100644 --- a/packages/cli/src/lib/classic-compiler/dev.ts +++ b/packages/cli/src/lib/classic-compiler/dev.ts @@ -55,7 +55,6 @@ type DevOptions = { disableVirtualRoutes?: boolean; disableVersionCheck?: boolean; env?: string; - envBranch?: string; debug?: boolean; sourcemap?: boolean; inspectorPort?: number; @@ -74,7 +73,6 @@ export async function runClassicCompilerDev({ codegenConfigPath, disableVirtualRoutes, env: envHandle, - envBranch, debug = false, sourcemap = true, disableVersionCheck = false, @@ -160,7 +158,6 @@ export async function runClassicCompilerDev({ getAllEnvironmentVariables({ root, fetchRemote, - envBranch, envHandle, localVariables, envFile, @@ -326,7 +323,6 @@ export async function runClassicCompilerDev({ await getAllEnvironmentVariables({ root, fetchRemote, - envBranch, envHandle, envFile, }); diff --git a/packages/cli/src/lib/environment-variables.test.ts b/packages/cli/src/lib/environment-variables.test.ts index 92af9c26db..08b554f71c 100644 --- a/packages/cli/src/lib/environment-variables.test.ts +++ b/packages/cli/src/lib/environment-variables.test.ts @@ -87,26 +87,10 @@ describe('getAllEnvironmentVariables()', () => { }); }); - it('calls pullRemoteEnvironmentVariables using branch', async () => { - await inTemporaryDirectory(async (tmpDir) => { - await getAllEnvironmentVariables({ - envBranch: 'main', - root: tmpDir, - envFile, - }); - - expect(getStorefrontEnvVariables).toHaveBeenCalledWith( - ADMIN_SESSION, - SHOPIFY_CONFIG.storefront.id, - 'production', - ); - }); - }); - it('does not call pullRemoteEnvironmentVariables when indicated', async () => { await inTemporaryDirectory(async (tmpDir) => { await getAllEnvironmentVariables({ - envBranch: 'main', + envHandle: 'production', root: tmpDir, fetchRemote: false, envFile, diff --git a/packages/cli/src/lib/environment-variables.ts b/packages/cli/src/lib/environment-variables.ts index a613796a1d..6f4d51acca 100644 --- a/packages/cli/src/lib/environment-variables.ts +++ b/packages/cli/src/lib/environment-variables.ts @@ -7,8 +7,6 @@ import {type AbortError} from '@shopify/cli-kit/node/error'; import {renderWarning} from '@shopify/cli-kit/node/ui'; import colors from '@shopify/cli-kit/node/colors'; import {getStorefrontEnvVariables} from './graphql/admin/pull-variables.js'; -import {getStorefrontEnvironments} from './graphql/admin/list-environments.js'; -import {findEnvironmentByBranchOrThrow} from './common.js'; import {login} from './auth.js'; type EnvMap = Record; @@ -16,7 +14,6 @@ type EnvMap = Record; interface Arguments { root: string; envHandle?: string; - envBranch?: string; fetchRemote?: boolean; envFile: string; localVariables?: EnvMap; @@ -30,7 +27,6 @@ const createEmptyRemoteVars = () => ({ export async function getAllEnvironmentVariables({ root, envHandle, - envBranch, envFile, fetchRemote = true, localVariables: inlineLocalVariables, @@ -39,19 +35,17 @@ export async function getAllEnvironmentVariables({ await Promise.all([ // Get remote vars fetchRemote - ? getRemoteVariables(root, envHandle, envBranch).catch( - (error: AbortError) => { - renderWarning({ - headline: - 'Failed to load environment variables from Shopify. The development server will still start, but the following error occurred:', - body: [error.message, error.tryMessage, error.nextSteps] - .filter(Boolean) - .join('\n\n'), - }); - - return createEmptyRemoteVars(); - }, - ) + ? getRemoteVariables(root, envHandle).catch((error: AbortError) => { + renderWarning({ + headline: + 'Failed to load environment variables from Shopify. The development server will still start, but the following error occurred:', + body: [error.message, error.tryMessage, error.nextSteps] + .filter(Boolean) + .join('\n\n'), + }); + + return createEmptyRemoteVars(); + }) : createEmptyRemoteVars(), // Get local vars inlineLocalVariables @@ -101,21 +95,9 @@ export async function getAllEnvironmentVariables({ }; } -async function getRemoteVariables( - root: string, - envHandle?: string, - envBranch?: string, -) { +async function getRemoteVariables(root: string, envHandle?: string) { const {session, config} = await login(root); - if (envBranch) { - const environments = - (await getStorefrontEnvironments(session, config.storefront!.id)) - ?.environments || []; - - envHandle = findEnvironmentByBranchOrThrow(environments, envBranch).handle; - } - const envVariables = (await getStorefrontEnvVariables(session, config.storefront!.id, envHandle)) ?.environmentVariables || []; diff --git a/packages/cli/src/lib/flags.ts b/packages/cli/src/lib/flags.ts index c3d2bd6895..94ae9a7323 100644 --- a/packages/cli/src/lib/flags.ts +++ b/packages/cli/src/lib/flags.ts @@ -62,21 +62,6 @@ export const commonFlags = { env: Flags.string({ description: 'Specifies the environment to perform the operation using its handle. Fetch the handle using the `env list` command.', - exclusive: ['env-branch'], - }), - }, - /** - * @deprecated use `env` instead. - */ - envBranch: { - 'env-branch': Flags.string({ - description: - 'Specifies the environment to perform the operation using its Git branch name.', - env: 'SHOPIFY_HYDROGEN_ENVIRONMENT_BRANCH', - deprecated: { - to: 'env', - message: '--env-branch is deprecated. Use --env instead.', - }, }), }, envFile: { From d8b1cf136b6e686864490dbdc25fea2578b32e15 Mon Sep 17 00:00:00 2001 From: rbshop Date: Mon, 14 Oct 2024 12:49:22 +0100 Subject: [PATCH 3/7] Added a changeset --- .changeset/gorgeous-paws-move.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/gorgeous-paws-move.md diff --git a/.changeset/gorgeous-paws-move.md b/.changeset/gorgeous-paws-move.md new file mode 100644 index 0000000000..280f6ac0ff --- /dev/null +++ b/.changeset/gorgeous-paws-move.md @@ -0,0 +1,5 @@ +--- +'@shopify/cli-hydrogen': patch +--- + +Remove deprecated --worker and --env-branch cli flags From fc4331ad55d36e09d8f8e283f81494b21738adb1 Mon Sep 17 00:00:00 2001 From: Helen Lin Date: Wed, 23 Oct 2024 09:34:47 -0700 Subject: [PATCH 4/7] update to minor bump --- .changeset/gorgeous-paws-move.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changeset/gorgeous-paws-move.md b/.changeset/gorgeous-paws-move.md index 280f6ac0ff..868cfc91ca 100644 --- a/.changeset/gorgeous-paws-move.md +++ b/.changeset/gorgeous-paws-move.md @@ -1,5 +1,5 @@ --- -'@shopify/cli-hydrogen': patch +'@shopify/cli-hydrogen': minor --- Remove deprecated --worker and --env-branch cli flags From 56bae64381e39afaf9f29f933ebc304616d0b62c Mon Sep 17 00:00:00 2001 From: rbshop Date: Thu, 24 Oct 2024 17:39:21 +0100 Subject: [PATCH 5/7] Revert removal of --env-branch cli flag --- .changeset/gorgeous-paws-move.md | 2 +- packages/cli/oclif.manifest.json | 63 +++++++++++++++ .../cli/src/commands/hydrogen/deploy.test.ts | 77 +++++++++++++++++++ packages/cli/src/commands/hydrogen/deploy.ts | 13 ++++ packages/cli/src/commands/hydrogen/dev.ts | 4 + .../src/commands/hydrogen/env/pull.test.ts | 20 +++++ .../cli/src/commands/hydrogen/env/pull.ts | 14 +++- packages/cli/src/commands/hydrogen/preview.ts | 4 + packages/cli/src/lib/classic-compiler/dev.ts | 4 + .../cli/src/lib/environment-variables.test.ts | 18 ++++- packages/cli/src/lib/environment-variables.ts | 42 +++++++--- packages/cli/src/lib/flags.ts | 15 ++++ 12 files changed, 260 insertions(+), 16 deletions(-) diff --git a/.changeset/gorgeous-paws-move.md b/.changeset/gorgeous-paws-move.md index 868cfc91ca..9d4c464f4e 100644 --- a/.changeset/gorgeous-paws-move.md +++ b/.changeset/gorgeous-paws-move.md @@ -2,4 +2,4 @@ '@shopify/cli-hydrogen': minor --- -Remove deprecated --worker and --env-branch cli flags +Remove deprecated --worker cli flag diff --git a/packages/cli/oclif.manifest.json b/packages/cli/oclif.manifest.json index 7d1d1e4b80..3d9458220e 100644 --- a/packages/cli/oclif.manifest.json +++ b/packages/cli/oclif.manifest.json @@ -340,11 +340,26 @@ }, "env": { "description": "Specifies the environment to perform the operation using its handle. Fetch the handle using the `env list` command.", + "exclusive": [ + "env-branch" + ], "name": "env", "hasDynamicHelp": false, "multiple": false, "type": "option" }, + "env-branch": { + "deprecated": { + "to": "env", + "message": "--env-branch is deprecated. Use --env instead." + }, + "description": "Specifies the environment to perform the operation using its Git branch name.", + "env": "SHOPIFY_HYDROGEN_ENVIRONMENT_BRANCH", + "name": "env-branch", + "hasDynamicHelp": false, + "multiple": false, + "type": "option" + }, "env-file": { "description": "Path to an environment file to override existing environment variables for the deployment.", "name": "env-file", @@ -579,11 +594,26 @@ }, "env": { "description": "Specifies the environment to perform the operation using its handle. Fetch the handle using the `env list` command.", + "exclusive": [ + "env-branch" + ], "name": "env", "hasDynamicHelp": false, "multiple": false, "type": "option" }, + "env-branch": { + "deprecated": { + "to": "env", + "message": "--env-branch is deprecated. Use --env instead." + }, + "description": "Specifies the environment to perform the operation using its Git branch name.", + "env": "SHOPIFY_HYDROGEN_ENVIRONMENT_BRANCH", + "name": "env-branch", + "hasDynamicHelp": false, + "multiple": false, + "type": "option" + }, "env-file": { "description": "Path to an environment file to override existing environment variables. Defaults to the '.env' located in your project path `--path`.", "name": "env-file", @@ -710,11 +740,26 @@ "flags": { "env": { "description": "Specifies the environment to perform the operation using its handle. Fetch the handle using the `env list` command.", + "exclusive": [ + "env-branch" + ], "name": "env", "hasDynamicHelp": false, "multiple": false, "type": "option" }, + "env-branch": { + "deprecated": { + "to": "env", + "message": "--env-branch is deprecated. Use --env instead." + }, + "description": "Specifies the environment to perform the operation using its Git branch name.", + "env": "SHOPIFY_HYDROGEN_ENVIRONMENT_BRANCH", + "name": "env-branch", + "hasDynamicHelp": false, + "multiple": false, + "type": "option" + }, "env-file": { "description": "Path to an environment file to override existing environment variables. Defaults to the '.env' located in your project path `--path`.", "name": "env-file", @@ -766,6 +811,9 @@ "flags": { "env": { "description": "Specifies the environment to perform the operation using its handle. Fetch the handle using the `env list` command.", + "exclusive": [ + "env-branch" + ], "name": "env", "hasDynamicHelp": false, "multiple": false, @@ -1279,11 +1327,26 @@ }, "env": { "description": "Specifies the environment to perform the operation using its handle. Fetch the handle using the `env list` command.", + "exclusive": [ + "env-branch" + ], "name": "env", "hasDynamicHelp": false, "multiple": false, "type": "option" }, + "env-branch": { + "deprecated": { + "to": "env", + "message": "--env-branch is deprecated. Use --env instead." + }, + "description": "Specifies the environment to perform the operation using its Git branch name.", + "env": "SHOPIFY_HYDROGEN_ENVIRONMENT_BRANCH", + "name": "env-branch", + "hasDynamicHelp": false, + "multiple": false, + "type": "option" + }, "env-file": { "description": "Path to an environment file to override existing environment variables. Defaults to the '.env' located in your project path `--path`.", "name": "env-file", diff --git a/packages/cli/src/commands/hydrogen/deploy.test.ts b/packages/cli/src/commands/hydrogen/deploy.test.ts index e57a50ebe6..ad5d091453 100644 --- a/packages/cli/src/commands/hydrogen/deploy.test.ts +++ b/packages/cli/src/commands/hydrogen/deploy.test.ts @@ -271,6 +271,61 @@ describe('deploy', () => { expect(vi.mocked(renderSuccess)).toHaveBeenCalled; }); + it('calls createDeploy against an environment selected by envBranch', async () => { + vi.mocked(getOxygenDeploymentData).mockResolvedValue({ + oxygenDeploymentToken: 'some-encoded-token', + environments: [ + { + name: 'Production', + handle: 'production', + branch: 'main', + type: 'PRODUCTION', + }, + {name: 'Preview', handle: 'preview', branch: null, type: 'PREVIEW'}, + {name: 'Staging', handle: 'staging', branch: 'stage-1', type: 'CUSTOM'}, + ], + }); + + await runDeploy({ + ...deployParams, + envBranch: 'stage-1', + }); + + expect(vi.mocked(createDeploy)).toHaveBeenCalledWith({ + config: { + ...expectedConfig, + environmentTag: 'stage-1', + }, + hooks: expectedHooks, + logger: deploymentLogger, + }); + expect(vi.mocked(renderSuccess)).toHaveBeenCalled; + }); + + it('calls createDeploy against an envBranch in CI', async () => { + vi.mocked(ciPlatform).mockReturnValue({ + isCI: true, + name: 'github', + metadata: {}, + }); + + await runDeploy({ + ...deployParams, + token: 'some-token', + envBranch: 'stage-1', + }); + + expect(vi.mocked(createDeploy)).toHaveBeenCalledWith({ + config: { + ...expectedConfig, + environmentTag: 'stage-1', + }, + hooks: expectedHooks, + logger: deploymentLogger, + }); + expect(vi.mocked(renderSuccess)).toHaveBeenCalled; + }); + it("errors when the env provided doesn't match any environment", async () => { await expect( runDeploy({ @@ -280,6 +335,15 @@ describe('deploy', () => { ).rejects.toThrowError('Environment not found'); }); + it("errors when the envBranch provided doesn't match any environment", async () => { + await expect( + runDeploy({ + ...deployParams, + envBranch: 'fake-branch', + }), + ).rejects.toThrowError('Environment not found'); + }); + it('errors when env is provided while running in CI', async () => { vi.mocked(ciPlatform).mockReturnValue({ isCI: true, @@ -735,6 +799,19 @@ describe('deploy', () => { message: expect.any(String), }); }); + + it('renders a user confirmation on deploy when production environment branch is provided', async () => { + await runDeploy({ + ...deployParams, + envBranch: 'main', + }); + + expect(renderConfirmationPrompt).toHaveBeenCalledWith({ + confirmationMessage: 'Yes, confirm deploy', + cancellationMessage: 'No, cancel deploy', + message: expect.any(String), + }); + }); }); describe('user provides a preview environment', () => { diff --git a/packages/cli/src/commands/hydrogen/deploy.ts b/packages/cli/src/commands/hydrogen/deploy.ts index 4acff026a7..4c217ea640 100644 --- a/packages/cli/src/commands/hydrogen/deploy.ts +++ b/packages/cli/src/commands/hydrogen/deploy.ts @@ -72,6 +72,7 @@ export default class Deploy extends Command { static flags: any = { ...commonFlags.entry, ...commonFlags.env, + ...commonFlags.envBranch, ...overrideFlag(commonFlags.envFile, { 'env-file': { description: @@ -196,6 +197,7 @@ interface OxygenDeploymentOptions { buildCommand?: string; defaultEnvironment: boolean; env?: string; + envBranch?: string; environmentFile?: string; force: boolean; noVerify: boolean; @@ -244,6 +246,7 @@ export async function runDeploy( buildCommand, defaultEnvironment, env: envHandle, + envBranch, environmentFile, force: forceOnUncommitedChanges, noVerify, @@ -354,6 +357,10 @@ export async function runDeploy( ); } + if (isCI && envBranch) { + userProvidedEnvironmentTag = envBranch; + } + if (!isCI) { deploymentData = await getOxygenDeploymentData({ root, @@ -375,6 +382,11 @@ export async function runDeploy( if (userProvidedEnvironmentTag === null) { isPreview = true; } + } else if (envBranch) { + userProvidedEnvironmentTag = findEnvironmentByBranchOrThrow( + deploymentData.environments || [], + envBranch, + ).branch; } } @@ -393,6 +405,7 @@ export async function runDeploy( !isCI && !defaultEnvironment && !envHandle && + !envBranch && deploymentData?.environments ) { if (deploymentData.environments.length > 1) { diff --git a/packages/cli/src/commands/hydrogen/dev.ts b/packages/cli/src/commands/hydrogen/dev.ts index e8d09b2be9..2f2268b373 100644 --- a/packages/cli/src/commands/hydrogen/dev.ts +++ b/packages/cli/src/commands/hydrogen/dev.ts @@ -76,6 +76,7 @@ export default class Dev extends Command { ...commonFlags.debug, ...commonFlags.inspectorPort, ...commonFlags.env, + ...commonFlags.envBranch, ...commonFlags.envFile, 'disable-version-check': Flags.boolean({ description: 'Skip the version check when running `hydrogen dev`', @@ -158,6 +159,7 @@ type DevOptions = { disableVirtualRoutes?: boolean; disableVersionCheck?: boolean; disableDepsOptimizer?: boolean; + envBranch?: string; env?: string; debug?: boolean; sourcemap?: boolean; @@ -177,6 +179,7 @@ export async function runDev({ codegenConfigPath, disableVirtualRoutes, disableDepsOptimizer = false, + envBranch, env: envHandle, debug = false, disableVersionCheck = false, @@ -203,6 +206,7 @@ export async function runDev({ const envPromise = backgroundPromise.then(({fetchRemote, localVariables}) => getAllEnvironmentVariables({ root, + envBranch, envHandle, fetchRemote, localVariables, diff --git a/packages/cli/src/commands/hydrogen/env/pull.test.ts b/packages/cli/src/commands/hydrogen/env/pull.test.ts index 8a12f1a29e..d86ac82b5c 100644 --- a/packages/cli/src/commands/hydrogen/env/pull.test.ts +++ b/packages/cli/src/commands/hydrogen/env/pull.test.ts @@ -107,6 +107,18 @@ describe('pullVariables', () => { }); }); + it('calls getStorefrontEnvVariables when branch is provided', async () => { + await inTemporaryDirectory(async (tmpDir) => { + await runEnvPull({path: tmpDir, envBranch: 'main', envFile}); + + expect(getStorefrontEnvVariables).toHaveBeenCalledWith( + ADMIN_SESSION, + SHOPIFY_CONFIG.storefront.id, + 'production', + ); + }); + }); + it('throws error if handle does not map to any environment', async () => { await inTemporaryDirectory(async (tmpDir) => { await expect( @@ -114,6 +126,14 @@ describe('pullVariables', () => { ).rejects.toThrowError('Environment not found'); }); }); + + it('throws error if branch does not map to any environment', async () => { + await inTemporaryDirectory(async (tmpDir) => { + await expect( + runEnvPull({path: tmpDir, envBranch: 'fake', envFile}), + ).rejects.toThrowError('Environment not found'); + }); + }); }); it('writes environment variables to a .env file by default', async () => { diff --git a/packages/cli/src/commands/hydrogen/env/pull.ts b/packages/cli/src/commands/hydrogen/env/pull.ts index b42ae542c5..5ed48b956f 100644 --- a/packages/cli/src/commands/hydrogen/env/pull.ts +++ b/packages/cli/src/commands/hydrogen/env/pull.ts @@ -36,6 +36,7 @@ export default class EnvPull extends Command { static flags = { ...commonFlags.env, + ...commonFlags.envBranch, ...commonFlags.envFile, ...commonFlags.path, ...commonFlags.force, @@ -49,6 +50,7 @@ export default class EnvPull extends Command { interface EnvPullOptions { env?: string; + envBranch?: string; envFile: string; force?: boolean; path?: string; @@ -56,6 +58,7 @@ interface EnvPullOptions { export async function runEnvPull({ env: envHandle, + envBranch, path: root = process.cwd(), envFile, force, @@ -76,11 +79,18 @@ export async function runEnvPull({ config.storefront = linkedStorefront; - if (envHandle) { + if (envHandle || envBranch) { const environments = (await getStorefrontEnvironments(session, config.storefront.id)) ?.environments || []; - findEnvironmentOrThrow(environments, envHandle); + if (envHandle) { + findEnvironmentOrThrow(environments, envHandle); + } else if (envBranch) { + envHandle = findEnvironmentByBranchOrThrow( + environments, + envBranch, + ).handle; + } } const storefront = await getStorefrontEnvVariables( diff --git a/packages/cli/src/commands/hydrogen/preview.ts b/packages/cli/src/commands/hydrogen/preview.ts index 8790a7cc80..5e77b63348 100644 --- a/packages/cli/src/commands/hydrogen/preview.ts +++ b/packages/cli/src/commands/hydrogen/preview.ts @@ -35,6 +35,7 @@ export default class Preview extends Command { ...commonFlags.port, ...commonFlags.legacyRuntime, ...commonFlags.env, + ...commonFlags.envBranch, ...commonFlags.envFile, ...commonFlags.inspectorPort, ...commonFlags.debug, @@ -97,6 +98,7 @@ type PreviewOptions = { directory?: string; legacyRuntime?: boolean; env?: string; + envBranch?: string; inspectorPort?: number; debug: boolean; verbose?: boolean; @@ -113,6 +115,7 @@ export async function runPreview({ directory, legacyRuntime = false, env: envHandle, + envBranch, inspectorPort, debug, verbose, @@ -187,6 +190,7 @@ export async function runPreview({ { root, fetchRemote, + envBranch, envHandle, envFile, }, diff --git a/packages/cli/src/lib/classic-compiler/dev.ts b/packages/cli/src/lib/classic-compiler/dev.ts index d7cc115e16..7c41715203 100644 --- a/packages/cli/src/lib/classic-compiler/dev.ts +++ b/packages/cli/src/lib/classic-compiler/dev.ts @@ -55,6 +55,7 @@ type DevOptions = { disableVirtualRoutes?: boolean; disableVersionCheck?: boolean; env?: string; + envBranch?: string; debug?: boolean; sourcemap?: boolean; inspectorPort?: number; @@ -73,6 +74,7 @@ export async function runClassicCompilerDev({ codegenConfigPath, disableVirtualRoutes, env: envHandle, + envBranch, debug = false, sourcemap = true, disableVersionCheck = false, @@ -158,6 +160,7 @@ export async function runClassicCompilerDev({ getAllEnvironmentVariables({ root, fetchRemote, + envBranch, envHandle, localVariables, envFile, @@ -323,6 +326,7 @@ export async function runClassicCompilerDev({ await getAllEnvironmentVariables({ root, fetchRemote, + envBranch, envHandle, envFile, }); diff --git a/packages/cli/src/lib/environment-variables.test.ts b/packages/cli/src/lib/environment-variables.test.ts index 08b554f71c..92af9c26db 100644 --- a/packages/cli/src/lib/environment-variables.test.ts +++ b/packages/cli/src/lib/environment-variables.test.ts @@ -87,10 +87,26 @@ describe('getAllEnvironmentVariables()', () => { }); }); + it('calls pullRemoteEnvironmentVariables using branch', async () => { + await inTemporaryDirectory(async (tmpDir) => { + await getAllEnvironmentVariables({ + envBranch: 'main', + root: tmpDir, + envFile, + }); + + expect(getStorefrontEnvVariables).toHaveBeenCalledWith( + ADMIN_SESSION, + SHOPIFY_CONFIG.storefront.id, + 'production', + ); + }); + }); + it('does not call pullRemoteEnvironmentVariables when indicated', async () => { await inTemporaryDirectory(async (tmpDir) => { await getAllEnvironmentVariables({ - envHandle: 'production', + envBranch: 'main', root: tmpDir, fetchRemote: false, envFile, diff --git a/packages/cli/src/lib/environment-variables.ts b/packages/cli/src/lib/environment-variables.ts index 6f4d51acca..a613796a1d 100644 --- a/packages/cli/src/lib/environment-variables.ts +++ b/packages/cli/src/lib/environment-variables.ts @@ -7,6 +7,8 @@ import {type AbortError} from '@shopify/cli-kit/node/error'; import {renderWarning} from '@shopify/cli-kit/node/ui'; import colors from '@shopify/cli-kit/node/colors'; import {getStorefrontEnvVariables} from './graphql/admin/pull-variables.js'; +import {getStorefrontEnvironments} from './graphql/admin/list-environments.js'; +import {findEnvironmentByBranchOrThrow} from './common.js'; import {login} from './auth.js'; type EnvMap = Record; @@ -14,6 +16,7 @@ type EnvMap = Record; interface Arguments { root: string; envHandle?: string; + envBranch?: string; fetchRemote?: boolean; envFile: string; localVariables?: EnvMap; @@ -27,6 +30,7 @@ const createEmptyRemoteVars = () => ({ export async function getAllEnvironmentVariables({ root, envHandle, + envBranch, envFile, fetchRemote = true, localVariables: inlineLocalVariables, @@ -35,17 +39,19 @@ export async function getAllEnvironmentVariables({ await Promise.all([ // Get remote vars fetchRemote - ? getRemoteVariables(root, envHandle).catch((error: AbortError) => { - renderWarning({ - headline: - 'Failed to load environment variables from Shopify. The development server will still start, but the following error occurred:', - body: [error.message, error.tryMessage, error.nextSteps] - .filter(Boolean) - .join('\n\n'), - }); - - return createEmptyRemoteVars(); - }) + ? getRemoteVariables(root, envHandle, envBranch).catch( + (error: AbortError) => { + renderWarning({ + headline: + 'Failed to load environment variables from Shopify. The development server will still start, but the following error occurred:', + body: [error.message, error.tryMessage, error.nextSteps] + .filter(Boolean) + .join('\n\n'), + }); + + return createEmptyRemoteVars(); + }, + ) : createEmptyRemoteVars(), // Get local vars inlineLocalVariables @@ -95,9 +101,21 @@ export async function getAllEnvironmentVariables({ }; } -async function getRemoteVariables(root: string, envHandle?: string) { +async function getRemoteVariables( + root: string, + envHandle?: string, + envBranch?: string, +) { const {session, config} = await login(root); + if (envBranch) { + const environments = + (await getStorefrontEnvironments(session, config.storefront!.id)) + ?.environments || []; + + envHandle = findEnvironmentByBranchOrThrow(environments, envBranch).handle; + } + const envVariables = (await getStorefrontEnvVariables(session, config.storefront!.id, envHandle)) ?.environmentVariables || []; diff --git a/packages/cli/src/lib/flags.ts b/packages/cli/src/lib/flags.ts index 94ae9a7323..c3d2bd6895 100644 --- a/packages/cli/src/lib/flags.ts +++ b/packages/cli/src/lib/flags.ts @@ -62,6 +62,21 @@ export const commonFlags = { env: Flags.string({ description: 'Specifies the environment to perform the operation using its handle. Fetch the handle using the `env list` command.', + exclusive: ['env-branch'], + }), + }, + /** + * @deprecated use `env` instead. + */ + envBranch: { + 'env-branch': Flags.string({ + description: + 'Specifies the environment to perform the operation using its Git branch name.', + env: 'SHOPIFY_HYDROGEN_ENVIRONMENT_BRANCH', + deprecated: { + to: 'env', + message: '--env-branch is deprecated. Use --env instead.', + }, }), }, envFile: { From d212fce579864e13a00614dddb3a25e5ec37d0c2 Mon Sep 17 00:00:00 2001 From: Helen Lin Date: Thu, 24 Oct 2024 10:42:11 -0700 Subject: [PATCH 6/7] Remove preview metadata description --- packages/cli/oclif.manifest.json | 2 +- packages/cli/src/commands/hydrogen/deploy.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/cli/oclif.manifest.json b/packages/cli/oclif.manifest.json index 3d9458220e..edea7fe98f 100644 --- a/packages/cli/oclif.manifest.json +++ b/packages/cli/oclif.manifest.json @@ -369,7 +369,7 @@ "type": "option" }, "preview": { - "description": "Deploys to the Preview environment. Overrides Git metadata.", + "description": "Deploys to the Preview environment.", "name": "preview", "required": false, "allowNo": false, diff --git a/packages/cli/src/commands/hydrogen/deploy.ts b/packages/cli/src/commands/hydrogen/deploy.ts index 4c217ea640..57f5226b3a 100644 --- a/packages/cli/src/commands/hydrogen/deploy.ts +++ b/packages/cli/src/commands/hydrogen/deploy.ts @@ -82,7 +82,7 @@ export default class Deploy extends Command { }), preview: Flags.boolean({ description: - 'Deploys to the Preview environment. Overrides Git metadata.', + 'Deploys to the Preview environment.', required: false, default: false, }), From 32d9f39e4b8f53b32c16b9b2c3b46e614a574762 Mon Sep 17 00:00:00 2001 From: Helen Lin Date: Thu, 24 Oct 2024 10:45:17 -0700 Subject: [PATCH 7/7] format --- packages/cli/src/commands/hydrogen/deploy.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/cli/src/commands/hydrogen/deploy.ts b/packages/cli/src/commands/hydrogen/deploy.ts index 57f5226b3a..f48902471f 100644 --- a/packages/cli/src/commands/hydrogen/deploy.ts +++ b/packages/cli/src/commands/hydrogen/deploy.ts @@ -81,8 +81,7 @@ export default class Deploy extends Command { }, }), preview: Flags.boolean({ - description: - 'Deploys to the Preview environment.', + description: 'Deploys to the Preview environment.', required: false, default: false, }),