-
Notifications
You must be signed in to change notification settings - Fork 224
Abort theme command when an invalid environment is provided #6698
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
Show new covered files 🐣
Show files with reduced coverage 🔻
Test suite run success3485 tests passing in 1406 suites. Report generated by 🧪jest coverage report action from e92155e |
|
|
||
| // Single environment or no environment | ||
| if (environments.length <= 1) { | ||
| if (environments[0] && !flags.store) { |
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've re-read this a few times and I don't think I understand how this works. Wouldn't environments[0] imply that there is an environment?
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.
Yup! So when you pass in an environment like -e my-store or --environment my-store it's extracted in the base command as the environment before it checks if it's valid or not. Even after it checks and is found to not be a valid environment, the flag.environment still has the value.
So in our case we check if an environment was actually set (no running a regular command like theme list still works without), and if the store flag is missing from the env. If it is, we know the command would not work.
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.
Ah! Because we'd populate flags.store based on the environment. I gotcha now!
graygilmore
left a comment
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 was always confused as to why it worked this way
WHY are these changes introduced?
When running theme commands with an environment that doesn't exist, we fall back to using the cached store data instead (which can be a different store entirely).
See below pictures.


Legitimate Environment
We get a warning that the environment isn't found but still use the prior store
WHAT is this pull request doing?
When running a theme command, we will check if the environment has the store flag which is needed, if it doesn't exist, stop the command and return a warning.
I chose this way as we already run

loadEnvironmentin the base command and it only renders a warning that the environment doesn't exist.How to test your changes?
Post-release steps
Measuring impact
How do we know this change was effective? Please choose one:
Checklist