Skip to content
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

Skip plugins and themes in internal Studio wp-cli commands like import export #748

Merged
merged 9 commits into from
Dec 18, 2024

Conversation

sejas
Copy link
Member

@sejas sejas commented Dec 17, 2024

Related issues

Proposed Changes

  • Let's skip plugins and themes executing wp-cli for Studio internal commands.
  • Keep the regular wp-cli behaviour for commands executed by the assistant

Testing Instructions

  • Apply this diff to log the arguments being executed:
diff --git a/src/site-server.ts b/src/site-server.ts
index 102b650..4371b19 100644
--- a/src/site-server.ts
+++ b/src/site-server.ts
@@ -191,6 +191,8 @@ export class SiteServer {
                        wpCliArgs.push( '--skip-themes' );
                }
 
+               console.log( '\n\n\n\n wpCliArgs', wpCliArgs );
+
                // The parsing of arguments can include shell operators like `>` or `||` that the app don't support.
                const isValidCommand = wpCliArgs.every(
                        ( arg: unknown ) => typeof arg === 'string' || arg instanceof String
  • Run npm start
  • Create a Studio site
  • Open the terminal
  • Run: wp plugin install slider-revolution-search-replace --activate
  • Go to the assistant tab
  • Ask "what plugins do I have installed?"
  • Observe the answer is correct
  • Observe in the node console the --skip-plugins and --skip-themes are not present
  • Go to the sync tab
  • Connect a site
  • Push the site
  • Observe the push successfully works
  • Observe in the node console the --skip-plugins and --skip-themes are added to each wp-cli command to export, get site url, etc.

Pre-merge Checklist

  • Have you checked for TypeScript, React or other console errors?

@sejas sejas self-assigned this Dec 17, 2024
@sejas sejas requested a review from a team December 17, 2024 15:47
Comment on lines 191 to 197
if ( ! includePlugins ) {
wpCliArgs.push( '--skip-plugins' );
}

if ( ! includeThemes ) {
wpCliArgs.push( '--skip-themes' );
}
Copy link
Member Author

Choose a reason for hiding this comment

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

I'm adding some parameters in case we can include the plugins when executing some specific wp-cli command, but maybe we could avoid those parameters and directly add the arguments:

wpCliArgs.push( '--skip-plugins' );
wpCliArgs.push( '--skip-themes' );

Copy link
Member Author

Choose a reason for hiding this comment

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

I also thought in adding this arguments at execute-wp-cli level, but that way we would adding the arguments also when we execute wp-cli from the CLI.

], ${ phpVar( args ) });

Copy link
Contributor

Choose a reason for hiding this comment

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

It fixes the issue with the plugin that was leaking PHP warnings to WP CLI commands output.

The only part I'm not convinced of is the default value. The executeWpCliCommand is a general purpose command, and it may be not clear that it skips plugins or themes internally.

I think it would be clearer if we changed includePlugins to skipPlugins and explicitly set it in all places which need to skip plugins. It would be also aligned with the WP CLI implementation.

Copy link
Contributor

Choose a reason for hiding this comment

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

I also thought in adding this arguments at execute-wp-cli level, but that way we would adding the arguments also when we execute wp-cli from the CLI.

Could you elaborate on this, @sejas?

Copy link
Member Author

Choose a reason for hiding this comment

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

I think it would be clearer if we changed includePlugins to skipPlugins and explicitly set it in all places which need to skip plugins. It would be also aligned with the WP CLI implementation.

Agreed! More often than not, magical code behavior produces more headaches.
I’ve inverted the conditions and added the flag where it’s needed (export, import, etc.).
3e99a7f

Copy link
Member Author

Choose a reason for hiding this comment

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

I also thought in adding this arguments at execute-wp-cli level, but that way we would adding the arguments also when we execute wp-cli from the CLI.

Could you elaborate on this, @sejas?

@fredrikekelund , my comment wants to highlight that server.executeWpCliCommand is the right place to add this parameter. Another option would be adding the parameter down to the [execute-wp-cli.ts](

], ${ phpVar( args ) });
) function, but that would create more confusion and wouldn't add any value.

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for the change @sejas , looks 100% clear now.

Copy link
Contributor

@fredrikekelund fredrikekelund left a comment

Choose a reason for hiding this comment

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

Nice initiative 👍 I agree this makes sense as a default for our hard-coded CLI calls.

The only issue I see with this is executeWPCLiInline (funny function name with that lowercase i, btw). I'm not sure which commands the Assistant can potentially suggests, but since it seems much more open ended compared to our hard-coded CLI calls, I might be inclined to not skip plugins and themes in that context.

Any thoughts, @sejas?

Comment on lines 173 to 174
includePlugins,
includeThemes,
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
includePlugins,
includeThemes,
includePlugins = false,
includeThemes = false,

Nit, but I think this clarifies intent

Comment on lines 191 to 197
if ( ! includePlugins ) {
wpCliArgs.push( '--skip-plugins' );
}

if ( ! includeThemes ) {
wpCliArgs.push( '--skip-themes' );
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I also thought in adding this arguments at execute-wp-cli level, but that way we would adding the arguments also when we execute wp-cli from the CLI.

Could you elaborate on this, @sejas?

@sejas sejas requested a review from fredrikekelund December 18, 2024 14:21
Copy link
Contributor

Choose a reason for hiding this comment

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

Per my previous review, this is the only place I would consider not skipping plugins and themes. Do we know all the commands Assistant might suggest, and are we sure that the output of those commands couldn't be meaningfully affected by plugins or themes..?

Copy link
Member Author

@sejas sejas Dec 18, 2024

Choose a reason for hiding this comment

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

@fredrikekelund Sure!, I totally agree with you, and the assistant should execute wp-cli command without any flag. Full experience. Skipping themes and plugins was my mistake in the first place.

Now we are skipping plugins and themes for Studio internal commands by passing skipPluginsAndThemes: true, and not including any flag for commands executed by the assistant.
I've added a skipPluginsAndThemes: false, to be more specific, but I can remove it if you think it adds confusion.

f4091ad

Copy link
Contributor

Choose a reason for hiding this comment

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

My bad for not looking closer at the code first 🙌 I see now that this code isn't for "general purpose" WP-CLI commands.

@sejas sejas changed the title Skip plugins and themes by default when executing wp-cli commands Skip plugins and themes in internal Studio wp-cli commands like import export Dec 18, 2024
@sejas sejas requested a review from wojtekn December 18, 2024 14:37
@sejas
Copy link
Member Author

sejas commented Dec 18, 2024

@wojtekn , @fredrikekelund , I would appreciate another review 🙏 .
Thank you!

Copy link
Contributor

@fredrikekelund fredrikekelund left a comment

Choose a reason for hiding this comment

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

LGTM and works as expected 👍

@sejas sejas merged commit 4b9f1ee into trunk Dec 18, 2024
7 checks passed
@sejas sejas deleted the add/exclude-plugins-themes-from-wpcli branch December 18, 2024 16:09
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