Skip to content

Update multi-environment theme command behaviour #6124

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 23, 2025
Merged

Conversation

dejmedus
Copy link
Contributor

@dejmedus dejmedus commented Jul 17, 2025

WHY are these changes introduced?

Previously multi-environment theme commands required force = "true" to be set in shopify.theme.toml since multi env commands must run without interactions. This PR allows flags to be provided via the CLI and adds a confirmation prompt that will run prior to concurrent command calls.

WHAT is this pull request doing?

  • Accepts command flags from both shopify.theme.toml and the CLI, with CLI flags taking precedence.
  • Prompts for confirmation before running commands if the command accepts force (ex. delete, push, pull) and --force has not been set.
  • Catches/handles command errors in renderConcurrent to prefix environment name to the error message and ensure that subsequent environment's commands will still be called.
multi-environment-demo.mov

How to test your changes?

  • pull down the branch gh checkout 6124
  • add a shopify.theme.toml file
Example toml
[environments.store1]
theme = "<theme>"
store = "<store>"
password  = "<shptka_password>"

[environments.store2]
theme = "<theme>"
store = "<store>"
password  = "<shptka_password>"

[environments.missing]
theme = "<theme>"
store = "<store>"

[environments.fake]
theme = "1000000"
store = "fake.myshopify.com"
password  = "not-real"
  • info and list commands both currently work with multiple envs
  • since neither allow --force (and confirmation prompts arent shown on commands that dont accept --force) the force flag can be manually added to test confirmation prompt
// packages/theme/src/cli/commands/theme/list.ts

force: Flags.boolean({
  char: 'f',
  description: 'Skip confirmation',
  env: 'SHOPIFY_FLAG_FORCE',
}),
pnpm shopify theme list -e store1 -e store2 -e missing -e fake
  • environments missing flags should display a warning and the command shouldn't be executed
  • environments with incorrect flags (ex. password = "fake") should have the environment name prefixed to the error message. Commands should fail gracefully and not prevent commands from running in other environments.
  • commands run with a single environment or no environment should work as normal

Post-release steps

  • more commands will be updated to allow multiple environments
  • multi-env documentation

Measuring impact

How do we know this change was effective? Please choose one:

  • Existing analytics will cater for this addition

Checklist

  • I've considered possible cross-platform impacts (Mac, Linux, Windows)
  • I've considered possible documentation changes

@dejmedus dejmedus force-pushed the jb-multi-env branch 2 times, most recently from d8cff92 to d14260f Compare July 17, 2025 18:41
Copy link
Contributor

github-actions bot commented Jul 17, 2025

Coverage report

St.
Category Percentage Covered / Total
🟡 Statements
78.1% (+0.12% 🔼)
13053/16713
🟡 Branches
72.17% (+0.08% 🔼)
6354/8804
🟡 Functions
78.19% (+0.06% 🔼)
3380/4323
🟡 Lines
78.5% (+0.12% 🔼)
12361/15746
Show files with reduced coverage 🔻
St.
File Statements Branches Functions Lines
🟢
... / local-storage.ts
100%
54.55% (-4.55% 🔻)
100% 100%
🔴
... / theme-store.ts
0% (-80% 🔻)
0% (-75% 🔻)
0% (-100% 🔻)
0% (-80% 🔻)

Test suite run success

3052 tests passing in 1315 suites.

Report generated by 🧪jest coverage report action from b382a89

@Shopify Shopify deleted a comment from github-actions bot Jul 17, 2025
@dejmedus
Copy link
Contributor Author

/snapit

Copy link
Contributor

🫰✨ Thanks @dejmedus! Your snapshot has been published to npm.

Test the snapshot by installing your package globally:

pnpm i -g @shopify/[email protected]

Tip

If you get an ETARGET error, install it with NPM and the flag --@shopify:registry=https://registry.npmjs.org

Caution

After installing, validate the version by running just shopify in your terminal.
If the versions don't match, you might have multiple global instances installed.
Use which shopify to find out which one you are running and uninstall it.

@@ -41,6 +47,7 @@ export default abstract class ThemeCommand extends Command {
async command(
_flags: FlagValues,
_session: AdminSession,
_multiEnvironment = false,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will be helpful in certain commands to toggle off behaviour like individual confirmations

try {
await this.command(flags, session, true, {stdout, stderr})

// eslint-disable-next-line no-catch-all/no-catch-all
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without catching/handling, some command errors (like authentication failures) would prevent subsequent commands from running

@dejmedus dejmedus force-pushed the jb-multi-env branch 5 times, most recently from 20c1ea0 to 7be6f14 Compare July 17, 2025 23:35
@dejmedus dejmedus marked this pull request as ready for review July 18, 2025 00:05
@dejmedus dejmedus requested review from a team as code owners July 18, 2025 00:05
@graygilmore
Copy link
Contributor

/snapit

Copy link
Contributor

🫰✨ Thanks @graygilmore! Your snapshot has been published to npm.

Test the snapshot by installing your package globally:

pnpm i -g @shopify/[email protected]

Tip

If you get an ETARGET error, install it with NPM and the flag --@shopify:registry=https://registry.npmjs.org

Caution

After installing, validate the version by running just shopify in your terminal.
If the versions don't match, you might have multiple global instances installed.
Use which shopify to find out which one you are running and uninstall it.

Copy link
Contributor

@graygilmore graygilmore left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎩 went great!

@@ -60,72 +61,125 @@ export default abstract class ThemeCommand extends Command {

// Single environment or no environment
if (environments.length <= 1) {
const session = await this.ensureAuthenticated(flags)
const session = await this.createSession(flags)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: in the future it'd be good to split a name change into a separate commit for an easier git diff!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good! So its easier to differentiate "cosmetic" changes from actual logic changes/additions?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Exactly!

const environmentsMap = await this.loadEnvironments(environments, flags)
const validationResults = await this.validateEnvironments(environmentsMap, requiredFlags)

const commandAllowsForceFlag = 'force' in (this.constructor as typeof ThemeCommand)?.flags
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we use klass here since we already type cast on L60?

Suggested change
const commandAllowsForceFlag = 'force' in (this.constructor as typeof ThemeCommand)?.flags
const commandAllowsForceFlag = 'force' in klass.flags

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

100%, thanks!

Copy link
Contributor

@EvilGenius13 EvilGenius13 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice changes! 🎩 went well too. I think we're headed in a good direction with this.

dejmedus added 2 commits July 23, 2025 10:05
Previously required multi-environment command flags were
only taken from the `shopify.theme.toml` file.
This commit updates ThemeCommand to accept flags from
the CLI as well, with CLI flags taking precedence.
Previously multi-environment theme commands did
not prompt for confirmation before running. This commit
adds a confirmation prompt that will be displayed
if the command accepts `--force` flag and has not
been set to force.
@dejmedus dejmedus added this pull request to the merge queue Jul 23, 2025
Merged via the queue into main with commit 997d4bb Jul 23, 2025
30 checks passed
@dejmedus dejmedus deleted the jb-multi-env branch July 23, 2025 17:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants