WordPress / wordpress-playground

Run WordPress in the browser via WebAssembly PHP
https://w.org/playground/
GNU General Public License v2.0
1.58k stars 226 forks source link

Blueprints bug: wpCLI step doesn't work via JS API (returns "Hello World!") #1414

Open eherman-godaddy opened 2 months ago

eherman-godaddy commented 2 months ago

I am trying to use wpCLI from @wp-playground/client but regardless of what command I use it always returns "Hello World!". In the examples below, the post is not created, the siteurl option is not returned nor is the plugin list displayed so it seems like wpCLI is not executing the commands properly. It appears to be working fine with the blueprint wp-cli step but not working through the @wp-playground/client wpCLI.

Code I have tried:

await wpCLI( client, { "command": "wp post create --post_title='Test post' --post_excerpt='Some content'" } );
await wpCLI( client, { "command": "wp option get siteurl" } );
await wpCLI( client, { "command": "wp plugin list" } );

Always returns:

"Hello World!"

Docs: https://wordpress.github.io/wordpress-playground/api/client/function/wpCLI

adamziel commented 2 months ago

@eherman-godaddy that's most likely because there's no /tmp/wp-cli.phar file – the code path responsible for running JSON pre-fetches it here:

https://github.com/WordPress/wordpress-playground/blob/97ecad01ea768b5f9834b666422ea5001a870980/packages/playground/blueprints/src/lib/compile.ts#L173-L203

It would be lovely for the JavaScript step to do the same and also log a warning to communicate with the developer.

bgrgicak commented 13 hours ago

This PR adds support for loading WP-CLI during boot, which should fix the wpCli command.

Alternatively adding a wp-cli step to the blueprints would do the same, but having a feature seemed cleaner.