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

Parse shell commands in createSpawnHandler #1065

Merged
merged 5 commits into from
Feb 27, 2024
Merged

Conversation

adamziel
Copy link
Collaborator

@adamziel adamziel commented Feb 27, 2024

What is this PR doing?

Introduces a naive shell command parser to provide equally good support for the following two types of proc_open() calls:

proc_open([ "wp-cli.phar", "plugin", "install", "gutenberg" ]);
proc_open("wp-cli.phar plugin install gutenberg" ]);

The command parsing semantics are extremely naive at this point and only cover splitting the command into an array of arguments as follows:

splitShellCommand(`wp option set      blogname "My \"fancy\" blog "'name'`);
> ["wp", "option", "set", "blogname", `my "fancy" blog name`]

There is no support for inline ENV variables, pipes, or redirects. For those, we might need to build an actual shell binary OR turn to something like bun shell.

Testing instructions

This PR ships unit tests so just confirm the CI checks pass.

Related resources

@adamziel adamziel merged commit 3bd910c into trunk Feb 27, 2024
5 checks passed
@adamziel adamziel deleted the add-shell-command-parser branch February 27, 2024 23:29
adamziel added a commit that referenced this pull request Feb 28, 2024
## What is this PR doing?

Supersedes #1051

Adds a PHP Blueprints demo page where the use of
[blueprints.phar](WordPress/blueprints#28) PHP
library in Playground may be further explored. The showcase is
intentionally not added to
http://localhost:5400/website-server/demos/index.html as PHP Blueprints
may become a part of Playground core soon enough.

For more context see:

* #1025
* https://github.com/WordPress/blueprints

## How does it work?

* The built Blueprints library is included with this PR via the
`blueprints.phar` file
* A number of PHP.wasm improvements have been merged to support it:
   * #1064
   * #1065
   * #1069
* This PR ships a `fetch` subprocess handler to enable streaming network
data in the Blueprints library – it uses [a special network transport
called
`fetch`](https://github.com/WordPress/blueprints/blob/efa8deef56095bd5bcb94868787e29f7b54350f3/src/WordPress/DataSource/PlaygroundFetchSource.php)
that requests network data via `proc_open()` when running in Playground.
Why subprocesses? They provide everything a custom network handler
needs: pipes, asynchronous execution, exit codes, internal PHP plumbing.

## Follow-up work

* Support a real-time progress bar

## Testing instructions

Go to http://localhost:5400/website-server/demos/php-blueprints.html and
confirm it looks like on the screenshot below:

![CleanShot 2024-02-28 at 15 46
14@2x](https://github.com/WordPress/wordpress-playground/assets/205419/47a91d99-07f3-40a5-a046-b58f8cda952e)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant