-
Notifications
You must be signed in to change notification settings - Fork 180
Add default environment functionality to theme commands #5931
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
Conversation
Coverage report
Test suite run success2878 tests passing in 1253 suites. Report generated by 🧪jest coverage report action from 4139e95 |
6951290
to
879bacc
Compare
/snapit |
🫰✨ 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 Caution After installing, validate the version by running just |
879bacc
to
782dbc6
Compare
/snapit |
🫰✨ 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 Caution After installing, validate the version by running just |
e771005
to
782dbc6
Compare
/snapit |
🫰✨ 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 Caution After installing, validate the version by running just |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The conditionals got a little out of hand in this file but it's a bit of a complicated thing to check for. Let me know if any of this is too complicated to read through and I can think about rearranging things.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pushed up a commit to help with this fbdb994
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do think the code in base-command
would benefit from another pass for readability, but my tophat went well!
Aside from that, I wanted to raise the edge case where a user may have created an environment called 'default', which is no longer actually used in their workflow or should only be used when specified.
Not too worried about functional impact, since we output information to the user about the environment being used.
I wonder if that's worth making this a minor
change though 🤔
🎩 went great here too. Chiming in that I agree making it a minor change would be nice. |
782dbc6
to
60c1b9d
Compare
Force Push Patch Notes
|
if (!environmentFileExists && !environmentSpecified) return originalResult | ||
|
||
// Noop if multiple environments were specified (let commands handle this) | ||
if (environmentSpecified && environments.length > 1) return originalResult |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we skip the check for environmentSpecified
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ty for the changes! If the platform team is ok with the implications of this change I'm 100% on board!
Bikeshed warning: I wonder if we can also provide a way to specify a custom 'default' name but that would likely be out of the scope of this
fbdb994
to
9b889ac
Compare
Force Push Patch Notes
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code LGTM. Is the documentation ready?
9b889ac
to
18f9aa2
Compare
Was waiting on approval on approach here first. I'll fire that up now and address the feedback on this PR, too. |
You may now optionally define a default environment in your environment config file (e.g. `shopify.theme.toml`) that will be automatically injected into the running command without needing to specify it.
18f9aa2
to
4139e95
Compare
Differences in type declarationsWe detected differences in the type declarations generated by Typescript for this branch compared to the baseline ('main' branch). Please, review them to ensure they are backward-compatible. Here are some important things to keep in mind:
New type declarationsWe found no new type declarations in this PR Existing type declarationspackages/cli-kit/dist/public/node/base-command.d.ts@@ -20,6 +20,11 @@ declare abstract class BaseCommand extends Command {
protected environmentsFilename(): string | undefined;
protected failMissingNonTTYFlags(flags: FlagOutput, requiredFlags: string[]): void;
private resultWithEnvironment;
+ /**
+ * Tries to load an environment to forward to the command. If no environment
+ * is specified it will try to load a default environment.
+ */
+ private loadEnvironmentForCommand;
}
export declare function addFromParsedFlags(flags: {
path?: string;
packages/cli-kit/dist/public/node/environments.d.ts@@ -11,4 +11,5 @@ interface LoadEnvironmentOptions {
* @returns The loaded environments.
*/
export declare function loadEnvironment(environmentName: string, fileName: string, options?: LoadEnvironmentOptions): Promise<JsonMap | undefined>;
+export declare function environmentFilePath(fileName: string, options?: LoadEnvironmentOptions): Promise<string | undefined>;
export {};
\ No newline at end of file
|
WHY are these changes introduced?
Allows developers to set a default environment in their environments config file:
This environment will automatically be used for CLI commands even if the developer does not specify the environment with the
--environment
flag. This gives developers a bit of a safety net when running commands and switching between different storefronts because this default environment will take precedence over any storefront saved to local storage.How to test your changes?
shopify.theme.toml
file if one doesn't already exist and populate it with at least a[environments.default]
entry that has astore
entryshopify theme dev
shopify theme dev --store different-store.myshopify.com
shopify.theme.toml
fileshopify theme dev -e new
Post-release steps
Once this is approved and merged we'll want to update the docs: https://shopify.dev/docs/storefronts/themes/tools/cli/environments#configure-environments
Checklist