-
Notifications
You must be signed in to change notification settings - Fork 268
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
Support wp-cli in the browser #957
Conversation
It's odd that you are seeing messages about missing |
WP-CLI's behavior for this can be controlled via the standard POSIX |
Aha! I bet the minification (that runs on PHP 7.4) thinks those attributes are comments and it removes them. |
In the browser we have neither so setting the PAGER is just choosing a different name for a custom callback handler we still have to provide. Once WASI is more baked out we should be able to use the actual pager binary, though! |
It took me the entire day but I figured it out. |
## What is this PR doing? A part of #957 Ensures that PHP attributes like `#[ Attr ]` are preserved when minifying WordPress by using PHP 8.0 for minification. PHP 7.4 stripped them out as comments. ## Testing instructions Confirm the CI tests pass
What is this PR doing?
Adds
wp-cli
support in the browser!This PR brings parts of #161 by @swissspidy into
trunk
to enable usingwp-cli
in the browser.Codebase changes
setSapiName
method for PHP.wp-cli
expects to see the exact string"cli"
as the SAPI name.js_open_process
is asynchronous via Asyncify. This is to enable callingsetSpawnHandler(handler)
from the parent site to set a handler in an asynchronous web worker. Unfortunately, using the Comlink messaging library is challenging with complex objects like spawn handlers so this PR ships a workaround where spawn handlers are passed as strings andeval()
-ed in the worker. This shouldn't have any security implications as Playground enables evaluating arbitrary code by definition.proc_open
waits for the process to spawn, andproc_close
waits for the process to die. This is necessary to support thewp-cli
behavior of piping its output through a pager program (likecat
orless -S
).Follow-up work
eval()
fromsetSpawnHandler(handler)
. Setting spawn handler works in Node.js where PHP runs synchronously in the same process, but these spawn handlers are challenging to transfer overpostMessage
as they're essentially composite EventEmitters that need to accept input inside the Worker process, handle it in the client process, and transmit it back to the worker process. Intuitively, it would be pretty easy if we usedMessagePort
directly. It seems likeComlink
as an abstraction layer makes things much easier to a point, since we can magically call functions on objects living in another thread, but there's a boundary beyond which Comlink makes these API interactions more difficult.cc @danielbachhuber @schlessera