[Feature]: Theme command to load the default environment
What area(s) will this request affect?
Theme
What type of change do you want to see?
New feature
Overview
The Shopify CLI already supports environment settings through shopify.theme.toml. I propose a small tweak to improve the default behavior by automatically loading the default environment if it is available.
Proposed Change Modify the default behavior of shopify theme related command to load the environment configuration by default. Specifically:
- When a developer runs
shopify theme dev, the CLI would effectively executeshopify theme dev -e defaultin the background. - If the developer has created a
shopify.theme.tomlfile with the default store settings, the command will automatically load these settings. - If the
shopify.theme.tomlfile doesn’t exist or doesn't contain default environment, the CLI would continue to work as it currently does —without any breaking changes.
Example Configuration
[environments.default]
store = "abc.myshopify.com"
With this change, developers could avoid unexpected deployment issues and simplify their workflow, particularly when switching between different stores.
How do you feel about this feature enhancement? If this makes sense, I’d be happy to go ahead and raise a PR to implement it.
Motivation
Currently, the Shopify CLI remembers the last store that was worked on and keeps this stored for future sessions. However, this behavior can lead to unexpected issues: when a developer switches to another project folder and runs shopify theme dev, the CLI mistakenly uploads files to the previous working store instead of the intended one. This can cause significant, unintended trouble, especially if the developer is unaware of this stored preference.
Although there are alternatives, such as setting the environment variable manually or writing scripts to ensure the correct store information is set, I believe the CLI could handle this more seamlessly by improving the default behavior. A solution that prevents accidental deployment to the wrong store would benefit everyone and make the experience smoother and safer for all users.
@jamesmengo @graygilmore I believe this issue illustrates well how Shopify CLI aims to support multiple-store development (mentioning this, because I've noticed you're investigating https://github.com/Shopify/cli/issues/3509).
You can set SHOPIFY_FLAG_ENVIRONMENT in your shell config and overriding that with the -e flag as needed. Let me know how that works out for you!
Related:
- https://github.com/Shopify/cli/issues/4431
I second the addition of a default environment with the shopify.theme.toml is present. It would provide a place to put passwords and the like without having to resort to environment variables until you need to make something "different."
Specifically in the case of #3509 and #4431, it's great to have all the CLI details in an environment and then only change a single value SHOPIFY_FLAG_ENVIRONMENT when you need to switch contexts.
In Shopkeeper, we manipulate the current env via a .env as people move between buckets. In the next release, we'll be changing our defaults to only switch SHOPIFY_FLAG_ENVIRONMENT and recommend people use the TOML for creds.
If a default environment was implemented, we'd probably make our default bucket match in name to remove the additional piece of config. Some extra context if it's helpful.
@cesarho This is great idea and must-have feature for the freelancers that works on multiple "single" stores.
This issue seems inactive. If it's still relevant, please add a comment saying so. Otherwise, take no action. → If there's no activity within a week, then a bot will automatically close this. Thanks for helping to improve Shopify's dev tooling and experience.
P.S. You can learn more about why we stale issues here.
People are interested.
This issue seems inactive. If it's still relevant, please add a comment saying so. Otherwise, take no action. → If there's no activity within a week, then a bot will automatically close this. Thanks for helping to improve Shopify's dev tooling and experience.
P.S. You can learn more about why we stale issues here.
People are interested, still.