Skip to content

Allowlist relevant flags for CLI2 passthrough#743

Merged
amcaplan merged 4 commits intomainfrom
fix-theme-pass-through-flags
Nov 29, 2022
Merged

Allowlist relevant flags for CLI2 passthrough#743
amcaplan merged 4 commits intomainfrom
fix-theme-pass-through-flags

Conversation

@amcaplan
Copy link
Copy Markdown
Contributor

@amcaplan amcaplan commented Nov 8, 2022

WHY are these changes introduced?

Fixes #672 and prevents further similar issues

WHAT is this pull request doing?

We are passing through all CLI3 flags to CLI2, which means any new global flags need to be mentioned in theme commands.

Better to take an allowlist approach since the per-command flags won't change that much and will only need updates in 1 place.

How to test your changes?

All the commands should still work!

Measuring impact

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

  • n/a - this doesn't need measurement, e.g. a linting rule or a bug-fix
  • Existing analytics will cater for this addition
  • PR includes analytics changes to measure impact

Checklist

  • I've considered possible cross-platform impacts (Mac, Linux, Windows)
  • I've considered possible documentation changes
  • I've made sure that any changes to dev or deploy have been reflected in the internal flowchart.

@amcaplan amcaplan requested a review from a team November 8, 2022 17:24
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Nov 8, 2022

We detected some changes at packages/*/src and there are no updates in the .changeset.
If the changes are user-facing, run "yarn changeset add" to track your changes and include them in the next release CHANGELOG.

Copy link
Copy Markdown
Contributor

@gonzaloriestra gonzaloriestra left a comment

Choose a reason for hiding this comment

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

Thanks for taking care of this, 👌

// Exclude flags that are only for CLI3 but will cause errors if passed to CLI2
exclude?: string[]
// Only pass on flags that are relevant to CLI2
relevantFlags?: string[]
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think allowedFlags would be more accurate, but it's just a suggestion.


export default abstract class ThemeCommand extends Command {
passThroughFlags(flags: FlagValues, {exclude}: PassThroughFlagsOptions): string[] {
passThroughFlags(flags: FlagValues, {relevantFlags}: PassThroughFlagsOptions): string[] {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

What about adding the default value here?

Suggested change
passThroughFlags(flags: FlagValues, {relevantFlags}: PassThroughFlagsOptions): string[] {
passThroughFlags(flags: FlagValues, {relevantFlags: Array = []}: PassThroughFlagsOptions): string[] {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This doesn't work as cleanly with TypeScript, I believe we'd have to do:

Suggested change
passThroughFlags(flags: FlagValues, {relevantFlags}: PassThroughFlagsOptions): string[] {
passThroughFlags(flags: FlagValues, {relevantFlags}: PassThroughFlagsOptions = {relevantFlags: []}): string[] {

Also note it's a default value for the whole object, so if {} is passed then relevantFlags would still be undefined.

const passThroughFlags: string[] = []
for (const [label, value] of Object.entries(flags)) {
if ((exclude ?? []).includes(label)) {
if (!(relevantFlags ?? []).includes(label)) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
if (!(relevantFlags ?? []).includes(label)) {
if (!relevantFlags.includes(label)) {

@karreiro karreiro requested review from karreiro and removed request for a team November 11, 2022 08:13
Copy link
Copy Markdown
Contributor

@karreiro karreiro left a comment

Choose a reason for hiding this comment

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

Thank you, @amcaplan! 🚀

Comment thread packages/theme/src/cli/commands/theme/dev.ts Outdated
@amcaplan amcaplan force-pushed the fix-theme-pass-through-flags branch from 0d434ec to 30967ff Compare November 27, 2022 13:27
@amcaplan amcaplan force-pushed the fix-theme-pass-through-flags branch from 30967ff to ad85ea3 Compare November 28, 2022 09:44
@amcaplan amcaplan merged commit 6caf687 into main Nov 29, 2022
@amcaplan amcaplan deleted the fix-theme-pass-through-flags branch November 29, 2022 08:38
@shopify-shipit shopify-shipit Bot temporarily deployed to production November 30, 2022 15:46 Inactive
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.

[Bug]: Preset does not work for themes

4 participants