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

Blueprints: Transition from a TypeScript library to a PHP library #1025

Open
adamziel opened this issue Feb 11, 2024 · 1 comment
Open

Blueprints: Transition from a TypeScript library to a PHP library #1025

adamziel opened this issue Feb 11, 2024 · 1 comment

Comments

@adamziel
Copy link
Collaborator

adamziel commented Feb 11, 2024

Let’s pivot Blueprints from a TypeScript library to a PHP library. I started the explorations in this repo:

https://github.com/WordPress/blueprints/

Motivation

PHP Blueprints would unite all the Blueprint runtime environments, use-cases, and developers. Single library and documentation unlocking multiple ecosystems.

  • PHP would run the logic in a write once–run everywhere fashion.
  • Playground would be a thin, interchangeable glue layer using WASM to run WordPress and PHP in the browser, Node.js, VS Code, iOS, Android, desktop, etc.

PHP-powered Blueprints would:

  • Force us to write universal and interoperable code
  • Empower WordPress developers who are familiar with PHP
  • Push Playground and PHP.wasm to feature parity with native PHP
  • Remove Playground internals and asynchronous code from the equation
  • Remove the PHP/TypeScript dualism. We’ll achieve more with less code
  • Remove the temptation to duplicate implementations in different JS tools, PHP, and WordPress plugins

Blueprints would become the lingua franca of WordPress. All the runtimes would rely on the same orchestration library:

  • Independent CLI binary
  • WP-now command
  • VS Code extension
  • The web browser
  • WordPress core
  • WP-CLI plugin
  • Mobile apps

Here's a few specific use-cases I have in mind

  • Template sites
  • Site export/import
  • The w.org community space
  • Prototypes of the Site Transfer protocol
  • “Quick development setup”, e.g. I have some local files and I run wp start

Technical steps to get there

Here's the big picture of what we'll need to do:

  1. Disregard WASM and prototype a PHP library that only works well in native PHP. Don't overuse third party libraries, but rely on small components like Symfony EventDispatcher when applicable.
  2. Run that library in PHP.WASM, identify all the ways it fails.
  3. Bundle the library as phar, explore using it in WordPress, WordPress Playground plugin, wp-now, wp-cli etc.
  4. Outline a plan to make it work with the least amount of work. Use workarounds, adjust the PHP library, adjust PHP.wasm implementation, and build polyfills as needed.
  5. Outline a plan to replace all the workarounds with stable, long-term, easy-to-maintain solutions.
  6. Bring the phar library into WordPress Playground core, make the @wp-playground/blueprints library a thin wrapper that delegates all the tasks to the PHP implementation

Related and known PHP.wasm limitations

Other notes

  • WordPress Playground plugin ships a PHP implements of site export and import. This code could be moved to the PHP Blueprint library and replace the TypeScript export/import implementation.
  • The PHP library should be extensible.
  • We could generate the Blueprint JSON schema from PHP types and interfaces in the same way as we do that today using the TypeScript types.
  • A future version of the Blueprint library should know how to extract only a part of a remote ZIP file without downloading all of it.
  • wp-cli could handle complex steps like setWpConfigConstant (wp config set), enableMultisite (wp core multisite-convert), runWpInstallationWizard (wp core install). Same for wp-now features like downloading and installing WordPress core or the SQLite integration plugin.

cc @bgrgicak @dmsnell @mtias @youknowriad @eliot-akira @sejas @danielbachhuber

@adamziel
Copy link
Collaborator Author

adamziel added a commit that referenced this issue 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
Projects
None yet
Development

No branches or pull requests

1 participant