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

wpCLI via JS API returns "Hello World!" #1414

Open
eherman-godaddy opened this issue May 16, 2024 · 1 comment
Open

wpCLI via JS API returns "Hello World!" #1414

eherman-godaddy opened this issue May 16, 2024 · 1 comment
Labels
[Package][@wp-playground] Blueprints [Type] Bug An existing feature does not function as intended
Milestone

Comments

@eherman-godaddy
Copy link

eherman-godaddy commented May 16, 2024

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 adamziel added this to the Zero Crashes milestone May 17, 2024
@adamziel adamziel added [Type] Bug An existing feature does not function as intended [Package][@wp-playground] Blueprints labels May 17, 2024
@adamziel
Copy link
Collaborator

adamziel commented May 17, 2024

@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:

if (wpCliStepIndex !== undefined && wpCliStepIndex > -1) {
if (blueprint.phpExtensionBundles.includes('light')) {
blueprint.phpExtensionBundles =
blueprint.phpExtensionBundles.filter(
(bundle) => bundle !== 'light'
);
logger.warn(
`The wpCli step used in your Blueprint requires the iconv and mbstring PHP extensions. ` +
`However, you did not specify the kitchen-sink extension bundle. Playground will override your ` +
`choice and load the kitchen-sink PHP extensions bundle to prevent the WP-CLI step from failing. `
);
}
blueprint.steps?.splice(wpCliStepIndex, 0, {
step: 'writeFile',
data: {
resource: 'url',
/**
* Use compression for downloading the wp-cli.phar file.
* The official release, hosted at raw.githubusercontent.com, is ~7MB and the
* transfer is uncompressed. playground.wordpress.net supports transfer compression
* and only transmits ~1.4MB.
*
* @TODO: minify the wp-cli.phar file. It can be as small as 1MB when all the
* whitespaces and are removed, and even 500KB when libraries like the
* JavaScript parser or Composer are removed.
*/
url: 'https://playground.wordpress.net/wp-cli.phar',
},
path: '/tmp/wp-cli.phar',
});
}

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Package][@wp-playground] Blueprints [Type] Bug An existing feature does not function as intended
Projects
Status: No status
Development

No branches or pull requests

2 participants